月度归档:2015年12月

PHP中的null合并运算符

null合并运算符是一个好东西,有了它我们就能很方便的获取一个参数,并能在其为空的情况下提供一个默认值。比如在js中可以用||来搞:
function setSomething(a){a = a || 'some-default-value';// ...}
而在PHP中,可惜PHP的||总是返回truefalse,无法这样来搞。PHP7才正式加入了??这个运算符:
// 获取user参数的值(如果为空,则用'nobody')$username = $_GET['user'] ?? 'nobody';// 等价于:$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
PHP7 估计还有很长时间才能用到生产环境中,那在目前的PHP5中有没有替代方案呢?据研究,完全有个非常便捷的替代方案:
// 获取user参数的值(如果为空,则用'nobody')$username = @$_GET['user'] ?: 'nobody';// 等价于:$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
-- 运行此代码:https://3v4l.org/aDUW8瞪大了眼睛看,跟前面的PHP7的例子差不多,主要是把??替换为了?:。 这个是个什么鬼呢?其实这就是(expr1) ? (expr2) : (expr3)表达式的省略模式:
表达式 (expr1) ? (expr...
阅读全文

PlantUML的实例参考

Alice -> Bob: Authentication RequestBob --> Alice: Authentication ResponseAlice -> Bob: Another authentication RequestAlice <-- Bob: another authentication Response

actor Foo1boundary Foo2control Foo3entity Foo4database Foo5Foo1 -> Foo2 : To boundaryFoo1 -> Foo3 : To controlFoo1 -> Foo4 : To entityFoo1 -> Foo5 : To database

actor Bob #red' The only difference between actor'and participant is the drawingparticipant Aliceparticipant "I have a really\nlong name" as L #99FF99/' You can also declare:participant L as "I have a really\nlong name"  #99FF99'/Alice->Bob: Authentication RequestBob->Alice: Authentication ResponseBob->L: Log transaction

Alice -> "Bob()" : Hello"Bob()" -> "This is very\nlong" as Long' You can also declare:' "Bob()" -> Long as "This is very\nlong"Long --> "Bob()" : ok

Alice->Alice: This is a signal to self.\nIt also demonstrates\nmultiline \ntext

Bob ->x AliceBob -> AliceBob ->> AliceBob -\ AliceBob \\- AliceBob //-- AliceBob ->o AliceBob o\\-- AliceBob <-> AliceBob <->o Alice

Bob -[#red]> Alice : helloAlice -[#0000FF]->Bob : okautonumberBob -> Alice : Authentication RequestBob <- Alice : Authentication Responseautonumber 15Bob -> Alice : Another authentication RequestBob <- Alice : Another authentication Responseautonumber 40 10Bob -> Alice : Yet another authentication RequestBob <- Alice : Yet another authentication Responseautonumber "<b>[000]"Bob -> Alice : Authentication RequestBob <- Alice : Authentication Responseautonumber 15 "<b>(<u>##</u>)"Bob -> Alice : Another authentication RequestBob <- Alice : Another authentication Responseautonumber 40 10 "<font color=red><b>Message 0  "Bob -> Alice : Yet another authentication RequestBob <- Alice : Yet another authentication Response

title Simple communication exampleAlice -> Bob: Authentication RequestBob --> Alice: Authentication ResponseAlice -> Bob : Hellolegend rightShortlegendendlegend

Alice -> Bob : message 1Alice -> Bob : message 2newpageAlice -> Bob : message 3Alice -> Bob : message 4newpage A title for the\nlast pageAlice -> Bob : message 5Alice -> Bob : message 6

Alice -> Bob: Authentication Requestalt successful caseBob -> Alice: Authentication Acceptedelse some kind of failureBob -> Alice: Authentication Failuregroup My own labelAlice -> Log : Log attack startloop 1000 timesAlice -> Bob: DNS AttackendAlice -> Log : Log attack endendelse Another type of failureBob -> Alice: Please repeatend

Alice->Bob : hellonote left: this is a first noteBob->Alice : oknote right: this is another noteBob->Bob : I am thinkingnote lefta notecan also be definedon several linesend note

participant Aliceparticipant Bobnote left of Alice #aquaThis is displayedleft of Alice.end notenote right of Alice: This is displayed right of Alice.note over Alice: This is displayed over Alice.note over Alice, Bob #FFAAAA: This is displayed\n over Bob and Alice.note over Bob, AliceThis is yet anotherexample ofa long note.end note

caller -> server : conReqhnote over caller : idlecaller <- server : conConfrnote over server"r" as rectangle"h" as hexagonendrnote

participant Aliceparticipant "The **Famous** Bob" as BobAlice -> Bob : hello --there--... Some ~~long delay~~ ...Bob -> Alice : oknote leftThis is **bold**This is //italics//This is ""monospaced""This is --stroked--This is __underlined__This is ~~waved~~end noteAlice -> Bob : A //well formatted// messagenote right of AliceThis is <back:cadetblue><size:18>displayed</size></back>__left of__ Alice.end notenote left of Bob<u:red>This</u> is <color #118888>displayed</color>**<color purple>left of</color> <s:red>Alice</strike> Bob**.end notenote over Alice, Bob<w:#FF33FF>This is hosted</w> by <img sourceforge.jpg>end note

== Initialization ==Alice -> Bob: Authentication RequestBob --> Alice: Authentication Response== Repetition ==Alice -> Bob: Another authentication RequestAlice <-- Bob: another authentication Response

participant Aliceactor Bobref over Alice, Bob : initAlice -> Bob : helloref over BobThis can be onseveral linesend ref

Alice -> Bob: Authentication Request...Bob --> Alice: Authentication Response...5 minutes latter...Bob --> Alice: Bye !

Alice -> Bob: message 1Bob --> Alice: ok|||Alice -> Bob: message 2Bob --> Alice: ok||45||Alice -> Bob: message 3Bob --> Alice: ok

participant UserUser -> A: DoWorkactivate AA -> B: << createRequest >>activate BB -> C: DoWorkactivate CC --> B: WorkDonedestroy CB --> A: RequestCreateddeactivate BA -> User: Donedeactivate A

participant UserUser -> A: DoWorkactivate A #FFBBBBA -> A: Internal callactivate A #DarkSalmonA -> B: << createRequest >>activate BB --> A: RequestCreateddeactivate Bdeactivate AA -> User: Donedeactivate A

Bob -> Alice : hellocreate OtherAlice -> Other : newcreate control StringAlice -> Stringnote right : You can also put notes!Alice --> Bob : ok

[-> A: DoWorkactivate AA -> A: Internal callactivate AA ->] : << createRequest >>A<--] : RequestCreateddeactivate A[<- A: Donedeactivate A

[-> Bob[o-> Bob[o->o Bob[x-> Bob[<- Bob[x<- BobBob ->]Bob ->o]Bob o->o]Bob ->x]Bob <-]Bob x<-]

@startuml/'This is an example Sequence diagramShowing a fictional web feature flowIt is easy to see roles & responsibilities for each componentand easy to change them too...'/title "Story Feature Example - Sequence Diagram"'This is a single line comment/'This is a multi-line commentOne another line'/actor User'boundary Proxyparticipant UIServer as UIparticipant APIUser -> UI: LINK: goto /account pageactivate UIUI -> User:deactivate UIactivate Usernote over UserRequirments:UI: Setting PageClick delete buttonend note' user requests account/delete pageUser -> UI: /account/deletedeactivate Useractivate UIUI -> User:deactivate UI' confirmation formactivate Usernote over UserUI: FormAre you sure?end noteUser -> UI: POST /account/deletedeactivate Useractivate UInote over UI: Verify: user has confirmedUI -> API: /account/deleteactivate APIAPI -> API: deleteAPI -> UI: donedeactivate APIUI -> User: successdeactivate UI@enduml

阅读全文

使用PHPUnit + Selenium进行自动化测试

第一步,安装PHPUni

最简单的方式莫过于到PHPUnit的官网下载PHPUnit,然后把那个下载了的phpunit.phar加到PATH中。此外,还可以通过pear来安装phpunit:
pear clear-cachepear channel-discover pear.phpunit.depear channel-discover components.ez.nopear channel-discover pear.symfony-project.compear install -a -f  phpunit/PHPUnit
参考:http://www.cnblogs.com/wanfox/p/4613517.html然而使用pear安装方式,我却是没有成功!大概是因为天朝的神奇的GFW吧!补记:还能通过composer来安装:
composer require phpunit/phpunit

第二步,下载Selenium Standalone Serve

传送门http://docs.seleniumhq.org/download/传送门2:https://selenium-release.storage.googleapis.com/index.html?path=2.48/下载下来一般是一个selenium-server-standalone-2.48.2.jar这样的文件(版本号可能会有所更新)。

第三步,下载WebDriver for Chrom...

阅读全文