ea:6:{s:7:"version";s:25:"nightly-2042-201305212221";s:6:"author";s:16:"Frédéric Hardy";s:7:"support";s:17:"support@atoum.org";s:10:"repository";s:26:"http://www.atoum.org/atoum";s:11:"description";s:73:"atoum is a simple, modern and intuitive PHP 5.3+ unit testing framework. ";s:7:"licence";s:1514:"Copyright (c) 2010-2013, Frédéric Hardy. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Frédéric Hardy nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY FRÉDÉRIC HARDY AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FRÉDÉRIC HARDY AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ";}versionsA\כQA"Ŷ 1/bin/atoum\כQ'UD 1/classes/adapter/definition.php\כQ<#1/classes/annotations/extractor.php\כQ 1/classes/asserter/exception.phpq\כQq|pζ 1/classes/asserter/generator.php \כQ ,1/classes/asserters/adapter/call/adapter.phpv\כQv)1/classes/asserters/adapter/call/mock.phpF\כQFz)1/classes/asserters/mock/call/adapter.phpJ\כQJaD-&1/classes/asserters/mock/call/mock.php \כQ  1/classes/asserters/adapter.php\כQ!1/classes/asserters/boolean.php@\כQ@>d$1/classes/asserters/castToString.php\כQlg$1/classes/asserters/dateInterval.php1 \כQ1 8 1/classes/asserters/dateTime.php\כQjt1/classes/asserters/error.phpO\כQO6E!1/classes/asserters/exception.php#\כQ#z!1/classes/asserters/extension.php\כQ*1/classes/asserters/float.php\כQ(^1/classes/asserters/hash.php\כQ$ 1/classes/asserters/integer.php\ \כQ\ ܱ1/classes/asserters/mock.php^"\כQ^"Gi%1/classes/asserters/mysqlDateTime.php\כQ]>/1/classes/asserters/object.php% \כQ% 8c1/classes/asserters/output.php\כQ-oW 1/classes/asserters/phpArray.php\!\כQ\!9l 1/classes/asserters/phpClass.php\כQiɶ1/classes/asserters/sizeOf.php\כQ1jE1/classes/asserters/stream.php\כQFV1/classes/asserters/string.php^\כQ^[#1/classes/asserters/testedClass.php\כQg]:"1/classes/asserters/utf8String.php \כQ r 1/classes/asserters/variable.php]\כQ]By1/classes/cli/colorizer.phpV\כQVץ|1/classes/cli/progressBar.php| \כQ| Q1/classes/cli/prompt.php\כQ}b϶,1/classes/exceptions/logic/badMethodCall.php\כQ.1/classes/exceptions/logic/invalidArgument.php\כQ|%1/classes/exceptions/runtime/file.php\כQ@01/classes/exceptions/runtime/unexpectedValue.php\כQK]X1/classes/exceptions/logic.php\כQ+ 1/classes/exceptions/runtime.php\כQKDا 1/classes/includer/exception.php}\כQ}hR<71/classes/iterators/filters/recursives/atoum/source.phpz\כQzYǟ21/classes/iterators/filters/recursives/closure.phpY\כQYwV.1/classes/iterators/filters/recursives/dot.php&\כQ&=Ҷ41/classes/iterators/filters/recursives/extension.php\כQn˪/1/classes/iterators/recursives/atoum/source.php\כQs41/classes/iterators/recursives/directory/factory.php \כQ 21/classes/mailers/mail.php\כQidY'1/classes/mock/controller/collector.php\כQٚY&1/classes/mock/controller/iterator.phpO\כQOIhQ&1/classes/mock/php/method/argument.php"\כQ"#옶1/classes/mock/php/method.phpU\כQU`緶$1/classes/mock/stream/controller.php\כQLjY!1/classes/mock/stream/invoker.php.\כQ.ȇ21/classes/mock/streams/fs/directory/controller.php\כQ䛶-1/classes/mock/streams/fs/file/controller.phpc&\כQc&{(1/classes/mock/streams/fs/controller.php\כQr['1/classes/mock/streams/fs/directory.php\כQq"1/classes/mock/streams/fs/file.php\כQ^1/classes/mock/aggregator.php\כQ1/classes/mock/controller.phpq\כQqٵG1/classes/mock/generator.phpP\כQPO(1/classes/mock/stream.php@ \כQ@ q!a1/classes/observers/runner.phpp\כQpj|ж1/classes/observers/test.phpn\כQnf*1/classes/php/call/arguments/decorator.php\כQD 1/classes/php/call/decorator.php\כQBm*1/classes/php/tokenizer/iterator/value.phpS\כQSbw%U11/classes/php/tokenizer/iterators/phpArgument.php\כQ܋Ķ.1/classes/php/tokenizer/iterators/phpClass.php\כQ=11/classes/php/tokenizer/iterators/phpConstant.php\כQI*51/classes/php/tokenizer/iterators/phpDefaultValue.php\כQ˶}r11/classes/php/tokenizer/iterators/phpFunction.php\כQ"㢶41/classes/php/tokenizer/iterators/phpImportation.php\כQ80/1/classes/php/tokenizer/iterators/phpMethod.php\כQnv21/classes/php/tokenizer/iterators/phpNamespace.php\כQ(ܙ11/classes/php/tokenizer/iterators/phpProperty.php\כQM/1/classes/php/tokenizer/iterators/phpScript.phpk\כQkxp$1/classes/php/tokenizer/iterator.phpW\כQWkxU!1/classes/php/tokenizer/token.php\כQN-G1/classes/php/call.php\כQĵg41/classes/php/exception.phpx\כQx?:!1/classes/php/tokenizer.php]\כQ]շx1/classes/readers/std/in.php\כQ{,1/classes/report/fields/runner/atoum/cli.php\כQͶ-1/classes/report/fields/runner/atoum/logo.php \כQ NZK.1/classes/report/fields/runner/atoum/phing.php\כQŭ</1/classes/report/fields/runner/coverage/cli.php \כQ ʼ01/classes/report/fields/runner/coverage/html.phpu5\כQu5۶31/classes/report/fields/runner/coverage/treemap.php \כQ Ŷ/1/classes/report/fields/runner/duration/cli.php\כQ? -11/classes/report/fields/runner/duration/phing.php\כQ -1/classes/report/fields/runner/errors/cli.php\כQ_h,1/classes/report/fields/runner/event/cli.php\כQ&ܶ11/classes/report/fields/runner/exceptions/cli.php\כQW,@1/classes/report/fields/runner/failures/execute/macos/macvim.phpS\כQSȨB1/classes/report/fields/runner/failures/execute/macos/phpstorm.php\כQg>1/classes/report/fields/runner/failures/execute/unix/gedit.php\כQeړ =1/classes/report/fields/runner/failures/execute/unix/gvim.php\כQA1/classes/report/fields/runner/failures/execute/unix/phpstorm.php*\כQ*&/1/classes/report/fields/runner/failures/cli.php \כQ gA31/classes/report/fields/runner/failures/execute.php\כQmt.1/classes/report/fields/runner/outputs/cli.php \כQ RY/1/classes/report/fields/runner/php/path/cli.phpK\כQKNQ21/classes/report/fields/runner/php/version/cli.php\כQz +1/classes/report/fields/runner/php/path.phpO\כQOK .1/classes/report/fields/runner/php/version.phpa\כQa[4ƶ>1/classes/report/fields/runner/result/notifier/image/growl.php\כQZwB1/classes/report/fields/runner/result/notifier/image/libnotify.php\כQcNw81/classes/report/fields/runner/result/notifier/image.php\כQV-;1/classes/report/fields/runner/result/notifier/terminal.php\כQe-1/classes/report/fields/runner/result/cli.php \כQ ".1/classes/report/fields/runner/result/logo.php{\כQ{(21/classes/report/fields/runner/result/notifier.phpj \כQj b垶+1/classes/report/fields/runner/tap/plan.php\כQS51/classes/report/fields/runner/tests/coverage/cli.php \כQ ;@71/classes/report/fields/runner/tests/coverage/phing.phpG\כQG51/classes/report/fields/runner/tests/duration/cli.php^\כQ^Wi31/classes/report/fields/runner/tests/memory/cli.php;\כQ;BeP51/classes/report/fields/runner/tests/memory/phing.php\כQR%41/classes/report/fields/runner/tests/skipped/cli.php \כQ |0c81/classes/report/fields/runner/tests/uncompleted/cli.php \כQ +ݶ11/classes/report/fields/runner/tests/void/cli.phpI\כQI-^11/classes/report/fields/runner/tests/coverage.phpe\כQe22!11/classes/report/fields/runner/tests/duration.php\כQjSF/1/classes/report/fields/runner/tests/memory.php\כQ4a01/classes/report/fields/runner/tests/skipped.phpF\כQF;41/classes/report/fields/runner/tests/uncompleted.phpJ\כQJ̑-1/classes/report/fields/runner/tests/void.phpC\כQC<С(1/classes/report/fields/runner/atoum.php\כQ:+1/classes/report/fields/runner/coverage.phpX\כQX-+1/classes/report/fields/runner/duration.phpl\כQl")1/classes/report/fields/runner/errors.php\כQlC(1/classes/report/fields/runner/event.php\כQ2zD-1/classes/report/fields/runner/exceptions.phpC\כQCׂ+1/classes/report/fields/runner/failures.phpZ\כQZ"1/classes/test/exceptions/stop.php\כQ'B!1/classes/test/mock/generator.php\כQ ?1/classes/test/adapter.php\כQ1/classes/test/engine.php\כQh1/classes/test/score.php\כQ3M8"1/classes/tools/diffs/variable.php\כQ1/classes/tools/diff.php \כQ tͶ1/classes/writers/std/err.php\כQ\@`S1/classes/writers/std/out.php\כQsUR1/classes/writers/file.php\כQA-pO1/classes/writers/mail.php\כQW1/classes/writers/std.phpZ\כQZ#'1/classes/adapter.phpf\כQfL}{1/classes/asserter.php \כQ 9q[1/classes/cli.php\כQZ 1/classes/autoloader.php\כQc˶1/classes/configurator.php4\כQ4Ӓ?j1/classes/exception.php:\כQ:| 1/classes/includer.php\כQX$1/classes/locale.php\כQ1/classes/mailer.php\כQu1/classes/observable.phpd\כQd]k1/classes/observer.phpx\כQxrq1/classes/php.php\כQ21/classes/reader.php\כQL?}1/classes/report.php\כQܦ8ڶ1/classes/runner.phpG1\כQG11/classes/score.php(\כQ(Ě01/classes/script.php\כQqoE1/classes/superglobals.php\כQPiy1/classes/template.php \כQ T1/classes/test.php\כQ^.@1/classes/writer.php\כQO{Y21/resources/configurations/builder/config.php.dist\כQtҶ21/resources/configurations/runner/builder.php.dist\כQ.1/resources/configurations/runner/cli.php.dist\כQ͂11/resources/configurations/runner/clover.php.dist\כQEMm31/resources/configurations/runner/coverage.php.dist\כQV\/1/resources/configurations/runner/logo.php.distx\כQxGiƶ.1/resources/configurations/runner/vim.php.dist?\כQ?v01/resources/configurations/runner/xunit.php.dist\כQU'1/resources/coverage/treemap/index.html+\כQ+vs#1/resources/images/logo/failure.pngA \כQA #1/resources/images/logo/success.pngD \כQD ) 1/resources/images/logo.png\כQwx 1/resources/phing/AtoumTask.phpa%\כQa%Wl1/resources/phing/build.xmlz\כQzNw1/resources/sonar/maven/pom.xmlu\כQu=챶(1/resources/templates/coverage/class.tpl \כQ J(1/resources/templates/coverage/index.tplY\כQY{n)1/resources/templates/coverage/screen.css \כQ 1/resources/treemap/index.html.\כQ. H1/resources/vim/atoum.vmbF\כQF϶!1/scripts/phar/resources/stub.php\כQeB1/scripts/phar/generator.phpa\כQaI[1/scripts/builder.php\כQ)@1/scripts/runner.phpr\כQr#H1/scripts/tagger.php\כQ1/scripts/treemap.phpE\כQEO51/tests/units/asserters/template/parser/exception.phpj\כQj֥]i/1/tests/units/classes/annotations/extractor.phpq0\כQq0~,1/tests/units/classes/asserter/generator.php\כQͥM81/tests/units/classes/asserters/adapter/call/adapter.php\כQ:d51/tests/units/classes/asserters/adapter/call/mock.phpW\כQW51/tests/units/classes/asserters/mock/call/adapter.phpK \כQK d21/tests/units/classes/asserters/mock/call/mock.php\כQq[+1/tests/units/classes/asserters/adapter.phpzw\כQzw$Yr+1/tests/units/classes/asserters/boolean.php2\כQ2sH01/tests/units/classes/asserters/castToString.php\כQ#*101/tests/units/classes/asserters/dateInterval.php\כQ|L,1/tests/units/classes/asserters/dateTime.php*\כQ*W[d5)1/tests/units/classes/asserters/error.php/#\כQ/#E-Y-1/tests/units/classes/asserters/exception.php\כQQ-1/tests/units/classes/asserters/extension.php \כQ b)1/tests/units/classes/asserters/float.phpC\כQC(1/tests/units/classes/asserters/hash.php\כQ#F+1/tests/units/classes/asserters/integer.phpF\כQFt(1/tests/units/classes/asserters/mock.php\כQɶ11/tests/units/classes/asserters/mysqlDateTime.phpI\כQI̶*1/tests/units/classes/asserters/object.php\כQת*1/tests/units/classes/asserters/output.phpN\כQNaH,1/tests/units/classes/asserters/phpArray.phpc\כQcT,1/tests/units/classes/asserters/phpClass.phpK5\כQK55 *1/tests/units/classes/asserters/sizeOf.php\כQ*1/tests/units/classes/asserters/stream.php!\כQ!\n'*1/tests/units/classes/asserters/string.phpL-\כQL-3/1/tests/units/classes/asserters/testedClass.php\כQ S@.1/tests/units/classes/asserters/utf8String.php4\כQ467,1/tests/units/classes/asserters/variable.php@4\כQ@4HË'1/tests/units/classes/cli/colorizer.phpY\כQYE[)1/tests/units/classes/cli/progressBar.php6\כQ6И墶$1/tests/units/classes/cli/prompt.php\כQeM81/tests/units/classes/exceptions/logic/badMethodCall.php\כQnV=3:1/tests/units/classes/exceptions/logic/invalidArgument.php\כQItֶ<1/tests/units/classes/exceptions/runtime/unexpectedValue.php\כQ u*1/tests/units/classes/exceptions/logic.php\כQ10,1/tests/units/classes/exceptions/runtime.php\כQ>C1/tests/units/classes/iterators/filters/recursives/atoum/source.php \כQ ]6>1/tests/units/classes/iterators/filters/recursives/closure.php\כQض:1/tests/units/classes/iterators/filters/recursives/dot.phpu\כQu@1/tests/units/classes/iterators/filters/recursives/extension.phpP\כQPt%;1/tests/units/classes/iterators/recursives/atoum/source.php^\כQ^W@1/tests/units/classes/iterators/recursives/directory/factory.php\כQ"lFC&1/tests/units/classes/mailers/mail.phps\כQs!uN31/tests/units/classes/mock/controller/collector.php\כQZiL21/tests/units/classes/mock/controller/iterator.phpa\כQaI^21/tests/units/classes/mock/php/method/argument.php\כQr)1/tests/units/classes/mock/php/method.php \כQ K϶01/tests/units/classes/mock/stream/controller.phpH\כQH'hŶ-1/tests/units/classes/mock/stream/invoker.php\כQ|vf>1/tests/units/classes/mock/streams/fs/directory/controller.php \כQ pR91/tests/units/classes/mock/streams/fs/file/controller.php(\כQ(us41/tests/units/classes/mock/streams/fs/controller.phpg\כQg&۶31/tests/units/classes/mock/streams/fs/directory.php\כQB'.1/tests/units/classes/mock/streams/fs/file.phpB\כQBfl)1/tests/units/classes/mock/controller.phpQ\כQQu6D߶(1/tests/units/classes/mock/generator.php\כQ05%1/tests/units/classes/mock/stream.php\כQ%/61/tests/units/classes/php/call/arguments/decorator.php\כQCl,1/tests/units/classes/php/call/decorator.phpF\כQF̺ߜ=1/tests/units/classes/php/tokenizer/iterators/phpArgument.php\כQ>WǶ:1/tests/units/classes/php/tokenizer/iterators/phpClass.php-\כQ-0T=1/tests/units/classes/php/tokenizer/iterators/phpConstant.php\כQ2?d =1/tests/units/classes/php/tokenizer/iterators/phpFunction.php\כQ񫹴@1/tests/units/classes/php/tokenizer/iterators/phpImportation.php\כQ;1/tests/units/classes/php/tokenizer/iterators/phpMethod.php\כQ~7v>1/tests/units/classes/php/tokenizer/iterators/phpNamespace.phpr\כQr =1/tests/units/classes/php/tokenizer/iterators/phpProperty.php\כQ!;1/tests/units/classes/php/tokenizer/iterators/phpScript.php4)\כQ4)x201/tests/units/classes/php/tokenizer/iterator.phpz\כQzж-1/tests/units/classes/php/tokenizer/token.php\כQY)"1/tests/units/classes/php/call.php: \כQ: p'1/tests/units/classes/php/exception.php\כQ)H'1/tests/units/classes/php/tokenizer.php4\כQ4爧(1/tests/units/classes/readers/std/in.php\כQZ$81/tests/units/classes/report/fields/runner/atoum/cli.php \כQ =/91/tests/units/classes/report/fields/runner/atoum/logo.php\כQ4z:1/tests/units/classes/report/fields/runner/atoum/phing.php \כQ L<1/tests/units/classes/report/fields/runner/coverage/html.phpdk\כQdkz?1/tests/units/classes/report/fields/runner/coverage/treemap.php4\כQ4Y*ֶ;1/tests/units/classes/report/fields/runner/duration/cli.php[\כQ[Φ*=1/tests/units/classes/report/fields/runner/duration/phing.php1\כQ1K91/tests/units/classes/report/fields/runner/errors/cli.phpy\כQyǶ81/tests/units/classes/report/fields/runner/event/cli.php\כQ߬=1/tests/units/classes/report/fields/runner/exceptions/cli.php\כQ2)L1/tests/units/classes/report/fields/runner/failures/execute/macos/macvim.php\כQc|?N1/tests/units/classes/report/fields/runner/failures/execute/macos/phpstorm.php^\כQ^J)J1/tests/units/classes/report/fields/runner/failures/execute/unix/gedit.php3\כQ3"牶I1/tests/units/classes/report/fields/runner/failures/execute/unix/gvim.php.\כQ.4M1/tests/units/classes/report/fields/runner/failures/execute/unix/phpstorm.php\כQhn;1/tests/units/classes/report/fields/runner/failures/cli.phpm4\כQm4Rɫ?1/tests/units/classes/report/fields/runner/failures/execute.phps \כQs pݶ:1/tests/units/classes/report/fields/runner/outputs/cli.phpb+\כQb+~~%;1/tests/units/classes/report/fields/runner/php/path/cli.php(\כQ(?>1/tests/units/classes/report/fields/runner/php/version/cli.php\כQ!LAJ1/tests/units/classes/report/fields/runner/result/notifier/image/growl.php})\כQ})diN1/tests/units/classes/report/fields/runner/result/notifier/image/libnotify.phpd&\כQd&Z[@D1/tests/units/classes/report/fields/runner/result/notifier/image.php2 \כQ2 7˶G1/tests/units/classes/report/fields/runner/result/notifier/terminal.phpR'\כQR'91/tests/units/classes/report/fields/runner/result/cli.php?\כQ?;b:1/tests/units/classes/report/fields/runner/result/logo.php\כQX?>1/tests/units/classes/report/fields/runner/result/notifier.php>'\כQ>'Ih71/tests/units/classes/report/fields/runner/tap/plan.php\כQklA1/tests/units/classes/report/fields/runner/tests/coverage/cli.php$\כQ$'W5C1/tests/units/classes/report/fields/runner/tests/coverage/phing.phpe(\כQe(a37A1/tests/units/classes/report/fields/runner/tests/duration/cli.phpA \כQA 8b?1/tests/units/classes/report/fields/runner/tests/memory/cli.php\כQ57A1/tests/units/classes/report/fields/runner/tests/memory/phing.php \כQ .Bu@1/tests/units/classes/report/fields/runner/tests/skipped/cli.phpu\כQu(1HD1/tests/units/classes/report/fields/runner/tests/uncompleted/cli.php (\כQ (}E<1/tests/units/classes/report/fields/runner/tests/skipped.php\כQZD91/tests/units/classes/report/fields/runner/tests/void.php\כQل91/tests/units/classes/report/fields/test/duration/cli.php\כQ;1/tests/units/classes/report/fields/test/duration/phing.php\כQԶ61/tests/units/classes/report/fields/test/event/cli.php\כQc81/tests/units/classes/report/fields/test/event/phing.php\כQ|61/tests/units/classes/report/fields/test/event/tap.phpAJ\כQAJ,Ķ71/tests/units/classes/report/fields/test/memory/cli.php\כQ 91/tests/units/classes/report/fields/test/memory/phing.php\כQ'41/tests/units/classes/report/fields/test/run/cli.php"\כQ"G61/tests/units/classes/report/fields/test/run/phing.php!\כQ!&1/tests/units/classes/report/field.php\כQ A1/tests/units/classes/reports/asynchronous/clover/resources/1.xml\כQ4A1/tests/units/classes/reports/asynchronous/clover/resources/2.xml \כQ У@1/tests/units/classes/reports/asynchronous/xunit/resources/1.xml\כQl>@1/tests/units/classes/reports/asynchronous/xunit/resources/2.xml;\כQ;&@1/tests/units/classes/reports/asynchronous/xunit/resources/3.xml\כQ?@1/tests/units/classes/reports/asynchronous/xunit/resources/4.xml\כQAv@1/tests/units/classes/reports/asynchronous/xunit/resources/5.xmlr\כQrOж@1/tests/units/classes/reports/asynchronous/xunit/resources/6.xml\כQ 61/tests/units/classes/reports/asynchronous/builder.php \כQ %51/tests/units/classes/reports/asynchronous/clover.php\כQ^21/tests/units/classes/reports/asynchronous/vim.php.\כQ.߬41/tests/units/classes/reports/asynchronous/xunit.php\כQXJ41/tests/units/classes/reports/realtime/cli/light.phpV \כQV ?.1/tests/units/classes/reports/realtime/cli.php\כQ01/tests/units/classes/reports/realtime/phing.php(\כQ( O.1/tests/units/classes/reports/realtime/tap.php%\כQ%&}.1/tests/units/classes/reports/asynchronous.php \כQ &1/tests/units/classes/runner/score.php-\כQ-X(1/tests/units/classes/score/coverage.php \כQ Ј=11/tests/units/classes/script/arguments/parser.php47\כQ47IE;-1/tests/units/classes/script/configurable.php\כQ%'1/tests/units/classes/script/prompt.phpq\כQq11/tests/units/classes/scripts/builder/vcs/svn.php85\כQ85FwП01/tests/units/classes/scripts/phar/generator.php>\כQ>6z ]+1/tests/units/classes/scripts/phar/stub.php \כQ );>/1/tests/units/classes/scripts/tagger/engine.php'\כQ'4):1/tests/units/classes/scripts/treemap/analyzer/generic.php4 \כQ4 751/tests/units/classes/scripts/treemap/categorizer.php \כQ i)1/tests/units/classes/scripts/builder.phpȈ\כQȈ%v(1/tests/units/classes/scripts/runner.php1\כQ1K8(1/tests/units/classes/scripts/tagger.php\כQtB2)1/tests/units/classes/scripts/treemap.phpg\כQgHl'1/tests/units/classes/template/data.phpB\כQBC+1/tests/units/classes/template/iterator.php0\כQ0{ )1/tests/units/classes/template/parser.phpo\כQo9nɶ&1/tests/units/classes/template/tag.php\כQL?.1/tests/units/classes/test/adapter/invoker.php~$\כQ~$=:1/tests/units/classes/test/assertion/manager/exception.php%\כQ%&701/tests/units/classes/test/assertion/manager.php,\כQ,,ƶ11/tests/units/classes/test/engines/concurrent.php\כQn-1/tests/units/classes/test/engines/inline.php\כQ$r&1/tests/units/classes/test/adapter.php=\כQ=Π}%1/tests/units/classes/test/engine.php\כQHކ$1/tests/units/classes/test/score.php \כQ xj!.1/tests/units/classes/tools/diffs/variable.php\כQ&L߶$1/tests/units/classes/tools/diff.php\כQ 1)1/tests/units/classes/writers/std/err.php\כQ)x)1/tests/units/classes/writers/std/out.php\כQ-&1/tests/units/classes/writers/file.php'\כQ'|Hm&1/tests/units/classes/writers/mail.phpv\כQv'!1/tests/units/classes/adapter.php\כQ4@""1/tests/units/classes/asserter.php\כQR$1/tests/units/classes/autoloader.php\כQ|鷙1/tests/units/classes/cli.php\כQ i&1/tests/units/classes/configurator.php\כQ\!"1/tests/units/classes/includer.php)\כQ)](< 1/tests/units/classes/locale.php\כQ%I;@1/tests/units/classes/php.php\כQҶ 1/tests/units/classes/reader.php?\כQ? ~K 1/tests/units/classes/report.php \כQ X} 1/tests/units/classes/runner.php3\כQ3Rvl1/tests/units/classes/score.phpE\כQE 1/tests/units/classes/script.phpj@\כQj@Y2&1/tests/units/classes/superglobals.php \כQ s"1/tests/units/classes/template.php[\כQ[p!v1/tests/units/classes/test.php\כQ~&@ 1/tests/units/classes/writer.php\כQP߶+1/tests/units/resources/phing/AtoumTask.phpL\כQLK1/tests/units/runner.php\כQ8%ж1/ABOUTI\כQI: 1/COPYING\כQW w1/CREDIT\כQg*11/FAQ\כQDŽ 1/README.md-\כQ-dz1/composer.json \כQ E*1/constants.php\כQxZa:2:{i:1;s:25:"nightly-2042-201305212221";s:7:"current";s:1:"1";}#!/usr/bin/env php handlers as $handlerAnnotation => $handlerValue) { if ($annotation == strtolower($handlerAnnotation)) { call_user_func_array($handlerValue, array($value)); } } } } } } return $this; } public function setHandler($annotation, \closure $handler) { $this->handlers[$annotation] = $handler; return $this; } public function unsetHandler($annotation) { if (isset($this->handlers[$annotation]) === true) { unset($this->handlers[$annotation]); } return $this; } public function getHandlers() { return $this->handlers; } public function resetHandlers() { $this->handlers = array(); return $this; } public static function toBoolean($value) { switch (strtolower((string) $value)) { case 'on': case '1': case 'true': return true; default: return false; } } public static function toArray($value) { return array_values(array_unique(preg_split('/\s+/', $value))); } } setAdapter($adapter) ->setLocale($locale) ->setAsserterNamespace($asserterNamespace) ; } public function __set($asserter, $class) { $this->setAlias($asserter, $class); } public function __get($property) { return $this->getAsserterInstance($property); } public function __call($method, $arguments) { return $this->getAsserterInstance($method, $arguments); } public function setAdapter(atoum\adapter $adapter = null) { $this->adapter = $adapter ?: new atoum\adapter(); return $this; } public function getAdapter() { return $this->adapter; } public function setLocale(atoum\locale $locale = null) { $this->locale = $locale ?: new atoum\locale(); return $this; } public function getLocale() { return $this->locale; } public function setAsserterNamespace($namespace = null) { $this->asserterNamespace = ($namespace === null ? static::defaultAsserterNamespace : trim($namespace, '\\')) . '\\'; return $this; } public function getAsserterNamespace() { return trim($this->asserterNamespace, '\\'); } public function setAlias($alias, $asserterClass) { $this->aliases[strtolower($alias)] = $asserterClass; return $this; } public function getAliases() { return $this->aliases; } public function resetAliases() { $this->aliases = array(); return $this; } public function asserterPass(atoum\asserter $asserter) { return $this; } public function asserterFail(atoum\asserter $asserter, $reason) { throw new exception($reason); } public function getAsserterClass($asserter) { $asserter = strtolower($asserter); $class = (isset($this->aliases[$asserter]) === false ? $asserter : $this->aliases[$asserter]); if (substr($class, 0, 1) != '\\') { $class = $this->asserterNamespace . $class; } if ($this->adapter->class_exists($class, true) === false) { $class = null; } return $class; } public function getAsserterInstance($asserter, array $arguments = array()) { if (($asserterClass = $this->getAsserterClass($asserter)) === null) { throw new exceptions\logic\invalidArgument('Asserter \'' . $asserter . '\' does not exist'); } $asserterInstance = new $asserterClass(); return $asserterInstance->setGenerator($this)->setWithArguments($arguments); } } adapterAsserter = $adapterAsserter; $this->adapter = $adapter; parent::__construct($function); } public function __call($method, $arguments) { if (method_exists($this->adapterAsserter, $method) === false) { throw new exceptions\logic\invalidArgument('Method ' . get_class($this->adapterAsserter) . '::' . $method . '() does not exist'); } return call_user_func_array(array($this->adapterAsserter, $method), $arguments); } public function getAdapterAsserter() { return $this->adapterAsserter; } public function getAdapter() { return $this->adapter; } public function withArguments() { $this->arguments = func_get_args(); return $this; } public function getFirstCall() { $calls = $this->adapter->getCalls($this->function, $this->arguments); return ($calls === null ? null : key($calls)); } public function getLastCall() { $calls = $this->adapter->getCalls($this->function, $this->arguments); return ($calls === null ? null : key(array_reverse($calls, true))); } } adapterAsserter = $adapterAsserter; parent::__construct($function, null, $mockAggregator); } public function __call($method, $arguments) { if (method_exists($this->adapterAsserter, $method) === false) { throw new exceptions\logic\invalidArgument('Method ' . get_class($this->adapterAsserter) . '::' . $method . '() does not exist'); } return call_user_func_array(array($this->adapterAsserter, $method), $arguments); } public function getAdapterAsserter() { return $this->adapterAsserter; } public function withArguments() { $this->arguments = func_get_args(); return $this; } public function getFirstCall() { $calls = $this->object->getMockController()->getCalls($this->function, $this->arguments); return ($calls === null ? null : key($calls)); } public function getLastCall() { $calls = $this->object->getMockController()->getCalls($this->function, $this->arguments); return ($calls === null ? null : key(array_reverse($calls, true))); } } mockAsserter = $mockAsserter; $this->adapter = $adapter; parent::__construct($function); } public function __call($method, $arguments) { if (method_exists($this->mockAsserter, $method) === false) { throw new exceptions\logic\invalidArgument('Method ' . get_class($this->mockAsserter) . '::' . $method . '() does not exist'); } return call_user_func_array(array($this->mockAsserter, $method), $arguments); } public function getMockAsserter() { return $this->mockAsserter; } public function getAdapter() { return $this->adapter; } public function withArguments() { return parent::setArguments(func_get_args()); } public function getFirstCall() { $calls = $this->adapter->getCalls($this->function, $this->arguments); return $calls === null ? null : key($calls); } public function getLastCall() { $calls = $this->adapter->getCalls($this->function, $this->arguments); return $calls === null ? null : key(array_reverse($calls, true)); } } mockAsserter = $mockAsserter; parent::__construct($function, null, $mockAggregator); } public function __call($function, $arguments) { if (method_exists($this->mockAsserter, $function) === false) { throw new exceptions\logic\invalidArgument('Method ' . get_class($this->mockAsserter) . '::' . $function . '() does not exist'); } return call_user_func_array(array($this->mockAsserter, $function), $arguments); } public function getMockAsserter() { return $this->mockAsserter; } public function withArguments() { return parent::setArguments(func_get_args()); } public function withAtLeastArguments(array $arguments) { return parent::setArguments(array($arguments)); } public function on(atoum\mock\aggregator $mockAggregator) { return $this->setObject($mockAggregator); } public function getFirstCall() { $calls = $this->getObject()->getMockController()->getCalls($this->function, $this->arguments); return $calls === null ? null : key($calls); } public function getLastCall() { $calls = $this->getObject()->getMockController()->getCalls($this->function, $this->arguments); return $calls === null ? null : key(array_reverse($calls, true)); } } adapter = $adapter; if ($this->adapter instanceof \mageekguy\atoum\test\adapter === false) { $this->fail(sprintf($this->getLocale()->_('%s is not a test adapter'), $this->getTypeOf($this->adapter))); } else { $this->pass(); } return $this; } public function reset() { if ($this->adapter !== null) { $this->adapter->resetCalls(); } return $this; } public function getAdapter() { return $this->adapter; } public function beforeMethodCall($methodName, atoum\mock\aggregator $mock) { $this->adapterIsSet()->beforeMethodCalls[] = $beforeMethodCall = new adapter\call\mock($this, $mock, $methodName); return $beforeMethodCall; } public function getBeforeMethodCalls() { return $this->beforeMethodCalls; } public function withAnyMethodCallsBefore() { $this->beforeMethodCalls = array(); return $this; } public function afterMethodCall($methodName, atoum\mock\aggregator $mock) { $this->adapterIsSet()->afterMethodCalls[] = $afterMethodCall = new adapter\call\mock($this, $mock, $methodName); return $afterMethodCall; } public function getAfterMethodCalls() { return $this->afterMethodCalls; } public function withAnyMethodCallsAfter() { $this->afterMethodCalls = array(); return $this; } public function beforeFunctionCall($methodName) { $this->adapterIsSet()->beforeFunctionCalls[] = $beforeFunctionCall = new adapter\call\adapter($this, $this->adapter, $methodName); return $beforeFunctionCall; } public function getBeforeFunctionCalls() { return $this->beforeFunctionCalls; } public function withAnyFunctionCallsBefore() { $this->beforeFunctionCalls = array(); return $this; } public function afterFunctionCall($methodName) { $this->adapterIsSet()->afterFunctionCalls[] = $afterFunctionCall = new adapter\call\adapter($this, $this->adapter, $methodName); return $afterFunctionCall; } public function getAfterFunctionCalls() { return $this->afterFunctionCalls; } public function withAnyFunctionCallsAfter() { $this->afterFunctionCalls = array(); return $this; } public function call($function) { if ($this->adapterIsSet()->call === null) { $this->call = new php\call($function); } else { $this->call ->setFunction($function) ->unsetArguments() ; } return $this; } public function getCall() { return ($this->call === null ? null : clone $this->call); } public function withArguments() { $this->calledFunctionNameIsSet()->call->setArguments(func_get_args()); return $this; } public function withIdenticalArguments() { $this->calledFunctionNameIsSet()->call->setArguments(func_get_args())->identical(); return $this; } public function withAnyArguments() { $this->calledFunctionNameIsSet()->call->unsetArguments(); return $this; } public function withoutAnyArgument() { $this->calledFunctionNameIsSet()->call->setArguments(array()); return $this; } public function once($failMessage = null) { return $this->exactly(1, $failMessage); } public function twice($failMessage = null) { return $this->exactly(2, $failMessage); } public function thrice($failMessage = null) { return $this->exactly(3, $failMessage); } public function atLeastOnce($failMessage = null) { $this->assertOnBeforeAndAfterCalls($calls = $this->calledFunctionNameIsSet()->adapter->getCalls($this->call->getFunction(), $this->call->getArguments())); if (($callsNumber = sizeof($calls)) >= 1) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('function %s is called 0 time'), $this->call) . $this->getCallsAsString()); } return $this; } public function exactly($number, $failMessage = null) { $this->assertOnBeforeAndAfterCalls($calls = $this->calledFunctionNameIsSet()->adapter->getCalls($this->call->getFunction(), $this->call->getArguments())); if (($callsNumber = sizeof($calls)) === $number) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf( $this->getLocale()->__( 'function %s is called %d time instead of %d', 'function %s is called %d times instead of %d', $callsNumber ), $this->call, $callsNumber, $number ) . $this->getCallsAsString() ); } return $this; } public function never($failMessage = null) { return $this->exactly(0, $failMessage); } protected function adapterIsSet() { if ($this->adapter === null) { throw new exceptions\logic('Adapter is undefined'); } return $this; } protected function calledFunctionNameIsSet() { if ($this->adapterIsSet()->call === null) { throw new exceptions\logic('Called function is undefined'); } return $this; } protected function assertOnBeforeAndAfterCalls($calls) { if (sizeof($calls) > 0) { foreach ($this->beforeMethodCalls as $beforeMethodCall) { $firstCall = $beforeMethodCall->getFirstCall(); if ($firstCall === null) { $this->fail(sprintf($this->getLocale()->_('function %s is not called'), $beforeMethodCall)); } if (key($calls) > $firstCall) { $this->fail(sprintf($this->getLocale()->_('function %s is not called before method %s'), $this->call, $beforeMethodCall)); } $this->pass(); } foreach ($this->beforeFunctionCalls as $beforeFunctionCall) { $firstCall = $beforeFunctionCall->getFirstCall(); if ($firstCall === null) { $this->fail(sprintf($this->getLocale()->_('function %s is not called'), $beforeFunctionCall)); } if (key($calls) > $firstCall) { $this->fail(sprintf($this->getLocale()->_('function %s is not called before function %s'), $this->call, $beforeFunctionCall)); } $this->pass(); } foreach ($this->afterMethodCalls as $afterMethodCall) { $lastCall = $afterMethodCall->getLastCall(); if ($lastCall === null) { $this->fail(sprintf($this->getLocale()->_('function %s is not called'), $afterMethodCall)); } if (key($calls) < $lastCall) { $this->fail(sprintf($this->getLocale()->_('function %s is not called after method %s'), $this->call, $afterMethodCall)); } $this->pass(); } foreach ($this->afterFunctionCalls as $afterFunctionCall) { $lastCall = $afterFunctionCall->getLastCall(); if ($lastCall === null) { $this->fail(sprintf($this->getLocale()->_('function %s is not called'), $afterFunctionCall)); } if (key($calls) < $lastCall) { $this->fail(sprintf($this->getLocale()->_('function %s is not called after function %s'), $this->call, $afterFunctionCall)); } $this->pass(); } } return $this; } protected function getCallsAsString() { $string = ''; if (($calls = $this->adapter->getCalls($this->call->getFunction())) !== null) { $format = '[%' . strlen((string) sizeof($calls)) . 's] %s'; $phpCalls = array(); foreach (array_values($calls) as $call => $arguments) { $phpCalls[] = sprintf($format, $call + 1, new php\call($this->call->getFunction(), $arguments)); } $string = PHP_EOL . join(PHP_EOL, $phpCalls); } return $string; } } isFalse(); case strtolower($property) == 'istrue': return $this->isTrue(); default: return parent::__get($property); } } public function setWith($value, $label = null) { parent::setWith($value, $label); if (self::isBoolean($this->value) === false) { $this->fail(sprintf($this->getLocale()->_('%s is not a boolean'), $this)); } else { $this->pass(); } return $this; } public function isTrue($failMessage = null) { return $this->isEqualTo(true, $failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is not true'), $this)); } public function isFalse($failMessage = null) { return $this->isEqualTo(false, $failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is not false'), $this)); } protected static function check($value, $method) { if (self::isBoolean($value) === false) { throw new exceptions\logic\invalidArgument('Argument of ' . $method . '() must be a boolean'); } } protected static function isBoolean($value) { return (is_bool($value) === true); } } fail(sprintf($this->getLocale()->_('%s is not an object'), $this->getTypeOf($value))); } else { $this->pass(); $this->value = (string) $this->value; } } return $this; } protected static function isObject($value) { return (is_object($value) === true); } } value) === true) { $this->pass(); } else { $this->fail(sprintf($this->getLocale()->_('%s is not an instance of \\dateInterval'), $this)); } } return $this; } public function __toString() { return (static::isDateInterval($this->value) === false ? parent::__toString() : $this->format($this->value)); } public function isGreaterThan(\dateInterval $interval, $failMessage = null) { list($date1, $date2) = $this->getDates($interval); if ($date1 > $date2) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Interval %s is not greater than %s'), $this, $this->format($interval))); } return $this; } public function isGreaterThanOrEqualTo(\dateInterval $interval, $failMessage = null) { list($date1, $date2) = $this->getDates($interval); if ($date1 >= $date2) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Interval %s is not greater than or equal to %s'), $this, $this->format($interval))); } return $this; } public function isLessThan(\dateInterval $interval, $failMessage = null) { list($date1, $date2) = $this->getDates($interval); if ($date1 < $date2) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Interval %s is not less than %s'), $this, $this->format($interval))); } return $this; } public function isLessThanOrEqualTo(\dateInterval $interval, $failMessage = null) { list($date1, $date2) = $this->getDates($interval); if ($date1 <= $date2) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Interval %s is not less than or equal to %s'), $this, $this->format($interval))); } return $this; } public function isEqualTo($interval, $failMessage = null) { list($date1, $date2) = $this->getDates($interval); if ($date1 == $date2) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Interval %s is not equal to %s'), $this, $this->format($interval))); } return $this; } public function isZero($failMessage = null) { return $this->isEqualTo(new \dateInterval('P0D'), sprintf($this->getLocale()->_('Interval %s is not equal to zero'), $this)); } protected function valueIsSet($message = 'Interval is undefined') { if (self::isDateInterval(parent::valueIsSet($message)->value) === false) { throw new exceptions\logic($message); } return $this; } protected function getDates(\dateInterval $interval) { $this->valueIsSet(); $date1 = new \dateTime(); $date2 = clone $date1; return array($date1->add($this->value), $date2->add($interval)); } protected static function isDateInterval($value) { return ($value instanceof \dateInterval); } protected function format(\dateInterval $interval) { return $interval->format($this->getLocale()->_('%Y/%M/%D %H:%I:%S')); } } value) === false) { $this->fail(sprintf($this->getLocale()->_('%s is not an instance of \\dateTime'), $this)); } else { $this->pass(); } } return $this; } public function hasTimezone(\dateTimezone $timezone, $failMessage = null) { if ($this->valueIsSet()->value->getTimezone()->getName() == $timezone->getName()) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Timezone is %s instead of %s'), $this->value->getTimezone()->getName(), $timezone->getName())); } return $this; } public function hasYear($year, $failMessage = null) { if ($this->valueIsSet()->value->format('Y') === sprintf('%04d', $year)) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Year is %s instead of %s'), $this->value->format('Y'), $year)); } return $this; } public function isInYear() { die('The method ' . __METHOD__ . ' is deprecated, please use ' . __CLASS__ . '::hasYear instead'); } public function hasMonth($month, $failMessage = null) { if ($this->valueIsSet()->value->format('m') === sprintf('%02d', $month)) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Month is %s instead of %02d'), $this->value->format('m'), $month)); } return $this; } public function isInMonth() { die('The method ' . __METHOD__ . ' is deprecated, please use ' . __CLASS__ . '::hasMonth instead'); } public function hasDay($day, $failMessage = null) { if ($this->valueIsSet()->value->format('d') === sprintf('%02d', $day)) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Day is %s instead of %02d'), $this->value->format('d'), $day)); } return $this; } public function isInDay() { die('The method ' . __METHOD__ . ' is deprecated, please use ' . __CLASS__ . '::hasDay instead'); } public function hasDate($year, $month, $day, $failMessage = null) { if ($this->valueIsSet()->value->format('Y-m-d') === sprintf('%04d-%02d-%02d', $year, $month, $day)) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Date is %s instead of %s'), $this->value->format('Y-m-d'), sprintf('%04d-%02d-%02d', $year, $month, $day))); } return $this; } public function hasHours($hours, $failMessage = null) { if ($this->valueIsSet()->value->format('H') === sprintf('%02d', $hours)) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Hours are %s instead of %02d'), $this->value->format('H'), $hours)); } return $this; } public function hasMinutes($minutes, $failMessage = null) { if ($this->valueIsSet()->value->format('i') === sprintf('%02d', $minutes)) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Minutes are %s instead of %02d'), $this->value->format('i'), $minutes)); } return $this; } public function hasSeconds($seconds, $failMessage = null) { if ($this->valueIsSet()->value->format('s') === sprintf('%02d', $seconds)) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Seconds are %s instead of %02d'), $this->value->format('s'), $seconds)); } return $this; } public function hasTime($hours, $minutes, $seconds, $failMessage = null) { if ($this->valueIsSet()->value->format('H:i:s') === sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds)) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Time is %s instead of %s'), $this->value->format('H:i:s'), sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds))); } return $this; } public function hasDateAndTime($year, $month, $day, $hours, $minutes, $seconds, $failMessage = null) { if ($this->valueIsSet()->value->format('Y-m-d H:i:s') === sprintf('%04d-%02d-%02d %02d:%02d:%02d', $year, $month, $day, $hours, $minutes, $seconds)) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Datetime is %s instead of %s'), $this->value->format('Y-m-d H:i:s'), sprintf('%04d-%02d-%02d %02d:%02d:%02d', $year, $month, $day, $hours, $minutes, $seconds))); } return $this; } protected function valueIsSet($message = 'Instance of \dateTime is undefined') { if (self::isDateTime(parent::valueIsSet($message)->value) === false) { throw new exceptions\logic($message); } return $this; } protected static function check($value, $method) { if (self::isDateTime($value) === false) { throw new exceptions\logic('Argument of ' . $method . '() must be an instance of \\dateTime'); } } protected static function isDateTime($value) { return ($value instanceof \dateTime); } } setScore($score); } public function setWithTest(atoum\test $test) { return $this->setScore($test->getScore()); } public function setWith($message = null, $type = null) { return $this ->withType($type) ->withMessage($message) ; } public function setScore(atoum\test\score $score = null) { $this->score = $score ?: new atoum\test\score(); return $this; } public function getScore() { return $this->score; } public function getMessage() { return $this->message; } public function getType() { return $this->type; } public function exists() { $key = $this->score->errorExists($this->message, $this->type, $this->messageIsPattern); if ($key !== null) { $this->score->deleteError($key); $this->pass(); } else { $failReason = ''; switch (true) { case $this->type === null && $this->message === null: $failReason = $this->getLocale()->_('error does not exist'); break; case $this->type === null && $this->message !== null: $failReason = sprintf($this->getLocale()->_('error with message \'%s\' does not exist'), $this->message); break; case $this->type !== null && $this->message === null: $failReason = sprintf($this->getLocale()->_('error of type %s does not exist'), self::getAsString($this->type)); break; default: $failReason = sprintf($this->getLocale()->_('error of type %s with message \'%s\' does not exist'), self::getAsString($this->type), $this->message); } $this->fail($failReason); } return $this; } public function notExists() { $score = $this->getScore(); $key = $score->errorExists($this->message, $this->type, $this->messageIsPattern); if ($key === null) { $this->pass(); } else { $failReason = ''; switch (true) { case $this->type === null && $this->message === null: $failReason = $this->getLocale()->_('error exists'); break; case $this->type === null && $this->message !== null: $failReason = sprintf($this->getLocale()->_('error with message \'%s\' exists'), $this->message); break; case $this->type !== null && $this->message === null: $failReason = sprintf($this->getLocale()->_('error of type %s exists'), self::getAsString($this->type)); break; default: $failReason = sprintf($this->getLocale()->_('error of type %s with message \'%s\' exists'), self::getAsString($this->type), $this->message); } $this->fail($failReason); } return $this; } public function withType($type) { $this->type = $type; return $this; } public function withAnyType() { $this->type = null; return $this; } public function messageIsPattern() { return $this->messageIsPattern; } public function withMessage($message) { $this->message = $message; $this->messageIsPattern = false; return $this; } public function withPattern($pattern) { $this->message = $pattern; $this->messageIsPattern = true; return $this; } public function withAnyMessage() { $this->message = null; $this->messageIsPattern = false; return $this; } public static function getAsString($errorType) { switch ($errorType) { case E_ERROR: return 'E_ERROR'; case E_WARNING: return 'E_WARNING'; case E_PARSE: return 'E_PARSE'; case E_NOTICE: return 'E_NOTICE'; case E_CORE_ERROR: return 'E_CORE_ERROR'; case E_CORE_WARNING: return 'E_CORE_WARNING'; case E_COMPILE_ERROR: return 'E_COMPILE_ERROR'; case E_COMPILE_WARNING: return 'E_COMPILE_WARNING'; case E_USER_ERROR: return 'E_USER_ERROR'; case E_USER_WARNING: return 'E_USER_WARNING'; case E_USER_NOTICE: return 'E_USER_NOTICE'; case E_STRICT: return 'E_STRICT'; case E_RECOVERABLE_ERROR: return 'E_RECOVERABLE_ERROR'; case E_DEPRECATED: return 'E_DEPRECATED'; case E_USER_DEPRECATED: return 'E_USER_DEPRECATED'; case E_ALL: return 'E_ALL'; default: return 'UNKNOWN'; } } } getMessageAsserter(); default: return $this->generator->__get($asserter); } } public function setWith($value, $label = null, $check = true) { $exception = $value; if ($exception instanceof \closure) { $exception = null; try { $value(); } catch (\exception $exception) {} } parent::setWith($exception, $label, false); if ($check === true) { if (self::isException($exception) === false) { $this->fail(sprintf($this->getLocale()->_('%s is not an exception'), $this)); } else { $this->pass(); } } return $this; } public function isInstanceOf($value, $failMessage = null) { try { self::check($value, __FUNCTION__); } catch (\logicException $exception) { if (self::classExists($value) === false || (strtolower(ltrim($value, '\\')) !== 'exception' && is_subclass_of($value, 'exception') === false)) { throw new exceptions\logic\invalidArgument('Argument of ' . __METHOD__ . '() must be a \exception instance or an exception class name'); } } return parent::isInstanceOf($value, $failMessage); } public function hasDefaultCode($failMessage = null) { if ($this->valueIsSet()->value->getCode() === 0) { return $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('code is %s instead of 0'), $this->value->getCode())); } } public function hasCode($code, $failMessage = null) { if ($this->valueIsSet()->value->getCode() === $code) { return $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('code is %s instead of %s'), $this->value->getCode(), $code)); } } public function hasMessage($message, $failMessage = null) { if ($this->valueIsSet()->value->getMessage() == (string) $message) { return $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('message \'%s\' is not identical to \'%s\''), $this->value->getMessage(), $message)); } } public function hasNestedException(\exception $exception = null, $failMessage = null) { if ($exception === null) { if ($this->valueIsSet()->value->getPrevious() !== null) { return $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : $this->getLocale()->_('exception does not contain any nested exception')); } } else { if ($this->valueIsSet()->value->getPrevious() == $exception) { return $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : $this->getLocale()->_('exception does not contain this nested exception')); } } } protected function valueIsSet($message = 'Exception is undefined') { return parent::valueIsSet($message); } protected function getMessageAsserter() { return $this->generator->__call('string', array($this->valueIsSet()->value->getMessage())); } protected static function check($value, $method) { if (self::isException($value) === false) { throw new exceptions\logic\invalidArgument('Argument of ' . __CLASS__ . '::' . $method . '() must be an exception instance'); } } protected static function isException($value) { return (parent::isObject($value) === true && $value instanceof \exception === true); } } setAdapter($adapter); } public function __toString() { return (string) $this->name; } public function setWith($name) { $this->name = $name; return $this; } public function setAdapter(atoum\adapter $adapter = null) { $this->adapter = $adapter ?: new atoum\adapter(); return $this; } public function getAdapter() { return $this->adapter; } public function reset() { $this->name = null; return $this; } public function getName() { return $this->name; } public function isLoaded($failMessage = null) { if ($this->valueIsSet()->adapter->extension_loaded($this->name) === true) { return $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('PHP extension \'%s\' is not loaded'), $this)); } } protected function valueIsSet($message = 'Name of PHP extension is undefined') { if ($this->name === null) { throw new exceptions\logic($message); } return $this; } protected function pass() { return $this; } protected function fail($reason) { throw new test\exceptions\skip($reason); } } value) === false) { $this->fail(sprintf($this->getLocale()->_('%s is not a float'), $this)); } else { $this->pass(); } return $this; } public function isNearlyEqualTo($value, $epsilon = null, $failMessage = null) { static::check($value, __FUNCTION__); if ($this->valueIsSet()->value !== $value) { // see http://www.floating-point-gui.de/errors/comparison/ for more informations $absValue = abs($value); $absCurrentValue = abs($this->value); $offset = abs($absCurrentValue - $absValue); $offsetIsNaN = is_nan($offset); if ($offsetIsNaN === false && $epsilon === null) { $epsilon = pow(10, - ini_get('precision')); } switch (true) { case $offsetIsNaN === true: case $offset / ($absCurrentValue + $absValue) >= $epsilon: case $absCurrentValue * $absValue == 0 && $offset >= pow($epsilon, 2): $diff = new diffs\variable(); $this->fail( ($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is not nearly equal to %s with epsilon %s'), $this, $this->getTypeOf($value), $epsilon)) . PHP_EOL . $diff->setReference($value)->setData($this->value) ); } } return $this; } protected static function check($value, $method) { if (self::isFloat($value) === false) { throw new exceptions\logic\invalidArgument('Argument of ' . __CLASS__ . '::' . $method . '() must be a float'); } } protected static function isFloat($value) { return (is_float($value) === true); } } isHash(40, $failMessage); } public function isSha256($failMessage = null) { return $this->isHash(64, $failMessage); } public function isSha512($failMessage = null) { return $this->isHash(128, $failMessage); } public function isMd5($failMessage = null) { return $this->isHash(32, $failMessage); } protected function isHash($length, $failMessage = null) { if (strlen($this->valueIsSet()->value) === $length) { $this->match('/^[a-fA-F0-9]+$/', sprintf($this->getLocale()->_('%s does not match given pattern'), $this)); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s should be a string of %d characters'), $this, $length)); } return $this; } } value) === false) { $this->fail(sprintf($this->getLocale()->_('%s is not an integer'), $this)); } else { $this->pass(); } return $this; } public function isZero($failMessage = null) { return $this->isEqualTo(0, $failMessage); } public function isEqualTo($value, $failMessage = null) { static::check($value, __FUNCTION__); return parent::isEqualTo($value, $failMessage); } public function isGreaterThan($value, $failMessage = null) { static::check($value, __FUNCTION__); if ($this->value > $value) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is not greater than %s'), $this, $this->getTypeOf($value))); } return $this; } public function isLessThan($value, $failMessage = null) { static::check($value, __FUNCTION__); if ($this->value < $value) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is not less than %s'), $this, $this->getTypeOf($value))); } return $this; } public function isGreaterThanOrEqualTo($value, $failMessage = null) { static::check($value, __FUNCTION__); if ($this->value >= $value) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is not greater than or equal to %s'), $this, $this->getTypeOf($value))); } return $this; } public function isLessThanOrEqualTo($value, $failMessage = null) { static::check($value, __FUNCTION__); if ($this->value <= $value) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is not less than or equal to %s'), $this, $this->getTypeOf($value))); } return $this; } protected static function check($value, $method) { if (self::isInteger($value) === false) { throw new exceptions\logic\invalidArgument('Argument of ' . __CLASS__ . '::' . $method . '() must be an integer'); } } protected static function isInteger($value) { return (is_integer($value) === true); } } mock !== null) { $this->mock->getMockController()->resetCalls(); } return $this; } public function getCall() { return ($this->call === null ? null : clone $this->call); } public function setWith($mock) { $this->mock = $mock; if ($this->mock instanceof \mageekguy\atoum\mock\aggregator === false) { $this->fail(sprintf($this->getLocale()->_('%s is not a mock'), $this->getTypeOf($this->mock))); } else { $this->pass(); } return $this; } public function getMock() { return $this->mock; } public function beforeMethodCall($methodName) { $this->mockIsSet()->beforeMethodCalls[] = $beforeMethodCall = new mock\call\mock($this, $this->mock, $methodName); return $beforeMethodCall; } public function getBeforeMethodCalls() { return $this->beforeMethodCalls; } public function withAnyMethodCallsBefore() { $this->beforeMethodCalls = array(); return $this; } public function afterMethodCall($methodName) { $this->mockIsSet()->afterMethodCalls[] = $afterMethodCall = new mock\call\mock($this, $this->mock, $methodName); return $afterMethodCall; } public function getAfterMethodCalls() { return $this->afterMethodCalls; } public function withAnyMethodCallsAfter() { $this->afterMethodCalls = array(); return $this; } public function beforeFunctionCall($functionName, test\adapter $adapter) { $this->mockIsSet()->beforeFunctionCalls[] = $beforeFunctionCall = new mock\call\adapter($this, $adapter, $functionName); return $beforeFunctionCall; } public function getBeforeFunctionCalls() { return $this->beforeFunctionCalls; } public function withAnyFunctionCallsBefore() { $this->beforeFunctionCalls = array(); return $this; } public function afterFunctionCall($functionName, test\adapter $adapter) { $this->mockIsSet()->afterFunctionCalls[] = $afterFunctionCall = new mock\call\adapter($this, $adapter, $functionName); return $afterFunctionCall; } public function getAfterFunctionCalls() { return $this->afterFunctionCalls; } public function withAnyFunctionCallsAfter() { $this->afterFunctionCalls = array(); return $this; } public function wasCalled($failMessage = null) { if (sizeof($this->mockIsSet()->mock->getMockController()->getCalls()) > 0) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is not called'), get_class($this->mock))); } return $this; } public function wasNotCalled($failMessage = null) { if (sizeof($this->mockIsSet()->mock->getMockController()->getCalls()) <= 0) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is called'), get_class($this->mock))); } return $this; } public function call($function) { if ($this->mockIsSet()->call === null) { $this->call = new php\call($function, null, $this->mock); } else { $this->call ->setFunction($function) ->setObject($this->mock) ->unsetArguments() ; } return $this; } public function withArguments() { $this->calledMethodNameIsSet()->call->setArguments(func_get_args())->notIdentical(); return $this; } public function withIdenticalArguments() { $this->calledMethodNameIsSet()->call->setArguments(func_get_args())->identical(); return $this; } public function withAtLeastArguments(array $arguments) { $this->calledMethodNameIsSet()->call->setArguments($arguments)->notIdentical(); return $this; } public function withAtLeastIdenticalArguments(array $arguments) { $this->calledMethodNameIsSet()->call->setArguments($arguments)->identical(); return $this; } public function withAnyArguments() { $this->calledMethodNameIsSet()->call->unsetArguments(); return $this; } public function withoutAnyArgument() { $this->calledMethodNameIsSet()->call->setArguments(array()); return $this; } public function once($failMessage = null) { return $this->exactly(1, $failMessage); } public function twice($failMessage = null) { return $this->exactly(2, $failMessage); } public function thrice($failMessage = null) { return $this->exactly(3, $failMessage); } public function atLeastOnce($failMessage = null) { $calls = $this->assertOnBeforeAndAfterCalls(); if (($callsNumber = sizeof($calls)) >= 1) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('method %s is called 0 time'), $this->call) . $this->getCallsAsString()); } return $this; } public function exactly($number, $failMessage = null) { $calls = $this->assertOnBeforeAndAfterCalls(); if (($callsNumber = sizeof($calls)) == $number) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf( $this->getLocale()->__( 'method %s is called %d time instead of %d', 'method %s is called %d times instead of %d', $callsNumber ), $this->call, $callsNumber, $number ) . $this->getCallsAsString() ); } return $this; } public function never($failMessage = null) { return $this->exactly(0, $failMessage); } protected function mockIsSet() { if ($this->mock === null) { throw new exceptions\logic('Mock is undefined'); } return $this; } protected function calledMethodNameIsSet() { if ($this->mockIsSet()->call === null) { throw new exceptions\logic('Called method is undefined'); } return $this; } protected function assertOnBeforeAndAfterCalls() { $calls = $this->calledMethodNameIsSet()->mock->getMockController()->getCalls($this->call->getFunction(), $this->call->getArguments(), $this->call->isIdentical()); if (sizeof($calls) > 0) { foreach ($this->beforeMethodCalls as $beforeMethodCall) { $firstCall = $beforeMethodCall->getFirstCall(); if ($firstCall === null) { $this->fail(sprintf($this->getLocale()->_('method %s is not called'), $beforeMethodCall)); } if (key($calls) > $firstCall) { $this->fail(sprintf($this->getLocale()->_('method %s is not called before method %s'), $this->call, $beforeMethodCall)); } $this->pass(); } foreach ($this->beforeFunctionCalls as $beforeFunctionCall) { $firstCall = $beforeFunctionCall->getFirstCall(); if ($firstCall === null) { $this->fail(sprintf($this->getLocale()->_('method %s is not called'), $beforeFunctionCall)); } if (key($calls) > $firstCall) { $this->fail(sprintf($this->getLocale()->_('method %s is not called before function %s'), $this->call, $beforeFunctionCall)); } $this->pass(); } foreach ($this->afterMethodCalls as $afterMethodCall) { $lastCall = $afterMethodCall->getLastCall(); if ($lastCall === null) { $this->fail(sprintf($this->getLocale()->_('method %s is not called'), $afterMethodCall)); } if (key($calls) < $lastCall) { $this->fail(sprintf($this->getLocale()->_('method %s is not called after method %s'), $this->call, $afterMethodCall)); } $this->pass(); } foreach ($this->afterFunctionCalls as $afterFunctionCall) { $lastCall = $afterFunctionCall->getLastCall(); if ($lastCall === null) { $this->fail(sprintf($this->getLocale()->_('method %s is not called'), $afterFunctionCall)); } if (key($calls) < $lastCall) { $this->fail(sprintf($this->getLocale()->_('method %s is not called after function %s'), $this->call, $afterFunctionCall)); } $this->pass(); } } $this->beforeMethodCalls = array(); $this->afterMethodCalls = array(); $this->beforeFunctionCalls = array(); $this->afterFunctionCalls = array(); return $calls; } protected function getCallsAsString() { $string = ''; if (($calls = $this->mock->getMockController()->getCalls($this->call->getFunction())) !== null) { $format = '[%' . strlen((string) sizeof($calls)) . 's] %s'; $phpCalls = array(); foreach (array_values($calls) as $call => $arguments) { $phpCalls[] = sprintf($format, $call + 1, new php\call($this->call->getFunction(), $arguments, $this->mock)); } $string = PHP_EOL . join(PHP_EOL, $phpCalls); } return $string; } } fail(sprintf($this->getLocale()->_('%s is not in format Y-m-d H:i:s'), $this)); } } return $this; } public function getValue() { $value = parent::getValue(); return ($value instanceof \dateTime === false ? $value : $value->format(self::mysqlDateTimeFormat)); } } toString(); default: return parent::__get($property); } } public function setWith($value, $checkType = true) { parent::setWith($value); if ($checkType === true) { if (self::isObject($this->value) === false) { $this->fail(sprintf($this->getLocale()->_('%s is not an object'), $this)); } else { $this->pass(); } } return $this; } public function isInstanceOf($value) { try { self::check($value, __FUNCTION__); } catch (\logicException $exception) { if (self::classExists($value) === false) { throw new exceptions\logic('Argument of ' . __METHOD__ . '() must be a class instance or a class name'); } } $this->valueIsSet()->value instanceof $value ? $this->pass() : $this->fail(sprintf($this->getLocale()->_('%s is not an instance of %s'), $this, is_string($value) === true ? $value : $this->getTypeOf($value))); return $this; } public function hasSize($size, $failMessage = null) { if (sizeof($this->valueIsSet()->value) == $size) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s has size %d, expected size %d'), $this, sizeof($this->valueIsSet()->value), $size)); } return $this; } public function isCloneOf($object, $failMessage = null) { if ($failMessage === null) { $failMessage = sprintf($this->getLocale()->_('%s is not a clone of %s'), $this, $this->getTypeOf($object)); } return $this->isEqualTo($object, $failMessage)->isNotIdenticalTo($object, $failMessage); } public function isEmpty($failMessage = null) { if (sizeof($this->valueIsSet()->value) == 0) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s has size %d'), $this, sizeof($this->value))); } return $this; } public function toString() { return $this->generator->castToString($this->valueIsSet()->value); } protected function valueIsSet($message = 'Object is undefined') { if (self::isObject(parent::valueIsSet($message)->value) === false) { throw new exceptions\logic($message); } return $this; } protected static function check($value, $method) { if (self::isObject($value) === false) { throw new exceptions\logic('Argument of ' . __CLASS__ . '::' . $method . '() must be a class instance'); } } protected static function isObject($value) { return (is_object($value) === true); } protected static function classExists($value) { return (class_exists($value) === true || interface_exists($value) === true); } } setWith(null); } public function setWith($value = null, $label = null, $charlist = null, $checkType = true) { if ($value instanceof \closure) { ob_start(); $value(); $value = ob_get_clean(); } else if ($value === null && ob_get_level() > 0) { $value = ob_get_clean(); ob_start(); } return parent::setWith($value, $label, $charlist, $checkType); } } getSizeAsserter(); default: return $this->generator->__get($asserter); } } public function setWith($value, $label = null) { parent::setWith($value, $label); if (self::isArray($this->value) === false) { $this->fail(sprintf($this->getLocale()->_('%s is not an array'), $this)); } else { $this->pass(); } return $this; } public function hasSize($size, $failMessage = null) { if (sizeof($this->valueIsSet()->value) == $size) { $this->pass(); } else { $this->fail($failMessage ?: sprintf($this->getLocale()->_('%s has not size %d'), $this, $size)); } return $this; } public function isEmpty($failMessage = null) { if (sizeof($this->valueIsSet()->value) == 0) { $this->pass(); } else { $this->fail($failMessage ?: sprintf($this->getLocale()->_('%s is not empty'), $this)); } return $this; } public function isNotEmpty($failMessage = null) { if (sizeof($this->valueIsSet()->value) > 0) { $this->pass(); } else { $this->fail($failMessage ?: sprintf($this->getLocale()->_('%s is empty'), $this)); } return $this; } public function strictlyContains($value, $failMessage = null) { return $this->containsValue($value, $failMessage, true); } public function contains($value, $failMessage = null) { return $this->containsValue($value, $failMessage, false); } public function strictlyNotContains($value, $failMessage = null) { return $this->notContainsValue($value, $failMessage, true); } public function notContains($value, $failMessage = null) { return $this->notContainsValue($value, $failMessage, false); } public function atKey($key, $failMessage = null) { $this->hasKey($key, $failMessage)->key = $key; return $this; } public function hasKeys(array $keys, $failMessage = null) { if (sizeof($undefinedKeys = array_diff($keys, array_keys($this->value))) <= 0) { $this->pass(); } else { $this->fail($failMessage ?: sprintf($this->getLocale()->_('%s should have keys %s'), $this, $this->getTypeOf($undefinedKeys))); } return $this; } public function notHasKeys(array $keys, $failMessage = null) { if (sizeof($definedKeys = array_intersect(array_keys($this->value), $keys)) <= 0) { $this->pass(); } else { $this->fail($failMessage ?: sprintf($this->getLocale()->_('%s should not have keys %s'), $this, $this->getTypeOf($definedKeys))); } return $this; } public function hasKey($key, $failMessage = null) { if (array_key_exists($key, $this->valueIsSet()->value)) { $this->pass(); } else { $this->fail($failMessage ?: sprintf($this->getLocale()->_('%s has no key %s'), $this, $this->getTypeOf($key))); } return $this; } public function notHasKey($key, $failMessage = null) { if (array_key_exists($key, $this->value) === false) { $this->pass(); } else { $this->fail($failMessage ?: sprintf($this->getLocale()->_('%s has a key %s'), $this, $this->getTypeOf($key))); } return $this; } public function containsValues(array $values, $failMessage = null) { return $this->intersect($values, $failMessage, false); } public function strictlyContainsValues(array $values, $failMessage = null) { return $this->intersect($values, $failMessage, true); } public function notContainsValues(array $values, $failMessage = null) { return $this->notIntersect($values, $failMessage, false); } public function strictlyNotContainsValues(array $values, $failMessage = null) { return $this->notIntersect($values, $failMessage, true); } protected function containsValue($value, $failMessage, $strict) { if (in_array($value, $this->valueIsSet()->value, $strict) === true) { if ($this->key === null) { $this->pass(); } else { $pass = false; if ($strict === false) { $pass = ($this->value[$this->key] == $value); } else { $pass = ($this->value[$this->key] === $value); } if ($pass === false) { $key = $this->key; } $this->key = null; if ($pass === true) { $this->pass(); } else { if ($strict === false) { $failMessage = sprintf($this->getLocale()->_('%s does not contain %s at key %s'), $this, $this->getTypeOf($value), $this->getTypeOf($key)); } else { $failMessage = sprintf($this->getLocale()->_('%s does not strictly contain %s at key %s'), $this, $this->getTypeOf($value), $this->getTypeOf($key)); } $this->fail($failMessage); } } } else { if ($failMessage === null) { if ($strict === false) { $failMessage = sprintf($this->getLocale()->_('%s does not contain %s'), $this, $this->getTypeOf($value)); } else { $failMessage = sprintf($this->getLocale()->_('%s does not strictly contain %s'), $this, $this->getTypeOf($value)); } } $this->fail($failMessage); } return $this; } protected function notContainsValue($value, $failMessage, $strict) { if (in_array($value, $this->valueIsSet()->value, $strict) === false) { $this->pass(); } else { if ($this->key === null) { if ($failMessage === null) { if ($strict === false) { $failMessage = sprintf($this->getLocale()->_('%s contains %s'), $this, $this->getTypeOf($value)); } else { $failMessage = sprintf($this->getLocale()->_('%s strictly contains %s'), $this, $this->getTypeOf($value)); } } $this->fail($failMessage); } else { $pass = false; if ($strict === false) { $pass = ($this->value[$this->key] != $value); } else { $pass = ($this->value[$this->key] !== $value); } if ($pass === false) { $key = $this->key; } $this->key = null; if ($pass === true) { $this->pass(); } else { if ($strict === false) { $failMessage = sprintf($this->getLocale()->_('%s contains %s at key %s'), $this, $this->getTypeOf($value), $this->getTypeOf($key)); } else { $failMessage = sprintf($this->getLocale()->_('%s strictly contains %s at key %s'), $this, $this->getTypeOf($value), $this->getTypeOf($key)); } $this->fail($failMessage); } } } return $this; } protected function intersect(array $values, $failMessage, $strict) { $unknownValues = array(); foreach ($values as $value) if (in_array($value, $this->value, $strict) === false) { $unknownValues[] = $value; } if (sizeof($unknownValues) <= 0) { $this->pass(); } else { if ($failMessage === null) { if ($strict === false) { $failMessage = sprintf($this->getLocale()->_('%s does not contain values %s'), $this, $this->getTypeOf($unknownValues)); } else { $failMessage = sprintf($this->getLocale()->_('%s does not contain strictly values %s'), $this, $this->getTypeOf($unknownValues)); } } $this->fail($failMessage); } return $this; } protected function notIntersect(array $values, $failMessage, $strict) { $knownValues = array(); foreach ($values as $value) if (in_array($value, $this->value, $strict) === true) { $knownValues[] = $value; } if (sizeof($knownValues) <= 0) { $this->pass(); } else { if ($failMessage === null) { if ($strict === false) { $failMessage = sprintf($this->getLocale()->_('%s should not contain values %s'), $this, $this->getTypeOf($knownValues)); } else { $failMessage = sprintf($this->getLocale()->_('%s should not contain strictly values %s'), $this, $this->getTypeOf($knownValues)); } } $this->fail($failMessage); } return $this; } protected function valueIsSet($message = 'Array is undefined') { return parent::valueIsSet($message); } protected function getSizeAsserter() { return $this->generator->__call('integer', array(sizeof($this->valueIsSet()->value))); } protected static function check($value, $method) { if (self::isArray($value) === false) { throw new exceptions\logic\invalidArgument('Argument of ' . $method . '() must be an array'); } } protected static function isArray($value) { return (is_array($value) === true); } } reflectionClassInjector === null) { $reflectionClass = new \reflectionClass($class); } else { $reflectionClass = $this->reflectionClassInjector->__invoke($class); if ($reflectionClass instanceof \reflectionClass === false) { throw new exceptions\runtime\unexpectedValue('Reflection class injector must return a \reflectionClass instance'); } } return $reflectionClass; } public function setReflectionClassInjector(\closure $reflectionClassInjector) { $closure = new \reflectionMethod($reflectionClassInjector, '__invoke'); if ($closure->getNumberOfParameters() != 1) { throw new exceptions\logic\invalidArgument('Reflection class injector must take one argument'); } $this->reflectionClassInjector = $reflectionClassInjector; return $this; } public function getClass() { return ($this->class === null ? null : $this->class->getName()); } public function setWith($class) { try { $this->class = $this->getReflectionClass($class); } catch (\exception $exception) { $this->fail(sprintf($this->getLocale()->_('Class \'%s\' does not exist'), $class)); } $this->pass(); return $this; } public function hasParent($parent, $failMessage = null) { $parentClass = $this->classIsSet()->class->getParentClass(); if ($parentClass !== false && strtolower($parentClass->getName()) == strtolower($parent)) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is not the parent of class %s'), $parent, $this->class->getName())); } return $this; } public function isSubClassOf($parent, $failMessage = null) { if ($this->classIsSet()->class->isSubClassOf($parent) == true) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Class %s is not a sub-class of %s'), $this->class->getName(), $parent)); } return $this; } public function hasNoParent($failMessage = null) { if (($parentClass = $this->classIsSet()->class->getParentClass()) === false) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('class %s has parent %s'), $this->class->getName(), $parentClass)); } return $this; } public function hasInterface($interface, $failMessage = null) { if ($this->classIsSet()->class->implementsInterface($interface) === true) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Class %s does not implement interface %s'), $this->class->getName(), $interface)); } return $this; } public function isAbstract($failMessage = null) { if ($this->classIsSet()->class->isAbstract() === true) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Class %s is not abstract'), $this->class->getName())); } return $this; } public function hasMethod($method, $failMessage = null) { if ($this->classIsSet()->class->hasMethod($method) === true) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Method %s::%s() does not exist'), $this->class->getName(), $method)); } return $this; } protected function classIsSet() { if ($this->class === null) { throw new exceptions\logic('Class is undefined'); } return $this; } } streamController = atoum\mock\stream::get($stream); return $this; } public function getStreamController() { return $this->streamController; } public function isRead($failMessage = null) { if (sizeof($this->streamIsSet()->streamController->getCalls('stream_read')) > 0) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('stream %s is not read'), $this->streamController)); } return $this; } public function isWrited($failMessage = null) { if (sizeof($this->streamIsSet()->streamController->getCalls('stream_write')) > 0) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('stream %s is not writed'), $this->streamController)); } return $this; } protected function streamIsSet() { if ($this->streamController === null) { throw new exceptions\logic('Stream is undefined'); } return $this; } } setAdapter($adapter); } public function __get($asserter) { switch ($asserter) { case 'length': return $this->getLengthAsserter(); default: return $this->generator->__get($asserter); } } public function __toString() { return (is_string($this->value) === false ? parent::__toString() : sprintf($this->getLocale()->_('string(%s) \'%s\''), strlen($this->value), addcslashes($this->value, $this->charlist))); } public function setAdapter(atoum\adapter $adapter = null) { $this->adapter = $adapter ?: new atoum\adapter(); return $this; } public function getAdapter() { return $this->adapter; } public function getCharlist() { return $this->charlist; } public function setWith($value, $label = null, $charlist = null, $checkType = true) { parent::setWith($value, $label); $this->charlist = $charlist; if ($checkType === true) { if (self::isString($this->value) === true) { $this->pass(); } else { $this->fail(sprintf($this->getLocale()->_('%s is not a string'), $this)); } } return $this; } public function isEmpty($failMessage = null) { return $this->isEqualTo('', $failMessage); } public function isNotEmpty($failMessage = null) { return $this->isNotEqualTo('', $failMessage !== null ? $failMessage : $this->getLocale()->_('string is empty')); } public function match($pattern, $failMessage = null) { if (preg_match($pattern, $this->valueIsSet()->value) === 1) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s does not match %s'), $this, $pattern)); } return $this; } public function isEqualTo($value, $failMessage = null) { return parent::isEqualTo($value, $failMessage !== null ? $failMessage : $this->getLocale()->_('strings are not equals')); } public function isEqualToContentsOfFile($path, $failMessage = null) { $fileContents = @$this->valueIsSet()->adapter->file_get_contents($path); if ($fileContents === false) { $this->fail(sprintf($this->getLocale()->_('Unable to get contents of file %s'), $path)); } else { return parent::isEqualTo($fileContents, $failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('string is not equals to contents of file %s'), $path)); } } public function hasLength($length, $failMessage = null) { if (strlen($this->valueIsSet()->value) == $length) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('length of %s is not %d'), $this, $length)); } return $this; } public function hasLengthGreaterThan($length, $failMessage = null) { if (strlen($this->valueIsSet()->value) > $length) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('length of %s is not greater than %d'), $this, $length)); } return $this; } public function hasLengthLessThan($length, $failMessage = null) { if (strlen($this->valueIsSet()->value) < $length) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('length of %s is not less than %d'), $this, $length)); } return $this; } public function contains($fragment, $failMessage = null) { if (strpos($this->valueIsSet()->value, $fragment) !== false) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('String does not contain %s'), $fragment)); } return $this; } protected function getLengthAsserter() { return $this->generator->__call('integer', array(strlen($this->valueIsSet()->value))); } protected static function check($value, $method) { if (self::isString($value) === false) { throw new exceptions\logic\invalidArgument('Argument of ' . $method . '() must be a string'); } } protected static function isString($value) { return (is_string($value) === true); } } getTestedClassName()); return parent::setWithTest($test); } } adapter->extension_loaded('mbstring') === false) { throw new exceptions\runtime('mbstring PHP extension is mandatory to use utf8String asserter'); } } public function __toString() { return (is_string($this->value) === false ? parent::__toString() : sprintf($this->getLocale()->_('string(%s) \'%s\''), mb_strlen($this->value, 'UTF-8'), addcslashes($this->value, $this->charlist))); } public function setWith($value, $label = null, $charlist = null, $checkType = true) { parent::setWith($value, $label, $charlist, $checkType); if ($checkType === true) { if (static::isUtf8($this->value) === true) { $this->pass(); } else { $this->fail(sprintf($this->getLocale()->_('\'%s\' is not an UTF-8 string'), $value)); } } return $this; } public function hasLength($length, $failMessage = null) { if (mb_strlen($this->valueIsSet()->value, 'UTF-8') == $length) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('length of %s is not %d'), $this, $length)); } return $this; } public function hasLengthGreaterThan($length, $failMessage = null) { if (mb_strlen($this->valueIsSet()->value, 'UTF-8') > $length) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('length of %s is not greater than %d'), $this, $length)); } return $this; } public function hasLengthLessThan($length, $failMessage = null) { if (mb_strlen($this->valueIsSet()->value, 'UTF-8') < $length) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('length of %s is not less than %d'), $this, $length)); } return $this; } public function contains($fragment, $failMessage = null) { if (static::isUtf8($fragment) === false) { throw new exceptions\logic\invalidArgument('Fragment \'' . $fragment . '\' is not an UTF-8 string'); } if (mb_strpos($this->valueIsSet()->value, $fragment, 0, 'UTF-8') !== false) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('String does not contain %s'), $fragment)); } return $this; } public function getTypeOf($mixed) { return (is_string($mixed) === false ? parent::getTypeOf($mixed) : sprintf($this->getLocale()->_('string(%s) \'%s\''), mb_strlen($mixed, 'UTF-8'), $mixed)); } protected function getLengthAsserter() { return $this->generator->__call('integer', array(mb_strlen($this->valueIsSet()->value, 'UTF-8'))); } protected static function isUtf8($string) { return (preg_match('/^.*$/us', $string) === 1); } } getTypeOf($this->value); } public function wasSet() { return ($this->isSet === true); } public function setWith($value) { $this->value = $value; $this->isSet = true; $this->isSetByReference = false; return $this; } public function setByReferenceWith(& $value) { $this->value = & $value; $this->isSet = true; $this->isSetByReference = true; return $this; } public function reset() { $this->value = null; $this->isSet = false; $this->isSetByReference = false; return $this; } public function getValue() { return $this->value; } public function isSetByReference() { return ($this->isSet === true && $this->isSetByReference === true); } public function isEqualTo($value, $failMessage = null) { self::check($value, __FUNCTION__); if ($this->valueIsSet()->value == $value) { $this->pass(); } else { $diff = new diffs\variable(); $this->fail( ($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is not equal to %s'), $this, $this->getTypeOf($value))) . PHP_EOL . $diff->setReference($value)->setData($this->value) ); } return $this; } public function isNotEqualTo($value, $failMessage = null) { self::check($value, __FUNCTION__); if ($this->valueIsSet()->value != $value) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is equal to %s'), $this, $this->getTypeOf($value))); } return $this; } public function isIdenticalTo($value, $failMessage = null) { self::check($value, __FUNCTION__); if ($this->valueIsSet()->value === $value) { $this->pass(); } else { $diff = new diffs\variable(); $this->fail( ($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is not identical to %s'), $this, $this->getTypeOf($value))) . PHP_EOL . $diff->setReference($value)->setData($this->value) ); } return $this; } public function isNotIdenticalTo($value, $failMessage = null) { self::check($value, __FUNCTION__); if ($this->valueIsSet()->value !== $value) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is identical to %s'), $this, $this->getTypeOf($value))); } return $this; } public function isNull($failMessage = null) { if ($this->valueIsSet()->value === null) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is not null'), $this)); } return $this; } public function isNotNull($failMessage = null) { if ($this->valueIsSet()->value !== null) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is null'), $this)); } return $this; } public function isNotFalse($failMessage = null) { return $this->isNotIdenticalTo(false, $failMessage ?: sprintf($this->getLocale()->_('%s is false'), $this)); } public function isNotTrue($failMessage = null) { return $this->isNotIdenticalTo(true, $failMessage ?: sprintf($this->getLocale()->_('%s is true'), $this)); } public function isReferenceTo(& $reference, $failMessage = null) { if ($this->valueIsSet()->isSetByReference() === false) { throw new exceptions\logic('Value is not set by reference'); } if (is_object($this->value) === true && is_object($reference) === true) { if ($this->value === $reference) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is not a reference to %s'), $this, $this->getTypeOf($reference))); } } else { $tmp = $reference; $reference = uniqid(mt_rand()); $isReference = ($this->value === $reference); $reference = $tmp; if ($isReference === true) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is not a reference to %s'), $this, $this->getTypeOf($reference))); } } return $this; } public function isCallable($failMessage = null) { if (is_callable($this->valueIsSet()->value) === true) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is not callable'), $this)); } return $this; } public function isNotCallable($failMessage = null) { if (is_callable($this->valueIsSet()->value) === false) { $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('%s is callable'), $this)); } return $this; } protected function valueIsSet($message = 'Value is undefined') { if ($this->isSet === false) { throw new exceptions\logic($message); } return $this; } protected static function check($value, $method) {} } setForeground($foreground); } if ($background !== null) { $this->setBackground($background); } $this->setCli($cli ?: new atoum\cli()); } public function setCli(atoum\cli $cli) { $this->cli = $cli; return $this; } public function getCli() { return $this->cli; } public function setForeground($foreground) { $this->foreground = (string) $foreground; return $this; } public function getForeground() { return $this->foreground; } public function setBackground($background) { $this->background = (string) $background; return $this; } public function getBackground() { return $this->background; } public function colorize($string) { if ($this->cli->isTerminal() === true && ($this->foreground !== null || $this->background !== null)) { if ($this->background !== null) { $string = "\033[" . $this->background . 'm' . $string; } if ($this->foreground !== null) { $string = "\033[" . $this->foreground . 'm' . $string; } $string .= "\033[0m"; } return $string; } } iterations = $iterations; $this->progressBarFormat = self::defaultProgressBarFormat; $this->counterFormat = self::defaultCounterFormat; $this->setCli($cli ?: new atoum\cli()); } public function reset() { $this->refresh = null; $this->iterations = 0; $this->currentIteration = 0; $this->progressBar = null; $this->counter = null; return $this; } public function setIterations($iterations) { $this->reset()->iterations = (int) $iterations; return $this; } public function setCli(atoum\cli $cli) { $this->cli = $cli; return $this; } public function getCli() { return $this->cli; } public function __toString() { $string = ''; if ($this->progressBar === null && $this->counter === null) { $this->progressBar = sprintf($this->progressBarFormat, ($this->iterations > self::width ? str_repeat('.', self::width - 1) . '>' : str_pad(str_repeat('.', $this->iterations), self::width, '_', STR_PAD_RIGHT))); $this->counter = sprintf($this->counterFormat, sprintf('%' . strlen((string) $this->iterations) . 'd', $this->currentIteration), $this->iterations); $string .= $this->progressBar . $this->counter; } if ($this->refresh !== null) { $refreshLength = strlen($this->refresh); $this->currentIteration += $refreshLength; if ($this->cli->isTerminal() === false) { $this->progressBar = substr($this->progressBar, 0, $this->currentIteration) . $this->refresh . substr($this->progressBar, $this->currentIteration + 1); $string .= PHP_EOL . $this->progressBar; } else { $string .= str_repeat("\010", (strlen($this->progressBar) - $refreshLength) + strlen($this->counter)); $this->progressBar = $this->refresh . substr($this->progressBar, $refreshLength + 1); $string .= $this->progressBar; } $this->counter = sprintf($this->counterFormat, sprintf('%' . strlen((string) $this->iterations) . 'd', $this->currentIteration), $this->iterations); $string .= $this->counter; if ($this->iterations > self::width && $this->iterations - $this->currentIteration && $this->currentIteration % (self::width - 1) == 0) { $this->progressBar = '[' . (($this->iterations - $this->currentIteration) > (self::width - 1) ? str_repeat('.', self::width - 1) . '>' : str_pad(str_repeat('.', $this->iterations - $this->currentIteration), self::width, '_', STR_PAD_RIGHT)) . ']'; $this->counter = ''; $string .= PHP_EOL . $this->progressBar; } $this->refresh = null; } return $string; } public function refresh($value) { if ($this->iterations > 0 && $this->currentIteration < $this->iterations) { $this->refresh .= $value; } return $this; } } setValue($value) ->setColorizer($colorizer) ; } public function __toString() { return $this->colorizer->colorize($this->value); } public function setValue($value) { $this->value = (string) $value; return $this; } public function getValue() { return $this->value; } public function setColorizer(colorizer $colorizer) { $this->colorizer = $colorizer; return $this; } public function getColorizer() { return $this->colorizer; } } getInnerIterator()->current()->getBasename()) { case 'GPATH': case 'GRTAGS': case 'GTAGS': return false; default: return parent::accept(); } } } addClosure($c); } } public function addClosure(\closure $closure) { $this->closures[] = $closure; return $this; } public function getClosures() { return $this->closures; } public function accept() { foreach ($this->closures as $closure) { if ($closure($this->current(), $this->key(), $this->getInnerIterator()) === false) { return false; } } return true; } public function getChildren() { return new static( $this->getInnerIterator()->getChildren(), $this->closures ); } } getInnerIterator()->current()->getBasename(), 0, 1) != '.'); } } setAcceptedExtensions($acceptedExtensions); } public function setAcceptedExtensions(array $extensions) { array_walk($extensions, function(& $extension) { $extension = trim($extension, '.'); }); $this->acceptedExtensions = $extensions; return $this; } public function getAcceptedExtensions() { return $this->acceptedExtensions; } public function accept() { $path = basename((string) $this->getInnerIterator()->current()); $extension = pathinfo($path, PATHINFO_EXTENSION); return ($extension == '' || in_array($extension, $this->acceptedExtensions) === true); } public function getChildren() { return new self($this->getInnerIterator()->getChildren(), $this->acceptedExtensions); } } sourceDirectory = (string) $sourceDirectory; $this->pharDirectory = $pharDirectory === null ? null : (string) $pharDirectory; $this->innerIterator = new \recursiveIteratorIterator(new iterators\filters\recursives\atoum\source($this->sourceDirectory)); $this->innerIterator->rewind(); } public function getSourceDirectory() { return $this->sourceDirectory; } public function getPharDirectory() { return $this->pharDirectory; } public function getInnerIterator() { return $this->innerIterator; } public function current() { $current = $this->innerIterator->current(); return $current === null ? null : (string) $current; } public function key() { return $this->pharDirectory === null ? $this->innerIterator->key() : preg_replace('#^(:[^:]+://)?' . preg_quote($this->sourceDirectory, '#') . '#', $this->pharDirectory, $this->innerIterator->current()); } public function next() { return $this->innerIterator->next(); } public function rewind() { return $this->innerIterator->rewind(); } public function valid() { return $this->innerIterator->valid(); } } setIteratorFactory($iteratorFactory) ->setDotFilterFactory($dotFilterFactory) ->setExtensionFilterFactory($extensionFilterFactory) ; } public function setIteratorFactory(\closure $factory = null) { $this->iteratorFactory = $factory ?: function($path) { return new \recursiveDirectoryIterator($path); }; return $this; } public function getIteratorFactory() { return $this->iteratorFactory; } public function setDotFilterFactory(\closure $factory = null) { $this->dotFilterFactory = $factory ?: function($iterator) { return new filters\recursives\dot($iterator); }; return $this; } public function getDotFilterFactory() { return $this->dotFilterFactory; } public function setExtensionFilterFactory(\closure $factory = null) { $this->extensionFilterFactory = $factory ?: function($iterator, $extensions) { return new filters\recursives\extension($iterator, $extensions); }; return $this; } public function getExtensionFilterFactory() { return $this->extensionFilterFactory; } public function getIterator($path) { $iterator = call_user_func($this->iteratorFactory, $path); if ($this->acceptDots === false) { $iterator = call_user_func($this->dotFilterFactory, $iterator); } if (sizeof($this->acceptedExtensions) > 0) { $iterator = call_user_func($this->extensionFilterFactory, $iterator, $this->acceptedExtensions); } return $iterator; } public function dotsAreAccepted() { return $this->acceptDots; } public function acceptDots() { $this->acceptDots = true; return $this; } public function refuseDots() { $this->acceptDots = false; return $this; } public function getAcceptedExtensions() { return $this->acceptedExtensions; } public function acceptExtensions(array $extensions) { $this->acceptedExtensions = array(); foreach ($extensions as $extension) { $this->acceptedExtensions[] = self::cleanExtension($extension); } return $this; } public function acceptAllExtensions() { return $this->acceptExtensions(array()); } public function refuseExtension($extension) { $key = array_search(self::cleanExtension($extension), $this->acceptedExtensions); if ($key !== false) { unset($this->acceptedExtensions[$key]); $this->acceptedExtensions = array_values($this->acceptedExtensions); } return $this; } protected static function cleanExtension($extension) { return trim($extension, '.'); } } to === null) { throw new exceptions\runtime('To is undefined'); } if ($this->subject === null) { throw new exceptions\runtime('Subject is undefined'); } if ($this->from === null) { throw new exceptions\runtime('From is undefined'); } if ($this->replyTo === null) { throw new exceptions\runtime('Reply to is undefined'); } if ($this->xMailer === null) { throw new exceptions\runtime('X-mailer is undefined'); } $headers = 'From: ' . $this->from . self::eol . 'Reply-To: ' . $this->replyTo . self::eol . 'X-Mailer: ' . $this->xMailer; if ($this->contentType !== null) { $headers .= self::eol . 'Content-Type: ' . $this->contentType[0] . '; charset="' . $this->contentType[1] . '"'; } $this->adapter->mail($this->to, $this->subject, (string) $something, $headers); return $this; } } control($mock); } public static function get(mock\aggregator $mock) { return (isset(self::$instances[$mock]) === false ? null : self::$instances[$mock]); } public static function remove(mock\aggregator $mock) { if (isset(self::$instances[$mock]) === true) { self::$instances[$mock]->reset(); unset(self::$instances[$mock]); } } public static function clean() { self::$instances = new \splObjectStorage(); } } collector::clean(); setMockController($controller); } } public function __set($keyword, $mixed) { foreach ($this->getMethods() as $method) { $this->controller->{$method}->{$keyword} = $mixed; } return $this; } public function getIterator() { return new \arrayIterator($this->getMethods()); } public function setMockController(mock\controller $controller) { $this->controller = $controller; return $this; } public function getMockController() { return $this->controller; } public function getMethods() { $methods = ($this->controller === null ? array() : $this->controller->getMethods()); foreach ($this->filters as $filter) { $methods = array_filter($methods, $filter); } return array_values(array_filter($methods, function($name) { return ($name !== '__construct'); })); } public function addFilter(\closure $filter) { $this->filters[] = $filter; return $this; } public function getFilters() { return $this->filters; } public function resetFilters() { $this->filters = array(); return $this; } } name = $name; } public function __toString() { $string = '$' . $this->name; if ($this->isReference === true) { $string = '& ' . $string; } if ($this->type !== null) { $string = $this->type . ' ' . $string; } if ($this->defaultValueIsSet === true) { $string .= '=' . var_export($this->defaultValue, true); } return $string; } public function getName() { return $this->name; } public function getVariable() { return '$' . $this->name; } public function isObject($type) { $this->type = $type; return $this; } public function isArray() { $this->type = 'array'; return $this; } public function isUntyped() { $this->type = null; return $this; } public function isReference() { $this->isReference = true; return $this; } public function setDefaultValue($defaultValue) { $this->defaultValue = $defaultValue; $this->defaultValueIsSet = true; return $this; } public static function get($name) { return new static($name); } } name = $name; $this->isConstructor = ($name == __FUNCTION__); } public function __toString() { $string = 'public function '; if ($this->returnReference === true) { $string .= '& '; } $string .= $this->name . '(' . $this->getArgumentsAsString() . ')'; return $string; } public function getArguments() { return $this->arguments; } public function getName() { return $this->name; } public function isConstructor() { return $this->isConstructor; } public function returnReference() { if ($this->isConstructor === true) { throw new exceptions\logic('Constructor can not return a reference'); } $this->returnReference = true; return $this; } public function addArgument(method\argument $argument) { $this->arguments[] = $argument; return $this; } public function getArgumentsAsString() { $arguments = $this->arguments; array_walk($arguments, function(& $value) { $value = (string) $value; }); return join(', ', $arguments); } public static function get($name) { return new static($name); } } path = (string) $path; } public function __toString() { return $this->getPath(); } public function __get($method) { $method = static::mapMethod($method); return $this->setInvoker($method, function() use ($method) { return new invoker($method); }); } public function __set($method, $value) { switch (strtolower($method)) { case 'file_get_contents': if ($value === false) { $this->fopen = false; } else { $this->stat = array('mode' => 33188); $this->fopen = true; $this->fread[1] = $value; $this->fread[2] = false; $this->fclose = true; } return $this; case 'file_put_contents': $this->stat = array('mode' => 33188); $this->fopen = true; $this->fwrite = $value; $this->fclose = true; return $this; default: $method = static::mapMethod($method); switch ($method) { case 'dir_opendir': $this->dir_closedir = true; $this->dir_rewinddir = true; $this->dir_readdir = false; $this->url_stat = array('mode' => 16877); break; case 'dir_readdir': if ($value instanceof self) { $value = $value->getBasename(); } break; } return parent::__set($method, $value); } } public function __isset($method) { return parent::__isset(static::mapMethod($method)); } public function duplicate() { $controller = clone $this; $controller->path = & $this->path; $controller->calls = & $this->calls; $controller->invokers = & $this->invokers; return $controller; } public function setPath($path) { $this->path = $path; return $this; } public function getPath() { return $this->path; } public function getBasename() { return basename($this->path); } public function invoke($method, array $arguments = array()) { $method = static::mapMethod($method); if ($method === 'dir_rewinddir' && isset($this->{$method}) === true) { $this->resetCalls('dir_readdir'); } return ($this->nextCallIsOverloaded($method) === false ? null : parent::invoke($method, $arguments)); } protected function buildInvoker() { return new invoker(); } protected static function mapMethod($method) { $method = strtolower($method); switch ($method) { case 'mkdir': case 'rmdir': case 'rename': case 'unlink': case '__construct': case 'stream_set_option': return $method; case 'closedir': case 'dir_closedir': return 'dir_closedir'; case 'opendir': case 'dir_opendir': return 'dir_opendir'; case 'readdir': case 'dir_readdir': return 'dir_readdir'; case 'rewinddir': case 'dir_rewinddir': return 'dir_rewinddir'; case 'select': case 'stream_cast': return 'stream_cast'; case 'fclose': case 'stream_close': return 'stream_close'; case 'feof': case 'stream_eof': return 'stream_eof'; case 'fflush': case 'stream_flush': return 'stream_flush'; case 'ftruncate': case 'stream_truncate': return 'stream_truncate'; case 'flock': case 'stream_lock': return 'stream_lock'; case 'touch': case 'chmod': case 'chown': case 'chgrp': case 'stream_metadata': return 'stream_metadata'; case 'fopen': case 'stream_open': return 'stream_open'; case 'fread': case 'fgets': case 'stream_read': return 'stream_read'; case 'fseek': case 'stream_seek': return 'stream_seek'; case 'fstat': case 'stream_stat': return 'stream_stat'; case 'ftell': case 'stream_tell': return 'stream_tell'; case 'fwrite': case 'stream_write': return 'stream_write'; case 'stat': case 'url_stat': return 'url_stat'; default: throw new exceptions\logic\invalidArgument('Method streamWrapper::' . $method . '() does not exist'); } } } methodName = strtolower($methodName); } public function getMethodName() { return $this->methodName; } public function offsetSet($call, $mixed) { if ($this->methodName == 'dir_readdir' && $mixed instanceof \mageekguy\atoum\mock\stream\controller) { $mixed = $mixed->getBasename(); } return parent::offsetSet($call, $mixed); } } setPermissions('755'); } public function setPermissions($permissions) { return parent::setPermissions(0400000 | octdec($permissions)); } public function getContents() { return array(); } public function mkdir($path, $mode, $options) { if ($this->exists === true) { return false; } else { $this->setPermissions($mode)->exists = true; return true; } } public function rmdir($path, $options) { if ($this->exists === false || $this->checkIfWritable() === false) { return false; } else { $this->exists = false; return true; } } public function dir_opendir($path, $useSafeMode) { return $this->exists; } public function dir_closedir() { return $this->exists; } } setPermissions('644'); } public function __set($method, $value) { switch ($method = static::mapMethod($method)) { case 'mkdir': case 'rmdir': case 'dir_closedir': case 'dir_opendir': case 'dir_readdir': case 'dir_rewinddir': throw new exceptions\logic\invalidArgument('Unable to override streamWrapper::' . $method . '() for file'); default: return parent::__set($method, $value); } } public function duplicate() { $controller = parent::duplicate(); $controller->contents = & $this->contents; return $controller; } public function setPermissions($permissions) { return parent::setPermissions(0100000 | octdec($permissions)); } public function getPointer() { return $this->pointer; } public function setContents($contents) { $this->contents = $contents; return $this->setStat('size', strlen($this->contents)); } public function getContents() { return $this->contents; } public function contains($contents) { return $this ->setContents($contents) ->setPointer(0) ; } public function isEmpty() { return $this->contains(''); } public function stream_open($path, $mode, $options, & $openedPath = null) { if ($this->nextCallIsOverloaded(__FUNCTION__) === true) { return $this->invoke(__FUNCTION__, func_get_args()); } else { $this->addCall(__FUNCTION__, func_get_args()); $this->offset = null; $this->append = false; $isOpened = false; $reportErrors = ($options & STREAM_REPORT_ERRORS) == STREAM_REPORT_ERRORS; if (self::checkOpenMode($mode) === false) { if ($reportErrors === true) { trigger_error('Operation timed out', E_USER_WARNING); } } else { $this->setOpenMode($mode); switch (true) { case $this->read === true && $this->write === false: $isOpened = $this->checkIfReadable(); break; case $this->read === false && $this->write === true: $isOpened = $this->checkIfWritable(); break; default: $isOpened = $this->checkIfReadable() && $this->checkIfWritable(); } if ($isOpened === false) { if ($reportErrors === true) { trigger_error('Permission denied', E_USER_WARNING); } } else { switch (self::getRawOpenMode($mode)) { case 'w': $this->exists = true; $this->truncate(0); $this->seek(0); break; case 'r': $isOpened = $this->exists; if ($isOpened === true) { $this->seek(0); } else if ($reportErrors === true) { trigger_error('No such file or directory', E_USER_WARNING); } break; case 'c': $this->exists = true; $this->seek(0); break; case 'x': if ($this->exists === false) { $this->seek(0); } else { $isOpened = false; if ($reportErrors === true) { trigger_error('File exists', E_USER_WARNING); } } break; case 'a': $this->exists = true; if ($this->read === true) { $this->seek(0); } else { $this->seek(0, SEEK_END); $this->offset = $this->pointer; } $this->append = true; break; } } } $openedPath = null; if ($isOpened === true && $options & STREAM_USE_PATH) { $openedPath = $this->getPath(); } return $isOpened; } } public function stream_seek($offset, $whence = SEEK_SET) { if ($this->nextCallIsOverloaded(__FUNCTION__) === true) { return $this->invoke(__FUNCTION__, func_get_args()); } else { $this->addCall(__FUNCTION__, func_get_args()); return $this->seek($offset, $whence); } } public function stream_eof() { if ($this->nextCallIsOverloaded(__FUNCTION__) === true) { return $this->invoke(__FUNCTION__, func_get_args()); } else { $this->addCall(__FUNCTION__, array()); return $this->eof; } } public function stream_tell() { if ($this->nextCallIsOverloaded(__FUNCTION__) === true) { return $this->invoke(__FUNCTION__, array()); } else { $this->addCall(__FUNCTION__, array()); return ($this->offset === null ? $this->pointer : $this->pointer - $this->offset); } } public function stream_read($count) { if ($this->nextCallIsOverloaded(__FUNCTION__) === true) { return $this->invoke(__FUNCTION__, func_get_args()); } else { $this->addCall(__FUNCTION__, func_get_args()); $data = ''; $this->eof = ($this->pointer < 0 || $this->pointer >= $this->stat['size']); if ($this->read === true && $this->pointer >= 0 && $this->eof === false) { $data = substr($this->contents, $this->pointer, $count) ?: ''; $this->movePointer(strlen($data) ?: $count); } return $data; } } public function stream_write($data) { if ($this->nextCallIsOverloaded(__FUNCTION__) === true) { return $this->invoke(__FUNCTION__, func_get_args()); } else { $this->addCall(__FUNCTION__, func_get_args()); $bytesWrited = 0; if ($this->write === true) { $contents = $this->getContents(); if ($this->append === true) { if ($contents !== '') { $contents .= PHP_EOL; $this->movePointer(1); } $this->append = false; } $this ->setContents($contents . $data) ->movePointer($bytesWrited = strlen($data)) ; } return $bytesWrited; } } public function stream_flush() { return true; } public function stream_metadata($path, $option, $value) { if ($this->nextCallIsOverloaded(__FUNCTION__) === true) { return $this->invoke(__FUNCTION__, func_get_args()); } else { $this->addCall(__FUNCTION__, func_get_args()); switch ($option) { case STREAM_META_TOUCH: case STREAM_META_OWNER_NAME: case STREAM_META_OWNER: case STREAM_META_GROUP_NAME: case STREAM_META_GROUP: return true; case STREAM_META_ACCESS: $this->setPermissions($value); return true; default: return false; } } } public function stream_truncate($newSize) { if ($this->nextCallIsOverloaded(__FUNCTION__) === true) { return $this->invoke(__FUNCTION__, func_get_args()); } else { $this->addCall(__FUNCTION__, func_get_args()); return $this->truncate($newSize); } } public function stream_lock($mode) { if ($this->nextCallIsOverloaded(__FUNCTION__) === true) { return $this->invoke(__FUNCTION__, func_get_args()); } else { $this->addCall(__FUNCTION__, func_get_args()); return true; } } public function stream_close() { if ($this->nextCallIsOverloaded(__FUNCTION__) === true) { return $this->invoke(__FUNCTION__, array()); } else { $this->addCall(__FUNCTION__, array()); return true; } } public function unlink($path) { if ($this->nextCallIsOverloaded(__FUNCTION__) === true) { return $this->invoke(__FUNCTION__, func_get_args()); } else { $this->addCall(__FUNCTION__, func_get_args()); if ($this->exists === false || $this->checkIfWritable() === false) { return false; } else { $this->exists = false; return true; } } } public function rename($from, $to) { if ($this->nextCallIsOverloaded(__FUNCTION__) === true) { return $this->invoke(__FUNCTION__, func_get_args()); } else { $this->addCall(__FUNCTION__, func_get_args()); $this->setPath($to); return true; } } public function mkdir($path, $mode, $options) { return false; } public function dir_opendir($path, $options) { return false; } public function dir_readdir() { return false; } public function dir_rewinddir() { return false; } public function dir_closedir() { return false; } public function rmdir($path, $options) { return false; } protected function truncate($newSize) { $this->setContents(str_pad(substr($this->contents, 0, $newSize), $newSize, "\0")); return true; } protected function seek($offset, $whence = SEEK_SET) { switch ($whence) { case SEEK_CUR: $offset = $this->pointer + $offset; break; case SEEK_END: $offset = strlen($this->getContents()) + $offset; } if ($this->offset !== null && $offset < $this->offset) { $offset = $this->offset; } $this->setPointer($offset); return true; } protected function setOpenMode($mode) { $this->read = false; $this->write = false; switch (str_replace(array('b', 't'), '', $mode)) { case 'r': case 'x': $this->read = true; break; case 'w': case 'a': case 'c': $this->write = true; break; case 'r+': case 'x+': case 'w+': case 'a+': case 'c+': $this->read = $this->write = true; } return $this; } protected function setPointer($pointer) { $this->pointer = $pointer; $this->eof = false; return $this; } protected function movePointer($offset) { return $this->setPointer($this->pointer + $offset); } protected static function getRawOpenMode($mode) { return str_replace(array('b', 't', '+'), '', $mode); } protected static function checkOpenMode($mode) { switch (self::getRawOpenMode($mode)) { case 'r': case 'w': case 'a': case 'x': case 'c': return true; default: return false; } } } setAdapter($adapter)->stat = array( 'dev' => 0, 'ino' => 0, 'mode' => 0, 'nlink' => 0, 'uid' => getmyuid(), 'gid' => getmygid(), 'rdev' => 0, 'size' => 0, 'atime' => 507769200, 'mtime' => 507769200, 'ctime' => 507769200, 'blksize' => 0, 'blocks' => 0 ); $this->stat[0] = & $this->stat['dev']; $this->stat[1] = & $this->stat['ino']; $this->stat[2] = & $this->stat['mode']; $this->stat[3] = & $this->stat['nlink']; $this->stat[4] = & $this->stat['uid']; $this->stat[5] = & $this->stat['gid']; $this->stat[6] = & $this->stat['rdev']; $this->stat[7] = & $this->stat['size']; $this->stat[8] = & $this->stat['atime']; $this->stat[9] = & $this->stat['mtime']; $this->stat[10] = & $this->stat['ctime']; $this->stat[11] = & $this->stat['blksize']; $this->stat[12] = & $this->stat['blocks']; } public function getAdapter() { return $this->adapter; } public function setAdapter(atoum\adapter $adapter = null) { $this->adapter = $adapter ?: new atoum\adapter(); return $this; } public function exists() { $this->exists = true; return $this->clearStatCache(); } public function notExists() { $this->exists = false; return $this->clearStatCache(); } public function isNotReadable() { return $this->removePermissions(0444); } public function isReadable() { return $this->addPermission(0444); } public function isNotWritable() { return $this->removePermissions(0222); } public function isWritable() { return $this->addPermission(0222); } public function isNotExecutable() { return $this->removePermissions(0111); } public function isExecutable() { return $this->addPermission(0111); } public function setPermissions($permissions) { return $this->setStat('mode', $permissions); } public function getPermissions() { return ($this->exists === false ? null : (int) sprintf('%03o', $this->stat['mode'] & 07777)); } public function duplicate() { $controller = parent::duplicate(); $controller->adapter = & $this->adapter; $controller->exists = & $this->exists; $controller->stat = & $this->stat; return $controller; } public function getStat() { return ($this->exists === false ? false : $this->stat); } public function stream_stat() { if ($this->nextCallIsOverloaded(__FUNCTION__) === true) { return $this->invoke(__FUNCTION__, array()); } else { $this->addCall(__FUNCTION__, array()); return $this->getStat(); } } public function url_stat($path, $flags) { if ($this->nextCallIsOverloaded(__FUNCTION__) === true) { return $this->invoke(__FUNCTION__, func_get_args()); } else { $this->addCall(__FUNCTION__, func_get_args()); return $this->getStat(); } } protected function setStat($name, $value) { if (isset($this->stat[$name]) === true) { $this->stat[$name] = $value; $this->clearStatCache(); } return $this; } protected function clearStatCache() { $this->adapter->clearstatcache(false, $this->getPath()); return $this; } protected function addPermission($permissions) { return $this->setStat('mode', $this->stat['mode'] | $permissions); } protected function removePermissions($permissions) { return $this->setStat('mode', $this->stat['mode'] & ~ $permissions); } protected function checkIfReadable() { return $this->checkPermission(0400, 0040, 0004); } protected function checkIfWritable() { return $this->checkPermission(0200, 0020, 0002); } protected function checkPermission($user, $group, $other) { $permissions = $this->stat['mode'] & 07777; switch (true) { case getmyuid() === $this->stat['uid']: return ($permissions & $user) > 0; case getmygid() === $this->stat['gid']: return ($permissions & $group) > 0; default: return ($permissions & $other) > 0; } } } setIterator()->controlNextNewMock(); } public function __set($method, $mixed) { $this->checkMethod($method); return parent::__set($method, $mixed); } public function __get($method) { $this->checkMethod($method); return parent::__get($method); } public function __isset($method) { $this->checkMethod($method); return parent::__isset($method); } public function __unset($method) { $this->checkMethod($method); parent::__unset($method); $this->invokers[strtolower($method)] = null; return $this; } public function setIterator(controller\iterator $iterator = null) { $this->iterator = $iterator ?: new controller\iterator(); $this->iterator->setMockController($this); return $this; } public function getIterator() { return $this->iterator; } public function disableMethodChecking() { $this->disableMethodChecking = true; return $this; } public function getMockClass() { return $this->mockClass; } public function getMethods() { return $this->mockMethods; } public function methods(\closure $filter = null) { $this->iterator->resetFilters(); if ($filter !== null) { $this->iterator->addFilter($filter); } return $this->iterator; } public function methodsMatching($regex) { return $this->iterator->resetFilters()->addFilter(function($name) use ($regex) { return preg_match($regex, $name); }); } public function getCalls($method = null, array $arguments = null, $identical = false) { if ($method !== null) { $this->checkMethod($method); } return parent::getCalls($method, $arguments, $identical); } public function control(mock\aggregator $mock) { $this->mockClass = get_class($mock); $this->mockMethods = $mock->getMockedMethods(); if ($this->disableMethodChecking === false) { foreach (array_keys($this->invokers) as $method) { if (in_array($method, $this->mockMethods) === false) { if (in_array('__call', $this->mockMethods) === false) { throw new exceptions\logic('Method \'' . $this->getMockClass() . '::' . $method . '()\' does not exist'); } if (isset($this->invokers['__call']) === false) { $this->invokers['__call'] = null; $this->set__call(); } } } } foreach ($this->mockMethods as $method) { if (isset($this->invokers[$method]) === false) { $this->invokers[$method] = null; } } if ($mock->getMockController() !== $this) { $mock->setMockController($this); } return $this->resetCalls()->notControlNextNewMock(); } public function controlNextNewMock() { self::$controlNextNewMock = $this; return $this; } public function notControlNextNewMock() { if (self::$controlNextNewMock === $this) { self::$controlNextNewMock = null; } return $this; } public function reset() { $this->mockClass = null; $this->mockMethods = array(); return parent::reset(); } public function invoke($method, array $arguments = array()) { $this->checkMethod($method); if (isset($this->{$method}) === false) { throw new exceptions\logic('Method ' . $method . '() is not under control'); } return parent::invoke($method, $arguments); } public static function get() { $instance = self::$controlNextNewMock; if ($instance !== null) { self::$controlNextNewMock = null; } return $instance; } protected function checkMethod($method) { if ($this->mockClass !== null && $this->disableMethodChecking === false && array_key_exists(strtolower($method), $this->invokers) === false) { if (array_key_exists('__call', $this->invokers) === true) { $this->set__call(); } else { throw new exceptions\logic('Method \'' . $this->getMockClass() . '::' . $method . '()\' does not exist'); } } return $this; } private function set__call() { $controller = $this; parent::__set('__call', function($method, $arguments) use ($controller) { return $controller->invoke($method, $arguments); } ); return $this; } } setAdapter() ->setPhpMethodFactory() ->setReflectionClassFactory() ; } public function callsToParentClassAreShunted() { return $this->shuntParentClassCalls; } public function setAdapter(atoum\adapter $adapter = null) { $this->adapter = $adapter ?: new atoum\adapter(); return $this; } public function getAdapter() { return $this->adapter; } public function setPhpMethodFactory(\closure $factory = null) { $this->phpMethodFactory = $factory ?: function($method) { return new mock\php\method($method); }; return $this; } public function getPhpMethodFactory() { return $this->phpMethodFactory; } public function setReflectionClassFactory(\closure $factory = null) { $this->reflectionClassFactory = $factory ?: function($class) { return new \reflectionClass($class); }; return $this; } public function getReflectionClassFactory() { return $this->reflectionClassFactory; } public function setDefaultNamespace($namespace) { $this->defaultNamespace = '\\' . trim($namespace, '\\'); return $this; } public function getDefaultNamespace() { return ($this->defaultNamespace === null ? self::defaultNamespace : $this->defaultNamespace); } public function overload(php\method $method) { $this->overloadedMethods[strtolower($method->getName())] = $method; return $this; } public function isOverloaded($method) { return ($this->getOverload($method) !== null); } public function getOverload($method) { return (isset($this->overloadedMethods[$method = strtolower($method)]) === false ? null : $this->overloadedMethods[$method]); } public function shunt($method) { if ($this->isShunted($method) === false) { $this->shuntedMethods[] = strtolower($method); } return $this; } public function isShunted($method) { return (in_array(strtolower($method), $this->shuntedMethods) === true); } public function shuntParentClassCalls() { $this->shuntParentClassCalls = true; return $this; } public function unshuntParentClassCalls() { $this->shuntParentClassCalls = false; return $this; } public function orphanize($method) { if ($this->isOrphanized($method) === false) { $this->orphanizedMethods[] = strtolower($method); } return $this->shunt($method); } public function isOrphanized($method) { return (in_array($method, $this->orphanizedMethods) === true); } public function getMockedClassCode($class, $mockNamespace = null, $mockClass = null) { if (trim($class, '\\') == '' || rtrim($class, '\\') != $class) { throw new exceptions\runtime('Class name \'' . $class . '\' is invalid'); } if ($mockNamespace === null) { $mockNamespace = $this->getNamespace($class); } $class = '\\' . ltrim($class, '\\'); if ($mockClass === null) { $mockClass = self::getClassName($class); } if ($this->adapter->class_exists($mockNamespace . '\\' . $mockClass, false) === true || $this->adapter->interface_exists($mockNamespace . '\\' . $mockClass, false) === true) { throw new exceptions\logic('Class \'' . $mockNamespace . '\\' . $mockClass . '\' already exists'); } $code = ''; if ($this->adapter->class_exists($class, true) === false && $this->adapter->interface_exists($class, true) === false) { $code = self::generateUnknownClassCode($class, $mockNamespace, $mockClass); } else { $reflectionClass = call_user_func($this->reflectionClassFactory, $class); if ($reflectionClass->isFinal() === true) { throw new exceptions\logic('Class \'' . $class . '\' is final, unable to mock it'); } $code = $reflectionClass->isInterface() === false ? $this->generateClassCode($reflectionClass, $mockNamespace, $mockClass) : $this->generateInterfaceCode($reflectionClass, $mockNamespace, $mockClass); } return $code; } public function generate($class, $mockNamespace = null, $mockClass = null) { eval($this->getMockedClassCode($class, $mockNamespace, $mockClass)); $this->shuntedMethods = $this->overloadedMethods = $this->orphanizedMethods = array(); return $this->unshuntParentClassCalls(); } protected function generateClassMethodCode(\reflectionClass $class) { $mockedMethods = ''; $mockedMethodNames = array(); $className = $class->getName(); $constructor = $class->getConstructor(); if ($constructor === null) { $mockedMethods .= self::generateDefaultConstructor(); $mockedMethodNames[] = '__construct'; } else if ($constructor->isFinal() === false) { $constructorName = $constructor->getName(); $overload = $this->getOverload($constructorName); if ($constructor->isPublic() === false) { $this->shuntParentClassCalls(); if ($overload === null) { $this->overload(new php\method('__construct')); $overload = $this->getOverload('__construct'); } } $parameters = $this->getParameters($constructor); if ($overload === null) { $mockedMethods .= "\t" . 'public function __construct(' . $this->getParametersSignature($constructor) . ')'; } else { $overload ->addArgument( php\method\argument::get('mockController') ->isObject('\\' . __NAMESPACE__ . '\\controller') ->setDefaultValue(null) ) ; $mockedMethods .= "\t" . $overload; } $mockedMethods .= PHP_EOL; $mockedMethods .= "\t" . '{' . PHP_EOL; $mockedMethods .= "\t\t" . '$arguments = array_merge(array(' . join(', ', $parameters) . '), array_slice(func_get_args(), ' . sizeof($parameters) . ', -1));' . PHP_EOL; $mockedMethods .= "\t\t" . 'if ($mockController === null)' . PHP_EOL; $mockedMethods .= "\t\t" . '{' . PHP_EOL; $mockedMethods .= "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL; $mockedMethods .= "\t\t" . '}' . PHP_EOL; $mockedMethods .= "\t\t" . 'if ($mockController !== null)' . PHP_EOL; $mockedMethods .= "\t\t" . '{' . PHP_EOL; $mockedMethods .= "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL; $mockedMethods .= "\t\t" . '}' . PHP_EOL; if ($constructor->isAbstract() === true || $this->isShunted('__construct') === true || $this->isShunted($className) === true) { $methodName = ($this->isShunted($className) === true ? $className : '__construct'); $mockedMethods .= "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === false)' . PHP_EOL; $mockedMethods .= "\t\t" . '{' . PHP_EOL; $mockedMethods .= "\t\t\t" . '$this->getMockController()->' . $methodName . ' = function() {};' . PHP_EOL; $mockedMethods .= "\t\t" . '}' . PHP_EOL; $mockedMethods .= "\t\t" . '$this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL; } else { $methodName = ($constructorName === $className ? $className : '__construct'); $mockedMethods .= "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL; $mockedMethods .= "\t\t" . '{' . PHP_EOL; $mockedMethods .= "\t\t\t" . '$this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL; $mockedMethods .= "\t\t" . '}' . PHP_EOL; $mockedMethods .= "\t\t" . 'else' . PHP_EOL; $mockedMethods .= "\t\t" . '{' . PHP_EOL; $mockedMethods .= "\t\t\t" . '$this->getMockController()->addCall(\'' . $constructorName . '\', $arguments);' . PHP_EOL; if ($this->shuntParentClassCalls === false) { $mockedMethods .= "\t\t\t" . 'call_user_func_array(\'parent::' . $constructorName . '\', $arguments);' . PHP_EOL; } $mockedMethods .= "\t\t" . '}' . PHP_EOL; } $mockedMethods .= "\t" . '}' . PHP_EOL; $mockedMethodNames[] = $constructorName; } foreach ($class->getMethods() as $method) { if ($this->methodIsMockable($method) === true) { $methodName = $method->getName(); $mockedMethodNames[] = strtolower($methodName); $overload = $this->getOverload($methodName); $parameters = $this->getParameters($method); if ($overload !== null) { $mockedMethods .= "\t" . $overload; } else { $mockedMethods .= "\t" . ($method->isPublic() === true ? 'public' : 'protected') . ' function' . ($method->returnsReference() === false ? '' : ' &') . ' ' . $methodName . '(' . $this->getParametersSignature($method) . ')'; } $mockedMethods .= PHP_EOL . "\t" . '{' . PHP_EOL; $mockedMethods .= "\t\t" . '$arguments = array_merge(array(' . join(', ', $parameters) . '), array_slice(func_get_args(), ' . sizeof($parameters) . '));' . PHP_EOL; if ($this->isShunted($methodName) === true || $method->isAbstract() === true) { $mockedMethods .= "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === false)' . PHP_EOL; $mockedMethods .= "\t\t" . '{' . PHP_EOL; $mockedMethods .= "\t\t\t" . '$this->getMockController()->' . $methodName . ' = function() {};' . PHP_EOL; $mockedMethods .= "\t\t" . '}' . PHP_EOL; $mockedMethods .= "\t\t" . 'return $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL; } else { $mockedMethods .= "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL; $mockedMethods .= "\t\t" . '{' . PHP_EOL; $mockedMethods .= "\t\t\t" . 'return $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL; $mockedMethods .= "\t\t" . '}' . PHP_EOL; $mockedMethods .= "\t\t" . 'else' . PHP_EOL; $mockedMethods .= "\t\t" . '{' . PHP_EOL; if ($methodName === '__call') { $mockedMethods .= "\t\t\t" . '$this->getMockController()->addCall(current(array_slice($arguments, 0, 1)), current(array_slice($arguments, 1)));' . PHP_EOL; } $mockedMethods .= "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL; if ($this->shuntParentClassCalls === false) { $mockedMethods .= "\t\t\t" . 'return call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL; } $mockedMethods .= "\t\t" . '}' . PHP_EOL; } $mockedMethods .= "\t" . '}' . PHP_EOL; } } return $mockedMethods . self::generateGetMockedMethod($mockedMethodNames); } protected function generateClassCode(\reflectionClass $class, $mockNamespace, $mockClass) { return 'namespace ' . ltrim($mockNamespace, '\\') . ' {' . PHP_EOL . 'final class ' . $mockClass . ' extends \\' . $class->getName() . ' implements \\' . __NAMESPACE__ . '\\aggregator' . PHP_EOL . '{' . PHP_EOL . self::generateMockControllerMethods() . $this->generateClassMethodCode($class) . '}' . PHP_EOL . '}' ; } protected function generateInterfaceMethodCode(\reflectionClass $class, $addIteratorAggregate) { $mockedMethods = ''; $mockedMethodNames = array(); $hasConstructor = false; $methods = $class->getMethods(\reflectionMethod::IS_PUBLIC); if ($addIteratorAggregate === true) { $iteratorInterface = call_user_func($this->reflectionClassFactory, 'iteratorAggregate'); $methods = array_merge($methods, $iteratorInterface->getMethods(\reflectionMethod::IS_PUBLIC)); } foreach ($methods as $method) { if ($method->isFinal() === false && $method->isStatic() === false) { $methodName = $method->getName(); $mockedMethodNames[] = strtolower($methodName); $isConstructor = $methodName === '__construct'; if ($isConstructor === true) { $hasConstructor = true; } $parameters = $this->getParameters($method); $methodCode = "\t" . 'public function' . ($method->returnsReference() === false ? '' : ' &') . ' ' . $methodName . '(' . $this->getParametersSignature($method) . ')' . PHP_EOL; $methodCode .= "\t" . '{' . PHP_EOL; $methodCode .= "\t\t" . '$arguments = array_merge(array(' . join(', ', $parameters) . '), array_slice(func_get_args(), ' . sizeof($parameters) . ($isConstructor === false ? '' : ', -1') . '));' . PHP_EOL; if ($isConstructor === true) { $methodCode .= "\t\t" . 'if ($mockController === null)' . PHP_EOL; $methodCode .= "\t\t" . '{' . PHP_EOL; $methodCode .= "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL; $methodCode .= "\t\t" . '}' . PHP_EOL; $methodCode .= "\t\t" . 'if ($mockController !== null)' . PHP_EOL; $methodCode .= "\t\t" . '{' . PHP_EOL; $methodCode .= "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL; $methodCode .= "\t\t" . '}' . PHP_EOL; } $methodCode .= "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === false)' . PHP_EOL; $methodCode .= "\t\t" . '{' . PHP_EOL; $methodCode .= "\t\t\t" . '$this->getMockController()->' . $methodName . ' = function() {};' . PHP_EOL; $methodCode .= "\t\t" . '}' . PHP_EOL; $methodCode .= "\t\t" . ($isConstructor === true ? '' : 'return ') . '$this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL; $methodCode .= "\t" . '}' . PHP_EOL; $mockedMethods .= $methodCode; } } if ($hasConstructor === false) { $mockedMethods .= self::generateDefaultConstructor(); $mockedMethodNames[] = '__construct'; } $mockedMethods .= self::generateGetMockedMethod($mockedMethodNames); return $mockedMethods; } protected function generateInterfaceCode(\reflectionClass $class, $mockNamespace, $mockClass) { $addIteratorAggregate = ( $class->isInstantiable() === false && ( $class->implementsInterface('traversable') === true && $class->implementsInterface('iterator') === false && $class->implementsInterface('iteratorAggregate') === false ) ); return 'namespace ' . ltrim($mockNamespace, '\\') . ' {' . PHP_EOL . 'final class ' . $mockClass . ' implements \\' . ($addIteratorAggregate === false ? '' : 'iteratorAggregate, \\') . $class->getName() . ', \\' . __NAMESPACE__ . '\\aggregator' . PHP_EOL . '{' . PHP_EOL . self::generateMockControllerMethods() . $this->generateInterfaceMethodCode($class, $addIteratorAggregate) . '}' . PHP_EOL . '}' ; } protected function getNamespace($class) { $class = ltrim($class, '\\'); $lastAntiSlash = strrpos($class, '\\'); return '\\' . $this->getDefaultNamespace() . ($lastAntiSlash === false ? '' : '\\' . substr($class, 0, $lastAntiSlash)); } protected function getParameters(\reflectionMethod $method) { $parameters = array(); $overload = $this->getOverload($method->getName()); if ($overload === null) { foreach ($method->getParameters() as $parameter) { $parameters[] = ($parameter->isPassedByReference() === false ? '' : '& ') . '$' . $parameter->getName(); } } else { foreach ($overload->getArguments() as $argument) { $parameters[] = $argument->getVariable(); } } return $parameters; } protected function getParametersSignature(\reflectionMethod $method) { $parameters = array(); $mustBeNull = $this->isOrphanized($method->getName()); foreach ($method->getParameters() as $parameter) { $parameterCode = self::getParameterType($parameter) . ($parameter->isPassedByReference() == false ? '' : '& ') . '$' . $parameter->getName(); switch (true) { case $parameter->isDefaultValueAvailable(): $parameterCode .= ' = ' . var_export($parameter->getDefaultValue(), true); break; case $parameter->isOptional(): case $mustBeNull: $parameterCode .= ' = null'; } $parameters[] = $parameterCode; } if ($method->isConstructor() === true) { $parameters[] = '\\' . __NAMESPACE__ . '\\controller $mockController = null'; } return join(', ', $parameters); } protected static function getClassName($class) { $class = ltrim($class, '\\'); $lastAntiSlash = strrpos($class, '\\'); return ($lastAntiSlash === false ? $class : substr($class, $lastAntiSlash + 1)); } protected static function getParameterType(\reflectionParameter $parameter) { switch (true) { case $parameter->isArray(): return 'array '; case method_exists($parameter, 'isCallable') && $parameter->isCallable(): return 'callable '; case ($class = $parameter->getClass()): return '\\' . $class->getName() . ' '; default: return ''; } } protected static function generateMockControllerMethods() { return "\t" . 'public function getMockController()' . PHP_EOL . "\t" . '{' . PHP_EOL . "\t\t" . '$mockController = \mageekguy\atoum\mock\controller\collector::get($this);' . PHP_EOL . "\t\t" . 'if ($mockController === null)' . PHP_EOL . "\t\t" . '{' . PHP_EOL . "\t\t\t" . '$this->setMockController($mockController = new \\' . __NAMESPACE__ . '\\controller());' . PHP_EOL . "\t\t" . '}' . PHP_EOL . "\t\t" . 'return $mockController;' . PHP_EOL . "\t" . '}' . PHP_EOL . "\t" . 'public function setMockController(\\' . __NAMESPACE__ . '\\controller $controller)' . PHP_EOL . "\t" . '{' . PHP_EOL . "\t\t" . 'return \mageekguy\atoum\mock\controller\collector::add($this, $controller);' . PHP_EOL . "\t" . '}' . PHP_EOL . "\t" . 'public function resetMockController()' . PHP_EOL . "\t" . '{' . PHP_EOL . "\t\t" . '\mageekguy\atoum\mock\controller\collector::remove($this);' . PHP_EOL . "\t\t" . 'return $this;' . PHP_EOL . "\t" . '}' . PHP_EOL ; } protected static function generateDefaultConstructor($disableMethodChecking = false) { $defaultConstructor = "\t" . 'public function __construct(\\' . __NAMESPACE__ . '\\controller $mockController = null)' . PHP_EOL . "\t" . '{' . PHP_EOL . "\t\t" . 'if ($mockController === null)' . PHP_EOL . "\t\t" . '{' . PHP_EOL . "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL . "\t\t" . '}' . PHP_EOL . "\t\t" . 'if ($mockController !== null)' . PHP_EOL . "\t\t" . '{' . PHP_EOL . "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL . "\t\t" . '}' . PHP_EOL ; if ($disableMethodChecking === true) { $defaultConstructor .= "\t\t" . '$this->getMockController()->disableMethodChecking();' . PHP_EOL; } $defaultConstructor .= "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL . "\t\t" . '{' . PHP_EOL . "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL . "\t\t" . '}' . PHP_EOL . "\t" . '}' . PHP_EOL ; return $defaultConstructor; } protected static function generateGetMockedMethod(array $mockedMethodNames) { return "\t" . 'public static function getMockedMethods()' . PHP_EOL . "\t" . '{' . PHP_EOL . "\t\t" . 'return ' . var_export($mockedMethodNames, true) . ';' . PHP_EOL . "\t" . '}' . PHP_EOL ; } protected static function generateUnknownClassCode($class, $mockNamespace, $mockClass) { return 'namespace ' . ltrim($mockNamespace, '\\') . ' {' . PHP_EOL . 'final class ' . $mockClass . ' implements \\' . __NAMESPACE__ . '\\aggregator' . PHP_EOL . '{' . PHP_EOL . self::generateMockControllerMethods() . self::generateDefaultConstructor(true) . "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL . "\t" . '{' . PHP_EOL . "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL . "\t\t" . '{' . PHP_EOL . "\t\t\t" . 'return $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL . "\t\t" . '}' . PHP_EOL . "\t\t" . 'else' . PHP_EOL . "\t\t" . '{' . PHP_EOL . "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL . "\t\t" . '}' . PHP_EOL . "\t" . '}' . PHP_EOL . self::generateGetMockedMethod(array('__call')) . '}' . PHP_EOL . '}' ; } private function methodIsMockable(\reflectionMethod $method) { switch (true) { case $method->isFinal(): case $method->isStatic(): case $method->isConstructor(): case $method->getName() === 'clone': case $method->getName() === '__destruct': return false; case $method->isPrivate(): case $method->isProtected() && $method->isAbstract() === false: return $this->isOverloaded($method->getName()); default: return true; } } } setControllerForMethod($method, $arguments)->streamController, $method), $arguments); } public static function getAdapter() { return (static::$adapter = static::$adapter ?: new adapter()); } public static function setAdapter(adapter $adapter) { static::$adapter = $adapter; } public static function get($name = null) { $name = static::setDirectorySeparator($name ?: uniqid()); $adapter = static::getAdapter(); if (($protocol = static::getProtocol($name)) === null) { $protocol = static::defaultProtocol; $name = $protocol . static::protocolSeparator . $name; } if (in_array($protocol, $adapter->stream_get_wrappers()) === false && $adapter->stream_wrapper_register($protocol, get_called_class(), 0) === false) { throw new runtime('Unable to register ' . $protocol . ' stream'); } $stream = static::findControllerForStream($name); if ($stream === null) { static::$streams[] = $stream = static::getController($name); } return $stream; } public static function getSubStream(stream\controller $controller, $stream = null) { return static::get($controller . DIRECTORY_SEPARATOR . static::setDirectorySeparator($stream ?: uniqid())); } public static function getProtocol($stream) { $scheme = null; $schemeSeparator = strpos($stream, static::protocolSeparator); if ($schemeSeparator !== false) { $scheme = substr($stream, 0, $schemeSeparator); } return $scheme; } public static function setDirectorySeparator($stream, $directorySeparator = DIRECTORY_SEPARATOR) { $path = preg_replace('#^[^:]+://#', '', $stream); if ($directorySeparator == '/') { $path = str_replace('\\', '/', $path); } else { $path = str_replace('/', '\\', $path); } return substr($stream, 0, strlen($stream) - strlen($path)) . $path; } protected function setControllerForMethod($method, array $arguments) { switch (strtolower($method)) { case 'dir_opendir': case 'mkdir': case 'rename': case 'rmdir': case 'stream_metadata': case 'stream_open': case 'unlink': case 'url_stat': case 'stat': $this->streamController = static::getControllerFromArguments($arguments)->duplicate(); break; } return $this; } protected static function getController($stream) { return new stream\controller($stream); } protected static function getControllerFromArguments(array $arguments) { if (isset($arguments[0]) === false) { throw new logic('Argument 0 is undefined for function ' . $method . '()'); } $stream = static::findControllerForStream(static::setDirectorySeparator($arguments[0])); if ($stream === null) { $stream = static::get($arguments[0]); } return $stream; } protected static function findControllerForStream($path) { foreach (static::$streams as $stream) { if ($stream->getPath() === $path) { return $stream; } } return null; } } 0) { $string = array(); foreach ($arguments as $argument) { switch ($type = gettype($argument)) { case 'boolean': $string[] = ($argument ? 'TRUE' : 'FALSE'); break; case 'integer': $string[] = 'integer(' . $argument . ')'; break; case 'double': $string[] = 'float(' . $argument . ')'; break; case 'string': $string[] = 'string(' . strlen($argument) . ') "' . $argument . '"'; break; case 'array': $string[] = 'array(' . ($size = sizeof($argument)) . ') {' . ($size <= 0 ? '' : '...') . '}'; break; case 'object': $string[] = 'object(' . get_class($argument) . ')'; break; case 'resource': ob_start(); var_dump($argument); $string[] = ob_get_clean(); break; case 'NULL': $string[] = $type; break; default: $string[] = $type; } } $string = join(', ', $string); } return $string; } } setArgumentsDecorator(); } public function setArgumentsDecorator(arguments\decorator $decorator = null) { $this->argumentsDecorator = $decorator ?: new arguments\decorator(); return $this; } public function getArgumentsDecorator() { return $this->argumentsDecorator; } public function decorate(php\call $call) { $string = $call->getFunction() . '(' . $this->argumentsDecorator->decorate($call->getArguments()) . ')'; $object = $call->getObject(); if ($object !== null) { $string = get_class($object) . '::' . $string; } return $string; } } parent !== null) { throw new exceptions\runtime('Parent is already set'); } $parent->append($this); return $this; } public function getParent() { return $this->parent; } public function getRoot() { $root = null; $parent = $this->getParent(); while ($parent !== null) { $root = $parent; $parent = $parent->getParent(); } return $root; } public abstract function __toString(); public abstract function prev(); public abstract function end(); public abstract function append(value $value); public abstract function getValue(); public abstract function seek($key); } defaultValue; } public function appendDefaultValue(iterators\phpDefaultValue $phpDefaultValue) { $this->defaultValue = $phpDefaultValue; return $this->append($phpDefaultValue); } } methods = array(); $this->constants = array(); $this->properties = array(); return parent::reset(); } public function getConstant($index) { return (isset($this->constants[$index]) === false ? null : $this->constants[$index]); } public function getConstants() { return $this->constants; } public function appendConstant(iterators\phpConstant $phpConstant) { $this->constants[] = $phpConstant; return $this->append($phpConstant); } public function getMethods() { return $this->methods; } public function getMethod($index) { return (isset($this->methods[$index]) === false ? null : $this->methods[$index]); } public function appendMethod(iterators\phpMethod $phpMethod) { $this->methods[] = $phpMethod; return $this->append($phpMethod); } public function getProperties() { return $this->properties; } public function getProperty($index) { return (isset($this->properties[$index]) === false ? null : $this->properties[$index]); } public function appendProperty(iterators\phpProperty $phpProperty) { $this->properties[] = $phpProperty; return $this->append($phpProperty); } } findTag(T_FUNCTION); if ($key !== null) { $this->goToNextTagWhichIsNot(array(T_WHITESPACE, T_COMMENT)); $token = $this->current(); if ($token !== null && $token->getTag() === T_STRING) { $name = $token->getValue(); } } return $name; } public function reset() { $this->arguments = array(); return parent::reset(); } public function appendArgument(iterators\phpArgument $phpArgument) { $this->arguments[] = $phpArgument; return $this->append($phpArgument); } public function getArguments() { return $this->arguments; } public function getArgument($index) { return (isset($this->arguments[$index]) === false ? null : $this->arguments[$index]); } } functions = array(); $this->constants = array(); $this->classes = array(); return parent::reset(); } public function getConstants() { return $this->constants; } public function getConstant($index) { return (isset($this->constants[$index]) === false ? null : $this->constants[$index]); } public function appendConstant(iterators\phpConstant $phpConstant) { $this->constants[] = $phpConstant; return $this->append($phpConstant); } public function getClasses() { return $this->classes; } public function getClass($index) { return (isset($this->classes[$index]) === false ? null : $this->classes[$index]); } public function appendClass(iterators\phpClass $phpClass) { $this->classes[] = $phpClass; return $this->append($phpClass); } public function getFunctions() { return $this->functions; } public function getFunction($index) { return (isset($this->functions[$index]) === false ? null : $this->functions[$index]); } public function appendFunction(iterators\phpFunction $phpFunction) { $this->functions[] = $phpFunction; return $this->append($phpFunction); } } namespaces = array(); return parent::reset(); } public function appendNamespace(iterators\phpNamespace $phpNamespace) { $this->namespaces[] = $phpNamespace; return $this->append($phpNamespace); } public function getNamespaces() { return $this->namespaces; } public function getNamespace($index) { return (isset($this->namespaces[$index]) === false ? null : $this->namespaces[$index]); } public function appendImportation(iterators\phpImportation $phpImportation) { $this->importations[] = $phpImportation; return $this->append($phpImportation); } public function getImportations() { return $this->importations; } public function getImportation($index) { return (isset($this->importations[$index]) === false ? null : $this->importations[$index]); } } key(); $string = join('', iterator_to_array($this)); if ($key !== null) { $this->seek($key); } return $string; } public function valid() { return (current($this->values) !== false); } public function current() { $value = null; if ($this->valid() === true) { $value = current($this->values)->current(); } return $value; } public function key() { return $this->key < 0 || $this->key >= $this->size ? null : $this->key; } public function prev($offset = 1) { while (($valid = $this->valid()) === true && $offset > 0) { $currentValue = current($this->values); $currentValue->prev(); while ($currentValue->valid() === false && $valid === true) { prev($this->values); if (($valid = $this->valid()) === true) { $currentValue = current($this->values); $currentValue->end(); } } if ($valid === true) { while (in_array($this->current(), $this->skipedValues) === true && $this->valid() === true) { $this->prev(); } } $this->key--; $offset--; } return $this; } public function next($offset = 1) { while (($valid = $this->valid()) === true && $offset > 0) { $currentValue = current($this->values); $currentValue->next(); while ($currentValue->valid() === false && $valid === true) { next($this->values); if (($valid = $this->valid()) === true) { $currentValue = current($this->values); $currentValue->rewind(); } } if ($valid === true) { while (in_array($this->current(), $this->skipedValues) === true && $this->valid() === true) { $this->next(); } } $this->key++; $offset--; } return $this; } public function rewind() { if ($this->size > 0) { reset($this->values); $currentValue = current($this->values); $valid = true; while ($currentValue->rewind()->valid() == false && $valid === true) { next($this->values); if (($valid = $this->valid()) === true) { $currentValue = current($this->values); } } $this->key = 0; if ($valid === true) { while (in_array($this->current(), $this->skipedValues) === true && $this->valid() === true) { $this->next(); } } } return $this; } public function end() { if ($this->size > 0) { end($this->values); $currentValue = current($this->values); $valid = true; while ($currentValue->end()->valid() == false && $valid === true) { prev($this->values); if (($valid = $this->valid()) === true) { $currentValue = current($this->values); } } $this->key = $this->size - 1; if ($valid === true) { while (in_array($this->current(), $this->skipedValues) === true && $this->valid() === true) { $this->prev(); } } } return $this; } public function append(iterator\value $value) { if ($value->parent !== null) { throw new exceptions\runtime('Unable to append value because it has already a parent'); } $value->parent = $this; $this->values[] = $value; if ($this->key === null) { $this->key = 0; } $size = sizeof($value); if ($size > 0) { $value->rewind(); $this->size += $size; $parent = $this->parent; while ($parent !== null) { $parent->size += $size; $parent = $parent->parent; } } return $this; } public function count() { return $this->size; } public function skipValue($value) { if (in_array($value, $this->skipedValues) === false) { $this->skipedValues[] = $value; } return $this; } public function getSkipedValues() { return $this->skipedValues; } public function reset() { $this->key = null; $this->size = 0; $this->values = array(); $this->parent = null; $this->skipedValues = array(); return $this; } public function getValue() { return (current($this->values) ?: null); } public function seek($key) { if ($key > sizeof($this) / 2) { $this->end(); } else if ($this->valid() === false) { $this->rewind(); } if ($key > $this->key) { $this->next($key - $this->key); } else { $this->prev($this->key - $key); } return $this; } public function findTag($tag) { foreach ($this as $key => $token) { if ($token->getTag() === $tag) { return $key; } } return null; } public function goToNextTagWhichIsNot(array $tags) { $this->next(); $token = $this->current(); while ($token !== null && in_array($token->getTag(), $tags) === true) { $this->next(); $token = $this->current(); } return $this; } } tag = $tag; $this->string = $string; $this->line = $line; if ($parent !== null) { $this->setParent($parent); } } public function __toString() { return (string) ($this->string ?: $this->tag); } public function count() { return 1; } public function getTag() { return $this->tag; } public function getString() { return $this->string; } public function getLine() { return $this->line; } public function key() { return $this->key === 0 ? 0 : null; } public function current() { return $this->key !== 0 ? null : $this; } public function rewind() { $this->key = 0; return $this; } public function end() { $this->key = 0; return $this; } public function valid() { return ($this->key === 0); } public function next() { if ($this->valid() === true) { $this->key = null; } return $this; } public function prev() { if ($this->valid() === true) { $this->key = null; } return $this; } public function append(iterator\value $value) { throw new exceptions\logic(__METHOD__ . '() is unavailable'); } public function seek($key) { if ($key != 0) { $this->key = null; } else { $this->key = 0; } return $this; } public function getParent() { return $this->parent; } public function getValue() { return $this->getString(); } } function = (string) $function; $this->arguments = $arguments; $this->object = $object; $this->setDecorator(); } public function __toString() { return $this->decorator->decorate($this); } public function identical() { $this->identical = true; return $this; } public function notIdentical() { $this->identical = false; return $this; } public function isIdentical() { return ($this->identical === true); } public function setFunction($function) { $this->function = $function; return $this; } public function getFunction() { return $this->function; } public function setArguments(array $arguments) { $this->arguments = $arguments; return $this; } public function getArguments() { return $this->arguments; } public function unsetArguments() { $this->arguments = null; return $this; } public function setObject($object) { $this->object = $object; return $this; } public function getObject() { return $this->object; } public function setDecorator(call\decorator $decorator = null) { $this->decorator = $decorator ?: new call\decorator(); return $this; } public function getDecorator() { return $this->decorator; } } resetIterator(); } public function getIterator() { return $this->iterator; } public function resetIterator() { $this->iterator = new iterators\phpScript(); return $this; } public function tokenize($string) { $this->currentIterator = $this->iterator; foreach ($this->tokens = new \arrayIterator(token_get_all($string)) as $key => $token) { switch ($token[0]) { case T_CONST: $token = $this->appendConstant(); break; case T_USE: $token = $this->appendImportation(); break; case T_NAMESPACE: $token = $this->appendNamespace(); break; case T_FUNCTION: $token = $this->appendFunction(); break; } $this->currentIterator->append(new tokenizer\token($token[0], isset($token[1]) === false ? null : $token[1], isset($token[2]) === false ? null : $token[2])); } return $this; } private function appendImportation() { $this->currentIterator->appendImportation($this->currentImportation = new iterators\phpImportation()); $this->currentIterator = $this->currentImportation; $inImportation = true; while ($inImportation === true) { $token = $this->tokens->current(); switch ($token[0]) { case ';': case T_CLOSE_TAG: $this->currentIterator = $this->currentIterator->getParent(); $inImportation = false; break; default: $this->currentIterator->append(new tokenizer\token($token[0], isset($token[1]) === false ? null : $token[1], isset($token[2]) === false ? null : $token[2])); $this->tokens->next(); } $inImportation = $inImportation && $this->tokens->valid(); } return $this->tokens->valid() === false ? null : $this->tokens->current(); } private function appendNamespace() { $inNamespace = true; while ($inNamespace === true) { $token = $this->tokens->current(); switch ($token[0]) { case T_NAMESPACE: $parent = $this->currentIterator->getParent(); if ($parent !== null) { $this->currentIterator = $parent; } $this->currentIterator->appendNamespace($this->currentNamespace = new iterators\phpNamespace()); $this->currentIterator = $this->currentNamespace; break; case T_CONST: $this->appendConstant(); break; case T_FUNCTION: $this->appendFunction(); break; case T_FINAL: case T_ABSTRACT: case T_CLASS: $this->appendClass(); break; case T_INTERFACE: $this->appendInterface(); break; case ';': $this->currentIterator = $this->currentIterator->getParent(); $inNamespace = false; break; case T_CLOSE_TAG: if ($this->nextTokenIs(T_OPEN_TAG) === false) { $this->currentIterator = $this->currentIterator->getParent(); $inNamespace = false; } break; case '}': $inNamespace = false; break; } $this->currentIterator->append(new tokenizer\token($token[0], isset($token[1]) === false ? null : $token[1], isset($token[2]) === false ? null : $token[2])); if ($token[0] === '}') { $this->currentIterator = $this->currentIterator->getParent(); } $this->tokens->next(); $inNamespace = $inNamespace && $this->tokens->valid(); } return $this->tokens->valid() === false ? null : $this->tokens->current(); } private function appendFunction() { $inFunction = true; $this->currentIterator->appendFunction($this->currentFunction = new iterators\phpFunction()); $this->currentIterator = $this->currentFunction; while ($inFunction === true) { $token = $this->tokens->current(); switch ($token[0]) { case '}': $inFunction = false; break; } $this->currentIterator->append(new tokenizer\token($token[0], isset($token[1]) === false ? null : $token[1], isset($token[2]) === false ? null : $token[2])); if ($token[0] === '}') { $this->currentIterator = $this->currentIterator->getParent(); } $this->tokens->next(); $inFunction = $inFunction && $this->tokens->valid(); } return $this->tokens->valid() === false ? null : $this->tokens->current(); } private function appendConstant() { $this->currentIterator->appendConstant($this->currentNamespace = new iterators\phpConstant()); $this->currentIterator = $this->currentNamespace; $inConstant = true; while ($inConstant === true) { $token = $this->tokens->current(); switch ($token[0]) { case ';': case T_CLOSE_TAG: $this->currentIterator = $this->currentIterator->getParent(); $inConstant = false; break; default: $this->currentIterator->append(new tokenizer\token($token[0], isset($token[1]) === false ? null : $token[1], isset($token[2]) === false ? null : $token[2])); $this->tokens->next(); } $inConstant = $inConstant && $this->tokens->valid(); } return $this->tokens->valid() === false ? null : $this->tokens->current(); } private function appendCommentAndWhitespace() { $key = $this->tokens->key(); while (isset($this->tokens[$key + 1]) === true && ($this->tokens[$key + 1][0] === T_WHITESPACE || $this->tokens[$key + 1][0] === T_COMMENT)) { $this->tokens->next(); $token = $this->tokens->current(); $this->currentIterator->append(new tokenizer\token($token[0], isset($token[1]) === false ? null : $token[1], isset($token[2]) === false ? null : $token[2])); $key = $this->tokens->key(); } } private function appendArray() { $this->appendCommentAndWhitespace(); $this->tokens->next(); if ($this->tokens->valid() === true) { $token = $this->tokens->current(); if ($token[0] === '(') { $this->currentIterator->append(new tokenizer\token($token[0], isset($token[1]) === false ? null : $token[1], isset($token[2]) === false ? null : $token[2])); $stack = 1; while ($stack > 0 && $this->tokens->valid() === true) { $this->tokens->next(); if ($this->tokens->valid() === true) { $token = $this->tokens->current(); if ($token[0] === '(') { $stack++; } else if ($token[0] === ')') { $stack--; } $this->currentIterator->append(new tokenizer\token($token[0], isset($token[1]) === false ? null : $token[1], isset($token[2]) === false ? null : $token[2])); } } } } } private function nextTokenIs($tokenName, array $skipedTags = array(T_WHITESPACE, T_COMMENT, T_INLINE_HTML)) { $key = $this->tokens->key() + 1; while (isset($this->tokens[$key]) === true && in_array($this->tokens[$key], $skipedTags) === true) { $key++; } $key++; return (isset($this->tokens[$key]) === true && $this->tokens[$key][0] === $tokenName); } } init()->adapter->fgets($this->resource) : $this->init()->adapter->fgets($this->resource, $length)); } protected function init() { if ($this->resource === null) { $resource = $this->adapter->fopen('php://stdout', 'w'); if ($resource === false) { throw new exceptions\runtime('Unable to open php://stdin stream'); } $this->resource = $resource; } return $this; } } setPrompt() ->setColorizer() ; } public function __toString() { return ($this->author === null || $this->version === null ? '' : $this->prompt . $this->colorizer->colorize(sprintf($this->locale->_('atoum version %s by %s (%s)'), $this->version, $this->author, $this->path)) . PHP_EOL); } public function setPrompt(prompt $prompt = null) { $this->prompt = $prompt ?: new prompt; return $this; } public function getPrompt() { return $this->prompt; } public function setColorizer(colorizer $colorizer = null) { $this->colorizer = $colorizer ?: new colorizer(); return $this; } public function getColorizer() { return $this->colorizer; } } author === null || $this->version === null ? '' : $this->prompt . $this->colorizer->colorize(sprintf($this->locale->_("Atoum version: %s \nAtoum path: %s \nAtoum author: %s"), $this->version, $this->path, $this->author))); } } setPrompt() ->setTitleColorizer() ->setCoverageColorizer() ; } public function __toString() { return $this->prompt . sprintf( '%s: %s.', $this->titleColorizer->colorize($this->locale->_('Code coverage')), $this->coverageColorizer->colorize( $this->coverage === null ? $this->locale->_('unknown') : sprintf($this->locale->_('%3.2f%%'), round($this->coverage->getValue() * 100, 2)) ) ) . PHP_EOL ; } public function setPrompt(prompt $prompt = null) { $this->prompt = $prompt ?: new prompt(); return $this; } public function getPrompt() { return $this->prompt; } public function setTitleColorizer(colorizer $colorizer = null) { $this->titleColorizer = $colorizer ?: new colorizer(); return $this; } public function getTitleColorizer() { return $this->titleColorizer; } public function setCoverageColorizer(colorizer $colorizer = null) { $this->coverageColorizer = $colorizer ?: new colorizer(); return $this; } public function getCoverageColorizer() { return $this->coverageColorizer; } } setProjectName($projectName) ->setDestinationDirectory($destinationDirectory) ->setAdapter() ->setUrlPrompt() ->setUrlColorizer() ->setTemplatesDirectory() ->setTemplateParser() ->setRootUrl('/') ; } public function __toString() { $string = ''; if ($this->adapter->extension_loaded('xdebug') === true) { foreach ($this->getSrcDirectoryIterators() as $srcDirectoryIterator) { foreach ($srcDirectoryIterator as $file) { $this->adapter->xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE); $declaredClasses = $this->adapter->get_declared_classes(); $this->adapter->ob_start(); require_once $file->getPathname(); $xDebugData = $this->adapter->xdebug_get_code_coverage(); $this->adapter->xdebug_stop_code_coverage(); $this->adapter->ob_end_clean(); foreach (array_diff($this->adapter->get_declared_classes(), $declaredClasses) as $class) { $this->coverage->addXdebugDataForClass($class, $xDebugData); } } } } if (sizeof($this->coverage) > 0) { try { $this->cleanDestinationDirectory(); $this->adapter->copy($this->templatesDirectory . DIRECTORY_SEPARATOR . 'screen.css', $this->destinationDirectory . DIRECTORY_SEPARATOR . 'screen.css'); $classes = $this->coverage->getClasses(); $indexTemplate = $this->templateParser->parseFile($this->templatesDirectory . DIRECTORY_SEPARATOR . 'index.tpl'); $indexTemplate->projectName = $this->projectName; $indexTemplate->rootUrl = $this->rootUrl; $coverageValue = $this->coverage->getValue(); if ($coverageValue === null) { $indexTemplate->coverageUnavailable->build(); } else { $indexTemplate->coverageAvailable->build(array('coverageValue' => round($coverageValue * 100, 2))); } $classCoverageTemplates = $indexTemplate->classCoverage; $classCoverageAvailableTemplates = $classCoverageTemplates->classCoverageAvailable; $classCoverageUnavailableTemplates = $classCoverageTemplates->classCoverageUnavailable; ksort($classes, \SORT_STRING); foreach ($classes as $className => $classFile) { $classCoverageTemplates->className = $className; $classCoverageTemplates->classUrl = str_replace('\\', '/', $className) . self::htmlExtensionFile; $classCoverageValue = $this->coverage->getValueForClass($className); if ($classCoverageValue === null) { $classCoverageUnavailableTemplates->build(); } else { $classCoverageAvailableTemplates->build(array('classCoverageValue' => round($classCoverageValue * 100, 2))); } $classCoverageTemplates->build(); $classCoverageAvailableTemplates->resetData(); $classCoverageUnavailableTemplates->resetData(); } $this->adapter->file_put_contents($this->destinationDirectory . DIRECTORY_SEPARATOR . 'index.html', (string) $indexTemplate->build()); $classTemplate = $this->templateParser->parseFile($this->templatesDirectory . DIRECTORY_SEPARATOR . 'class.tpl'); $classTemplate->rootUrl = $this->rootUrl; $classTemplate->projectName = $this->projectName; $classCoverageAvailableTemplates = $classTemplate->classCoverageAvailable; $classCoverageUnavailableTemplates = $classTemplate->classCoverageUnavailable; $methodsTemplates = $classTemplate->methods; $methodTemplates = $methodsTemplates->method; $methodCoverageAvailableTemplates = $methodTemplates->methodCoverageAvailable; $methodCoverageUnavailableTemplates = $methodTemplates->methodCoverageUnavailable; $sourceFileTemplates = $classTemplate->sourceFile; $lineTemplates = $sourceFileTemplates->line; $coveredLineTemplates = $sourceFileTemplates->coveredLine; $notCoveredLineTemplates = $sourceFileTemplates->notCoveredLine; foreach ($this->coverage->getMethods() as $className => $methods) { $classTemplate->className = $className; $classTemplate->relativeRootUrl = str_repeat('../', substr_count($className, '\\')); $classCoverageValue = $this->coverage->getValueForClass($className); if ($classCoverageValue === null) { $classCoverageUnavailableTemplates->build(); } else { $classCoverageAvailableTemplates->build(array('classCoverageValue' => round($classCoverageValue * 100, 2))); } $reflectedMethods = array(); foreach (array_filter($this->getReflectionClass($className)->getMethods(), function($reflectedMethod) use ($className) { return $reflectedMethod->isAbstract() === false && $reflectedMethod->getDeclaringClass()->getName() === $className; }) as $reflectedMethod) { $reflectedMethods[$reflectedMethod->getName()] = $reflectedMethod; } if (sizeof($reflectedMethods) > 0) { foreach (array_intersect(array_keys($reflectedMethods), array_keys($methods)) as $methodName) { $methodCoverageValue = $this->coverage->getValueForMethod($className, $methodName); if ($methodCoverageValue === null) { $methodCoverageUnavailableTemplates->build(array('methodName' => $methodName)); } else { $methodCoverageAvailableTemplates->build(array( 'methodName' => $methodName, 'methodCoverageValue' => round($methodCoverageValue * 100, 2) ) ); } $methodTemplates->build(); $methodCoverageAvailableTemplates->resetData(); $methodCoverageUnavailableTemplates->resetData(); } $methodsTemplates->build(); $methodTemplates->resetData(); } $srcFile = $this->adapter->fopen($classes[$className], 'r'); if ($srcFile !== false) { $methodLines = array(); foreach ($reflectedMethods as $reflectedMethodName => $reflectedMethod) { $methodLines[$reflectedMethod->getStartLine()] = $reflectedMethodName; } $currentMethod = null; for ($currentMethod = null, $lineNumber = 1, $line = $this->adapter->fgets($srcFile); $line !== false; $lineNumber++, $line = $this->adapter->fgets($srcFile)) { if (isset($methodLines[$lineNumber]) === true) { $currentMethod = $methodLines[$lineNumber]; } switch (true) { case isset($methods[$currentMethod]) === false || (isset($methods[$currentMethod][$lineNumber]) === false || $methods[$currentMethod][$lineNumber] == -2): $lineTemplateName = 'lineTemplates'; break; case isset($methods[$currentMethod]) === true && isset($methods[$currentMethod][$lineNumber]) === true && $methods[$currentMethod][$lineNumber] == -1: $lineTemplateName = 'notCoveredLineTemplates'; break; default: $lineTemplateName = 'coveredLineTemplates'; } ${$lineTemplateName}->lineNumber = $lineNumber; ${$lineTemplateName}->code = htmlentities($line, ENT_QUOTES, 'UTF-8'); if (isset($methodLines[$lineNumber]) === true) { foreach (${$lineTemplateName}->anchor as $anchorTemplate) { $anchorTemplate->resetData(); $anchorTemplate->method = $currentMethod; $anchorTemplate->build(); } } ${$lineTemplateName} ->addToParent() ->resetData() ; } $this->adapter->fclose($srcFile); } $file = $this->destinationDirectory . DIRECTORY_SEPARATOR . str_replace('\\', '/', $className) . self::htmlExtensionFile; $directory = $this->adapter->dirname($file); if ($this->adapter->is_dir($directory) === false) { $this->adapter->mkdir($directory, 0777, true); } $this->adapter->file_put_contents($file, (string) $classTemplate->build()); $classTemplate->resetData(); $classCoverageAvailableTemplates->resetData(); $classCoverageUnavailableTemplates->resetData(); $methodsTemplates->resetData(); $sourceFileTemplates->resetData(); } $string .= $this->urlPrompt . $this->urlColorizer->colorize(sprintf($this->locale->_('Details of code coverage are available at %s.'), $this->rootUrl)) . PHP_EOL; } catch (\exception $exception) { $string .= $this->urlPrompt . $this->urlColorizer->colorize(sprintf($this->locale->_('Unable to generate code coverage at %s: %s.'), $this->rootUrl, $exception->getMessage())) . PHP_EOL; } } return parent::__toString() . $string; } public function setReflectionClassInjector(\closure $reflectionClassInjector) { $closure = new \reflectionMethod($reflectionClassInjector, '__invoke'); if ($closure->getNumberOfParameters() != 1) { throw new exceptions\logic\invalidArgument('Reflection class injector must take one argument'); } $this->reflectionClassInjector = $reflectionClassInjector; return $this; } public function getReflectionClass($class) { $reflectionClass = null; if ($this->reflectionClassInjector === null) { $reflectionClass = new \reflectionClass($class); } else { $reflectionClass = $this->reflectionClassInjector->__invoke($class); if ($reflectionClass instanceof \reflectionClass === false) { throw new exceptions\runtime\unexpectedValue('Reflection class injector must return a \reflectionClass instance'); } } return $reflectionClass; } public function setProjectName($projectName) { $this->projectName = (string) $projectName; return $this; } public function getProjectName() { return $this->projectName; } public function setDestinationDirectory($path) { $this->destinationDirectory = (string) $path; return $this; } public function getDestinationDirectory() { return $this->destinationDirectory; } public function setAdapter(atoum\adapter $adapter = null) { $this->adapter = $adapter ?: new atoum\adapter(); return $this; } public function getAdapter() { return $this->adapter; } public function setUrlPrompt(prompt $prompt = null) { $this->urlPrompt = $prompt ?: new prompt(); return $this; } public function getUrlPrompt() { return $this->urlPrompt; } public function setUrlColorizer(colorizer $colorizer = null) { $this->urlColorizer = $colorizer ?: new colorizer(); return $this; } public function getUrlColorizer() { return $this->urlColorizer; } public function setTemplatesDirectory($path = null) { $this->templatesDirectory = ($path !== null ? (string) $path : atoum\directory . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'coverage'); return $this; } public function getTemplatesDirectory() { return $this->templatesDirectory; } public function setTemplateParser(template\parser $parser = null) { $this->templateParser = $parser ?: new template\parser(); return $this; } public function getTemplateParser() { return $this->templateParser; } public function setRootUrl($rootUrl) { $this->rootUrl = rtrim((string) $rootUrl, '/') . '/'; return $this; } public function getRootUrl() { return $this->rootUrl; } public function addSrcDirectory($srcDirectory, \closure $filterClosure = null) { $srcDirectory = (string) $srcDirectory; if (isset($this->srcDirectories[$srcDirectory]) === false) { $this->srcDirectories[$srcDirectory] = $filterClosure === null ? array() : array($filterClosure); } else if ($filterClosure !== null) { $this->srcDirectories[$srcDirectory][] = $filterClosure; } return $this; } public function getSrcDirectories() { return $this->srcDirectories; } public function getDestinationDirectoryIterator() { return new \recursiveIteratorIterator(new \recursiveDirectoryIterator($this->destinationDirectory, \filesystemIterator::KEY_AS_PATHNAME | \filesystemIterator::CURRENT_AS_FILEINFO | \filesystemIterator::SKIP_DOTS), \recursiveIteratorIterator::CHILD_FIRST); } public function getSrcDirectoryIterators() { $iterators = array(); foreach ($this->srcDirectories as $srcDirectory => $closures) { $iterators[] = $iterator = new \recursiveIteratorIterator(new atoum\iterators\filters\recursives\closure(new \recursiveDirectoryIterator($srcDirectory, \filesystemIterator::SKIP_DOTS|\filesystemIterator::CURRENT_AS_FILEINFO)), \recursiveIteratorIterator::LEAVES_ONLY); foreach ($closures as $closure) { $iterator->addClosure($closure); } } return $iterators; } public function cleanDestinationDirectory() { try { foreach ($this->getDestinationDirectoryIterator() as $inode) { if ($inode->isDir() === false) { $this->adapter->unlink($inode->getPathname()); } else if (($pathname = $inode->getPathname()) !== $this->destinationDirectory) { $this->adapter->rmdir($pathname); } } } catch (\exception $exception) {} return $this; } } setProjectName($projectName) ->setDestinationDirectory($destinationDirectory) ->setAdapter() ->setUrlPrompt() ->setUrlColorizer() ->setTreemapUrl('/') ->setResourcesDirectory() ; } public function __toString() { $string = ''; if ($this->adapter->extension_loaded('xdebug') === true) { foreach ($this->getSrcDirectoryIterators() as $srcDirectoryIterator) { foreach ($srcDirectoryIterator as $file) { $this->adapter->xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE); $declaredClasses = $this->adapter->get_declared_classes(); $this->adapter->ob_start(); require_once $file->getPathname(); $xDebugData = $this->adapter->xdebug_get_code_coverage(); $this->adapter->xdebug_stop_code_coverage(); $this->adapter->ob_end_clean(); foreach (array_diff($this->adapter->get_declared_classes(), $declaredClasses) as $class) { $this->coverage->addXdebugDataForClass($class, $xDebugData); } } } } if (sizeof($this->coverage) > 0) { try { $nodes = array( 'coverage' => round($this->coverage->getValue() * 100, 2), 'project' => $this->projectName, 'name' => '', 'fullname' => '', 'htmlReportBaseUrl' => $this->htmlReportBaseUrl, 'date' => time(), 'children' => array() ); foreach ($this->coverage->getClasses() as $className => $classPath) { $node = & $nodes; $class = new \reflectionClass($className); $namespaces = explode('\\', $class->getNamespaceName()); foreach ($namespaces as $namespace) { $childFound = false; foreach ($node['children'] as $key => $child) { $childFound = ($child['name'] === $namespace); if ($childFound === true) { break; } } if ($childFound === false) { $key = sizeof($node['children']); $node['children'][] = array( 'name' => $namespace, 'fullname' => $node['fullname'] . ($node['fullname'] == '' ? '' : '\\') . $namespace, 'children' => array() ); } $node = & $node['children'][$key]; } $child = array( 'name' => $class->getShortName(), 'fullname' => $node['fullname'] . '\\' . $class->getShortName(), 'covered' => $this->coverage->getNumberOfCoveredLinesInClass($className), 'coverable' => $this->coverage->getNumberOfCoverableLinesInClass($className), 'pourcent' => round($this->coverage->getValueForClass($className) * 100, 2), 'children' => array() ); $node['children'][] = $child; } if (@file_put_contents($this->destinationDirectory . DIRECTORY_SEPARATOR . self::dataFile, json_encode($nodes)) === false) { throw new exceptions\runtime($this->locale->_('Unable to write in \'' . $this->destinationDirectory . '\'')); } try { $resourcesDirectoryIterator = new \recursiveIteratorIterator(new atoum\iterators\filters\recursives\dot($this->resourcesDirectory)); } catch (\exception $exception) { throw new exceptions\runtime($this->locale->_('Directory \'' . $this->resourcesDirectory . '\' does not exist')); } foreach ($resourcesDirectoryIterator as $file) { if (@copy($file, $this->destinationDirectory . DIRECTORY_SEPARATOR . $resourcesDirectoryIterator->getSubPathname()) === false) { throw new exceptions\runtime($this->locale->_('Unable to write in \'' . $this->destinationDirectory . '\'')); } } $string .= $this->urlPrompt . $this->urlColorizer->colorize(sprintf($this->locale->_('Treemap of code coverage are available at %s.'), $this->treemapUrl)) . PHP_EOL; } catch (\exception $exception) { $string .= $this->urlPrompt . $this->urlColorizer->colorize(sprintf($this->locale->_('Unable to generate code coverage at %s: %s.'), $this->treemapUrl, $exception->getMessage())) . PHP_EOL; } } return $string; } public function getHtmlReportBaseUrl() { return $this->htmlReportBaseUrl; } public function setHtmlReportBaseUrl($url) { $this->htmlReportBaseUrl = (string) $url; return $this; } public function addSrcDirectory($srcDirectory, \closure $filterClosure = null) { $srcDirectory = (string) $srcDirectory; if (isset($this->srcDirectories[$srcDirectory]) === false) { $this->srcDirectories[$srcDirectory] = $filterClosure === null ? array() : array($filterClosure); } else if ($filterClosure !== null) { $this->srcDirectories[$srcDirectory][] = $filterClosure; } return $this; } public function getSrcDirectories() { return $this->srcDirectories; } public function setReflectionClassFactory(\closure $factory) { $closure = new \reflectionMethod($factory, '__invoke'); if ($closure->getNumberOfParameters() != 1) { throw new exceptions\logic\invalidArgument('Reflection class factory must take one argument'); } $this->reflectionClassFactory = $factory; return $this; } public function getReflectionClass($class) { $reflectionClass = null; if ($this->reflectionClassFactory === null) { $reflectionClass = new \reflectionClass($class); } else { $reflectionClass = $this->reflectionClassFactory->__invoke($class); if ($reflectionClass instanceof \reflectionClass === false) { throw new exceptions\runtime\unexpectedValue('Reflection class injector must return a \reflectionClass instance'); } } return $reflectionClass; } public function setProjectName($projectName) { $this->projectName = (string) $projectName; return $this; } public function getProjectName() { return $this->projectName; } public function setDestinationDirectory($path) { $this->destinationDirectory = (string) $path; return $this; } public function getDestinationDirectory() { return $this->destinationDirectory; } public function setAdapter(atoum\adapter $adapter = null) { $this->adapter = $adapter ?: new atoum\adapter(); return $this; } public function getAdapter() { return $this->adapter; } public function setUrlPrompt(prompt $prompt = null) { $this->urlPrompt = $prompt ?: new prompt(); return $this; } public function getUrlPrompt() { return $this->urlPrompt; } public function setUrlColorizer(colorizer $colorizer = null) { $this->urlColorizer = $colorizer ?: new colorizer(); return $this; } public function getUrlColorizer() { return $this->urlColorizer; } public function setTreemapUrl($treemapUrl) { $this->treemapUrl = rtrim((string) $treemapUrl, '/') . '/'; return $this; } public function getTreemapUrl() { return $this->treemapUrl; } public function setResourcesDirectory($directory = null) { $this->resourcesDirectory = $directory ?: atoum\directory . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'coverage' . DIRECTORY_SEPARATOR . 'treemap'; return $this; } public function getResourcesDirectory() { return $this->resourcesDirectory; } public function getSrcDirectoryIterators() { $iterators = array(); foreach ($this->srcDirectories as $srcDirectory => $closures) { $iterators[] = $iterator = new \recursiveIteratorIterator(new atoum\iterators\filters\recursives\closure(new \recursiveDirectoryIterator($srcDirectory, \filesystemIterator::SKIP_DOTS|\filesystemIterator::CURRENT_AS_FILEINFO)), \recursiveIteratorIterator::LEAVES_ONLY); foreach ($closures as $closure) { $iterator->addClosure($closure); } } return $iterators; } } setPrompt() ->setTitleColorizer() ->setDurationColorizer() ; } public function __toString() { return $this->prompt . sprintf( $this->locale->_('%1$s: %2$s.'), $this->titleColorizer->colorize($this->locale->_('Running duration')), $this->durationColorizer->colorize($this->value === null ? $this->locale->_('unknown') : sprintf($this->locale->__('%4.2f second', '%4.2f seconds', $this->value), $this->value)) ) . PHP_EOL ; } public function setPrompt(prompt $prompt = null) { $this->prompt = $prompt ?: new prompt(); return $this; } public function getPrompt() { return $this->prompt; } public function setTitleColorizer(colorizer $colorizer = null) { $this->titleColorizer = $colorizer ?: new colorizer(); return $this; } public function getTitleColorizer() { return $this->titleColorizer; } public function setDurationColorizer(colorizer $colorizer = null) { $this->durationColorizer = $colorizer ?: new colorizer(); return $this; } public function getDurationColorizer() { return $this->durationColorizer; } } prompt . sprintf( $this->locale->_('%1$s: %2$s.'), $this->titleColorizer->colorize($this->locale->_('Running duration')), $this->durationColorizer->colorize($this->value === null ? $this->locale->_('unknown') : sprintf($this->locale->__('%4.2f second', '%4.2f seconds', $this->value), $this->value) ) ); } } setTitlePrompt() ->setTitleColorizer() ->setMethodPrompt() ->setMethodColorizer() ->setErrorPrompt() ->setErrorColorizer() ; } public function __toString() { $string = ''; if ($this->runner !== null) { $errors = $this->runner->getScore()->getErrors(); $sizeOfErrors = sizeof($errors); if ($sizeOfErrors > 0) { $string .= $this->titlePrompt . sprintf( $this->locale->_('%s:'), $this->titleColorizer->colorize(sprintf($this->locale->__('There is %d error', 'There are %d errors', $sizeOfErrors), $sizeOfErrors)) ) . PHP_EOL ; $class = null; $method = null; foreach ($errors as $error) { if ($error['class'] !== $class || $error['method'] !== $method) { $string .= $this->methodPrompt . sprintf( $this->locale->_('%s:'), $this->methodColorizer->colorize($error['class'] . '::' . $error['method'] . '()') ) . PHP_EOL ; $class = $error['class']; $method = $error['method']; } $string .= $this->errorPrompt; $type = static::getType($error['type']); if ($error['case'] === null) { switch (true) { case $error['file'] === null: switch (true) { case $error['errorFile'] === null: $errorMessage = sprintf($this->locale->_('Error %s in unknown file on unknown line, generated by unknown file'), $type); break; case $error['errorLine'] === null: $errorMessage = sprintf($this->locale->_('Error %s in unknown file on unknown line, generated by file %s'), $type, $error['errorFile']); break; case $error['errorLine'] !== null: $errorMessage = sprintf($this->locale->_('Error %s in unknown file on unknown line, generated by file %s on line %d'), $type, $error['errorFile'], $error['errorLine']); break; } break; case $error['line'] === null: switch (true) { case $error['errorFile'] === null: $errorMessage = sprintf($this->locale->_('Error %s in %s on unknown line, generated by unknown file'), $type, $error['file']); break; case $error['errorLine'] === null: $errorMessage = sprintf($this->locale->_('Error %s in %s on unknown line, generated by file %s'), $type, $error['file'], $error['errorFile']); break; case $error['errorLine'] !== null: $errorMessage = sprintf($this->locale->_('Error %s in %s on unknown line, generated by file %s on line %d'), $type, $error['file'], $error['errorFile'], $error['errorLine']); break; } break; default: switch (true) { case $error['errorFile'] === null: $errorMessage = sprintf($this->locale->_('Error %s in %s on line %d, generated by unknown file'), $type, $error['file'], $error['line']); break; case $error['errorLine'] === null: $errorMessage = sprintf($this->locale->_('Error %s in %s on line %d, generated by file %s'), $type, $error['file'], $error['line'], $error['errorFile']); break; case $error['errorLine'] !== null: $errorMessage = sprintf($this->locale->_('Error %s in %s on line %d, generated by file %s on line %d'), $type, $error['file'], $error['line'], $error['errorFile'], $error['errorLine']); break; } break; } } else { switch (true) { case $error['file'] === null: switch (true) { case $error['errorFile'] === null: $errorMessage = sprintf($this->locale->_('Error %s in unknown file on unknown line in case \'%s\', generated by unknown file'), $type, $error['case']); break; case $error['errorLine'] === null: $errorMessage = sprintf($this->locale->_('Error %s in unknown file on unknown line, generated by file %s in case \'%s\''), $type, $error['errorFile'], $error['case']); break; case $error['errorLine'] !== null: $errorMessage = sprintf($this->locale->_('Error %s in unknown file on unknown line, generated by file %s on line %d in case \'%s\''), $type, $error['errorFile'], $error['errorLine'], $error['case']); break; } break; case $error['line'] === null: switch (true) { case $error['errorFile'] === null: $errorMessage = sprintf($this->locale->_('Error %s in %s on unknown line, generated by unknown file in case \'%s\''), $type, $error['file'], $error['case']); break; case $error['errorLine'] === null: $errorMessage = sprintf($this->locale->_('Error %s in %s on unknown line, generated by file %s in case \'%s\''), $type, $error['file'], $error['errorFile'], $error['case']); break; case $error['errorLine'] !== null: $errorMessage = sprintf($this->locale->_('Error %s in %s on unknown line, generated by file %s on line %d in case \'%s\''), $type, $error['file'], $error['errorFile'], $error['errorLine'], $error['case']); break; } break; default: switch (true) { case $error['errorFile'] === null: $errorMessage = sprintf($this->locale->_('Error %s in %s on line %d, generated by unknown file in case \'%s\''), $type, $error['file'], $error['line'], $error['case']); break; case $error['errorLine'] === null: $errorMessage = sprintf($this->locale->_('Error %s in %s on line %d, generated by file %s in case \'%s\''), $type, $error['file'], $error['line'], $error['errorFile'], $error['case']); break; case $error['errorLine'] !== null: $errorMessage = sprintf($this->locale->_('Error %s in %s on line %d, generated by file %s on line %d in case \'%s\''), $type, $error['file'], $error['line'], $error['errorFile'], $error['errorLine'], $error['case']); break; } break; } } $string .= sprintf( $this->locale->_('%s:'), $this->errorColorizer->colorize(($errorMessage)) ) . PHP_EOL ; foreach (explode(PHP_EOL, $error['message']) as $line) { $string .= $line . PHP_EOL; } } } } return $string; } public function setTitlePrompt(prompt $prompt = null) { $this->titlePrompt = $prompt ?: new prompt(); return $this; } public function getTitlePrompt() { return $this->titlePrompt; } public function setTitleColorizer(colorizer $colorizer = null) { $this->titleColorizer = $colorizer ?: new colorizer(); return $this; } public function getTitleColorizer() { return $this->titleColorizer; } public function setMethodPrompt(prompt $prompt = null) { $this->methodPrompt = $prompt ?: new prompt(); return $this; } public function getMethodPrompt() { return $this->methodPrompt; } public function setMethodColorizer(colorizer $colorizer = null) { $this->methodColorizer = $colorizer ?: new colorizer(); return $this; } public function getMethodColorizer() { return $this->methodColorizer; } public function setErrorPrompt(prompt $prompt = null) { $this->errorPrompt = $prompt ?: new prompt(); return $this; } public function getErrorPrompt() { return $this->errorPrompt; } public function setErrorColorizer(colorizer $colorizer = null) { $this->errorColorizer = $colorizer ?: new colorizer(); return $this; } public function getErrorColorizer() { return $this->errorColorizer; } } progressBar = $progressBar ?: new progressBar(); } public function __toString() { $string = ''; if ($this->observable !== null) { if ($this->event === runner::runStop) { $string = PHP_EOL; } else { switch ($this->event) { case runner::runStart: $this->progressBar->reset()->setIterations($this->observable->getTestMethodNumber()); break; case test::success: $this->progressBar->refresh('S'); break; case test::fail: $this->progressBar->refresh('F'); break; case test::void: $this->progressBar->refresh('0'); break; case test::error: $this->progressBar->refresh('E'); break; case test::exception: $this->progressBar->refresh('X'); break; case test::uncompleted: $this->progressBar->refresh('U'); break; case test::skipped: $this->progressBar->refresh('-'); break; case runner::runStop: $this->progressBar->reset(); break; } $string = (string) $this->progressBar; } } return $string; } public function getProgressBar() { return $this->progressBar; } } setTitlePrompt() ->setTitleColorizer() ->setMethodPrompt() ->setMethodColorizer() ->setExceptionPrompt() ->setExceptionColorizer() ; } public function __toString() { $string = ''; if ($this->runner !== null) { $exceptions = $this->runner->getScore()->getExceptions(); $sizeOfErrors = sizeof($exceptions); if ($sizeOfErrors > 0) { $string .= $this->titlePrompt . sprintf( $this->locale->_('%s:'), $this->colorizeTitle(sprintf($this->locale->__('There is %d exception', 'There are %d exceptions', $sizeOfErrors), $sizeOfErrors)) ) . PHP_EOL ; $class = null; $method = null; foreach ($exceptions as $exception) { if ($exception['class'] !== $class || $exception['method'] !== $method) { $string .= $this->methodPrompt . sprintf( $this->locale->_('%s:'), $this->colorizeMethod($exception['class'] . '::' . $exception['method'] . '()') ) . PHP_EOL ; $class = $exception['class']; $method = $exception['method']; } $string .= $this->exceptionPrompt . sprintf( $this->locale->_('%s:'), $this->colorizeException(sprintf($this->locale->_('Exception throwed in file %s on line %d'), $exception['file'], $exception['line'])) ) . PHP_EOL ; foreach (explode(PHP_EOL, rtrim($exception['value'])) as $line) { $string .= $this->exceptionPrompt . $line . PHP_EOL; } } } } return $string; } public function setTitlePrompt(prompt $prompt = null) { $this->titlePrompt = $prompt ?: new prompt(); return $this; } public function getTitlePrompt() { return $this->titlePrompt; } public function setTitleColorizer(colorizer $colorizer = null) { $this->titleColorizer = $colorizer ?: new colorizer(); return $this; } public function getTitleColorizer() { return $this->titleColorizer; } public function setMethodPrompt(prompt $prompt = null) { $this->methodPrompt = $prompt ?: new prompt(); return $this; } public function getMethodPrompt() { return $this->methodPrompt; } public function setMethodColorizer(colorizer $colorizer = null) { $this->methodColorizer = $colorizer ?: new colorizer(); return $this; } public function getMethodColorizer() { return $this->methodColorizer; } public function setExceptionPrompt(prompt $prompt = null) { $this->exceptionPrompt = $prompt ?: new prompt(); return $this; } public function getExceptionPrompt() { return $this->exceptionPrompt; } public function setExceptionColorizer(colorizer $colorizer = null) { $this->exceptionColorizer = $colorizer ?: new colorizer(); return $this; } public function getExceptionColorizer() { return $this->exceptionColorizer; } private function colorizeTitle($title) { return $this->titleColorizer === null ? $title : $this->titleColorizer->colorize($title); } private function colorizeMethod($method) { return $this->methodColorizer === null ? $method : $this->methodColorizer->colorize($method); } private function colorizeException($exception) { return $this->exceptionColorizer === null ? $exception : $this->exceptionColorizer->colorize($exception); } } /dev/null &'); } } /dev/null &'); } } /dev/null &'); } } /dev/null &'; } } setTitlePrompt() ->setTitleColorizer() ->setMethodPrompt() ->setMethodColorizer() ; } public function __toString() { $string = ''; if ($this->runner !== null) { $fails = $this->runner->getScore()->getFailAssertions(); $numberOfFails = sizeof($fails); if ($numberOfFails > 0) { $string .= $this->titlePrompt . sprintf( $this->locale->_('%s:'), $this->titleColorizer->colorize(sprintf($this->locale->__('There is %d failure', 'There are %d failures', $numberOfFails), $numberOfFails)) ) . PHP_EOL ; foreach ($fails as $fail) { $string .= $this->methodPrompt . sprintf( '%s:', $this->methodColorizer->colorize(($fail['class'] . '::' . $fail['method'] . '()')) ) . PHP_EOL ; switch (true) { case $fail['case'] === null && $fail['dataSetKey'] === null: $string .= sprintf($this->locale->_('In file %s on line %d, %s failed: %s'), $fail['file'], $fail['line'], $fail['asserter'], $fail['fail']); break; case $fail['case'] === null && $fail['dataSetKey'] !== null: $string .= sprintf($this->locale->_('In file %s on line %d, %s failed for data set #%s of data provider %s: %s'), $fail['file'], $fail['line'], $fail['asserter'], $fail['dataSetKey'], $fail['dataSetProvider'], $fail['fail']); break; case $fail['case'] !== null && $fail['dataSetKey'] === null: $string .= sprintf($this->locale->_('In file %s on line %d in case \'%s\', %s failed: %s'), $fail['file'], $fail['line'], $fail['case'], $fail['asserter'], $fail['fail']); break; case $fail['case'] !== null && $fail['dataSetKey'] !== null: $string .= sprintf($this->locale->_('In file %s on line %d in case \'%s\', %s failed for data set #%s of data provider %s: %s'), $fail['file'], $fail['line'], $fail['case'], $fail['asserter'], $fail['dataSetKey'], $fail['dataSetProvider'], $fail['fail']); break; } $string .= PHP_EOL; } } } return $string; } public function setTitlePrompt(prompt $prompt = null) { $this->titlePrompt = $prompt ?: new prompt(); return $this; } public function getTitlePrompt() { return $this->titlePrompt; } public function setTitleColorizer(colorizer $colorizer = null) { $this->titleColorizer = $colorizer ?: new colorizer(); return $this; } public function getTitleColorizer() { return $this->titleColorizer; } public function setMethodPrompt(prompt $prompt = null) { $this->methodPrompt = $prompt ?: new prompt(); return $this; } public function getMethodPrompt() { return $this->methodPrompt; } public function setMethodColorizer(colorizer $colorizer = null) { $this->methodColorizer = $colorizer ?: new colorizer(); return $this; } public function getMethodColorizer() { return $this->methodColorizer; } } setCommand($command) ->setAdapter() ; } public function __toString() { if ($this->runner !== null) { $fails = array(); foreach ($this->runner->getScore()->getFailAssertions() as $fail) { switch (true) { case isset($fails[$fail['file']]) === false: case $fails[$fail['file']] > $fail['line']: $fails[$fail['file']] = $fail['line']; } } ksort($fails); foreach ($fails as $file => $line) { $this->adapter->system(sprintf($this->getCommand(), $file, $line)); } } return ''; } public function setCommand($command) { $this->command = (string) $command; return $this; } public function getCommand() { return $this->command; } public function setAdapter(adapter $adapter = null) { $this->adapter = $adapter ?: new adapter(); return $this; } public function getAdapter() { return $this->adapter; } } setTitlePrompt() ->setTitleColorizer() ->setMethodPrompt() ->setMethodColorizer() ->setOutputPrompt() ->setOutputColorizer() ; } public function __toString() { $string = ''; if ($this->runner !== null) { $outputs = $this->runner->getScore()->getOutputs(); $sizeOfOutputs = sizeof($outputs); if ($sizeOfOutputs > 0) { $string .= $this->titlePrompt . sprintf( $this->locale->_('%s:'), $this->titleColorizer->colorize(sprintf($this->locale->__('There is %d output', 'There are %d outputs', $sizeOfOutputs), $sizeOfOutputs)) ) . PHP_EOL ; foreach ($outputs as $output) { $string .= $this->methodPrompt . sprintf('%s:', $this->methodColorizer->colorize(sprintf($this->locale->_('In %s::%s()'), $output['class'], $output['method']))) . PHP_EOL; foreach (explode(PHP_EOL, rtrim($output['value'])) as $line) { $string .= $this->outputPrompt . $this->outputColorizer->colorize($line) . PHP_EOL; } } } } return $string; } public function setTitlePrompt(prompt $prompt = null) { $this->titlePrompt = $prompt ?: new prompt(); return $this; } public function getTitlePrompt() { return $this->titlePrompt; } public function setTitleColorizer(colorizer $colorizer = null) { $this->titleColorizer = $colorizer ?: new colorizer(); return $this; } public function getTitleColorizer() { return $this->titleColorizer; } public function setMethodPrompt(prompt $prompt = null) { $this->methodPrompt = $prompt ?: new prompt(); return $this; } public function getMethodPrompt() { return $this->methodPrompt; } public function setMethodColorizer(colorizer $colorizer = null) { $this->methodColorizer = $colorizer ?: new colorizer(); return $this; } public function getMethodColorizer() { return $this->methodColorizer; } public function setOutputPrompt(prompt $prompt = null) { $this->outputPrompt = $prompt ?: new prompt(); return $this; } public function getOutputPrompt() { return $this->outputPrompt; } public function setOutputColorizer(colorizer $colorizer = null) { $this->outputColorizer = $colorizer ?: new colorizer(); return $this; } public function getOutputColorizer() { return $this->outputColorizer; } } setPrompt() ->setTitleColorizer() ->setPathColorizer() ; } public function __toString() { return $this->prompt . sprintf( $this->locale->_('%1$s: %2$s'), $this->titleColorizer->colorize($this->locale->_('PHP path')), $this->pathColorizer->colorize($this->path) ) . PHP_EOL ; } public function setPrompt(prompt $prompt = null) { $this->prompt = $prompt ?: new prompt(); return $this; } public function getPrompt() { return $this->prompt; } public function setTitleColorizer(colorizer $colorizer = null) { $this->titleColorizer = $colorizer ?: new colorizer(); return $this; } public function getTitleColorizer() { return $this->titleColorizer; } public function setPathColorizer(colorizer $colorizer = null) { $this->pathColorizer = $colorizer ?: new colorizer(); return $this; } public function getPathColorizer() { return $this->pathColorizer; } } setTitlePrompt() ->setTitleColorizer() ->setVersionPrompt() ->setVersionColorizer() ; } public function __toString() { $string = $this->titlePrompt . sprintf( '%s:', $this->titleColorizer->colorize($this->locale->_('PHP version')) ) . PHP_EOL ; foreach (explode(PHP_EOL, $this->version) as $line) { $string .= $this->versionPrompt . $this->versionColorizer->colorize(rtrim($line)) . PHP_EOL; } return $string; } public function setTitlePrompt(prompt $prompt = null) { $this->titlePrompt = $prompt ?: new prompt(); return $this; } public function getTitlePrompt() { return $this->titlePrompt; } public function setTitleColorizer(colorizer $colorizer = null) { $this->titleColorizer = $colorizer ?: new colorizer(); return $this; } public function getTitleColorizer() { return $this->titleColorizer; } public function setVersionPrompt(prompt $prompt = null) { $this->versionPrompt = $prompt ?: new prompt(); return $this; } public function getVersionPrompt() { return $this->versionPrompt; } public function setVersionColorizer(colorizer $colorizer = null) { $this->versionColorizer = $colorizer ?: new colorizer(); return $this; } public function getVersionColorizer() { return $this->versionColorizer; } } path; } public function handleEvent($event, atoum\observable $observable) { if (parent::handleEvent($event, $observable) === false) { return false; } else { $this->path = $observable->getScore()->getPhpPath(); return true; } } } version; } public function handleEvent($event, atoum\observable $observable) { if (parent::handleEvent($event, $observable) === false) { return false; } else { $this->version = $observable->getScore()->getPhpVersion(); return true; } } } callbackUrl = $url; return $this; } public function send($title, $message, $success) { return $this->adapter->system(sprintf($this->getCommand(), escapeshellarg($title), escapeshellarg($message), escapeshellarg($this->getImage($success)), escapeshellarg($this->callbackUrl))); } } getMessage() . PHP_EOL; } } public function setSuccessImage($path) { $this->successImage = $path; return $this; } public function getSuccessImage() { return $this->successImage; } public function setFailureImage($path) { $this->failureImage = $path; return $this; } public function getFailureImage() { return $this->failureImage; } public function getImage($success) { $image = $success ? $this->getSuccessImage() : $this->getFailureImage(); if ($this->getAdapter()->file_exists($image) === false) { throw new exceptions\runtime(sprintf('File %s does not exist', $image)); } return $image; } public function send($title, $message, $success) { return parent::send($title, $message, $this->getImage($success)); } } callbackCommand = $command; return $this; } public function send($title, $message, $success) { return $this->adapter->system(sprintf($this->getCommand(), escapeshellarg($title), escapeshellarg($message), escapeshellarg($this->callbackCommand))); } } setPrompt() ->setSuccessColorizer() ->setFailureColorizer() ; } public function __toString() { $string = $this->prompt; if ($this->testNumber === null ) { $string .= $this->locale->_('No test running.'); } else if ($this->failNumber === 0 && $this->errorNumber === 0 && $this->exceptionNumber === 0 && $this->uncompletedMethodNumber === 0) { $string .= $this->successColorizer->colorize( sprintf( $this->locale->_('Success (%s, %s, %s, %s, %s) !'), sprintf($this->locale->__('%s test', '%s tests', $this->testNumber), $this->testNumber), sprintf($this->locale->__('%s/%s method', '%s/%s methods', $this->testMethodNumber), $this->testMethodNumber - $this->voidMethodNumber - $this->skippedMethodNumber, $this->testMethodNumber), sprintf($this->locale->__('%s void method', '%s void methods', $this->voidMethodNumber), $this->voidMethodNumber), sprintf($this->locale->__('%s skipped method', '%s skipped methods', $this->skippedMethodNumber), $this->skippedMethodNumber), sprintf($this->locale->__('%s assertion', '%s assertions', $this->assertionNumber), $this->assertionNumber) ) ) ; } else { $string .= $this->failureColorizer->colorize( sprintf( $this->locale->_('Failure (%s, %s, %s, %s, %s, %s, %s, %s) !'), sprintf($this->locale->__('%s test', '%s tests', $this->testNumber), $this->testNumber), sprintf($this->locale->__('%s/%s method', '%s/%s methods', $this->testMethodNumber), $this->testMethodNumber - $this->voidMethodNumber - $this->skippedMethodNumber - $this->uncompletedMethodNumber, $this->testMethodNumber), sprintf($this->locale->__('%s void method', '%s void methods', $this->voidMethodNumber), $this->voidMethodNumber), sprintf($this->locale->__('%s skipped method', '%s skipped methods', $this->skippedMethodNumber), $this->skippedMethodNumber), sprintf($this->locale->__('%s uncompleted method', '%s uncompleted methods', $this->uncompletedMethodNumber), $this->uncompletedMethodNumber), sprintf($this->locale->__('%s failure', '%s failures', $this->failNumber), $this->failNumber), sprintf($this->locale->__('%s error', '%s errors', $this->errorNumber), $this->errorNumber), sprintf($this->locale->__('%s exception', '%s exceptions', $this->exceptionNumber), $this->exceptionNumber) ) ) ; } return $string . PHP_EOL; } public function setPrompt(prompt $prompt = null) { $this->prompt = $prompt ?: new prompt(); return $this; } public function getPrompt() { return $this->prompt; } public function setSuccessColorizer(colorizer $colorizer = null) { $this->successColorizer = $colorizer ?: new colorizer(); return $this; } public function getSuccessColorizer() { return $this->successColorizer; } public function setFailureColorizer(colorizer $colorizer = null) { $this->failureColorizer = $colorizer ?: new colorizer(); return $this; } public function getFailureColorizer() { return $this->failureColorizer; } } failNumber === 0 && $this->errorNumber === 0 && $this->exceptionNumber === 0 && $this->uncompletedMethodNumber === 0) { return " \033[48;5;16m \033[0m \033[48;5;16m \033[0m \033[48;5;16m \033[0m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;231m \033[48;5;120m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;120m \033[48;5;231m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;231m \033[48;5;120m \033[48;5;16m \033[48;5;120m \033[48;5;231m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;231m \033[48;5;120m \033[48;5;16m \033[48;5;157m \033[48;5;16m \033[48;5;120m \033[48;5;231m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;34m \033[48;5;16m \033[48;5;157m \033[48;5;120m \033[48;5;157m \033[48;5;16m \033[48;5;34m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;157m \033[48;5;120m \033[48;5;157m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;157m \033[48;5;120m \033[48;5;157m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;157m \033[48;5;120m \033[48;5;16m \033[48;5;120m \033[48;5;16m \033[48;5;120m \033[48;5;157m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;83m \033[48;5;16m \033[48;5;157m \033[48;5;120m \033[48;5;16m \033[48;5;120m \033[48;5;16m \033[48;5;120m \033[48;5;157m \033[48;5;16m \033[48;5;83m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;157m \033[48;5;120m \033[48;5;157m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;157m \033[48;5;120m \033[48;5;157m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;157m \033[48;5;120m \033[48;5;157m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;83m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;83m \033[48;5;16m \033[48;5;83m \033[48;5;16m \033[48;5;83m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;83m \033[48;5;16m \033[0m \033[48;5;16m \033[0m \033[0m" . PHP_EOL; } else { return " \033[48;5;16m \033[0m \033[48;5;16m \033[0m \033[48;5;16m \033[0m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;231m \033[48;5;211m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;211m \033[48;5;231m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;231m \033[48;5;211m \033[48;5;16m \033[48;5;211m \033[48;5;231m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;231m \033[48;5;211m \033[48;5;16m \033[48;5;218m \033[48;5;16m \033[48;5;211m \033[48;5;231m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;124m \033[48;5;16m \033[48;5;218m \033[48;5;204m \033[48;5;218m \033[48;5;16m \033[48;5;124m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;218m \033[48;5;204m \033[48;5;218m \033[48;5;16m \033[0m \033[0m \033[48;5;16m \033[48;5;218m \033[48;5;204m \033[48;5;218m \033[48;5;16m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;218m \033[48;5;204m \033[48;5;16m \033[48;5;204m \033[48;5;16m \033[48;5;204m \033[48;5;218m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;197m \033[48;5;16m \033[48;5;218m \033[48;5;204m \033[48;5;16m \033[48;5;204m \033[48;5;16m \033[48;5;204m \033[48;5;218m \033[48;5;16m \033[48;5;197m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;218m \033[48;5;204m \033[48;5;218m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;218m \033[48;5;204m \033[48;5;218m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;218m \033[48;5;204m \033[48;5;218m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;197m \033[48;5;197m \033[48;5;197m \033[48;5;197m \033[48;5;197m \033[48;5;197m \033[48;5;197m \033[48;5;197m \033[48;5;197m \033[48;5;197m \033[48;5;197m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;197m \033[48;5;197m \033[48;5;16m \033[48;5;197m \033[48;5;16m \033[48;5;197m \033[48;5;197m \033[48;5;16m \033[0m \033[48;5;16m \033[48;5;197m \033[48;5;197m \033[48;5;197m \033[48;5;197m \033[48;5;197m \033[48;5;197m \033[48;5;197m \033[48;5;16m \033[0m \033[48;5;16m \033[0m \033[0m" . PHP_EOL; } } } setAdapter($adapter); } public function __toString() { $string = $this->notify(); return $string == '' ? '' : trim($string) . PHP_EOL; } public function notify() { $success = ($this->failNumber === 0 && $this->errorNumber === 0 && $this->exceptionNumber === 0 && $this->uncompletedMethodNumber === 0); if ($success === true) { $title = 'Success !'; $message = sprintf( $this->locale->_('%s %s %s %s %s'), sprintf($this->locale->__('%s test', '%s tests', $this->testNumber), $this->testNumber) . PHP_EOL, sprintf($this->locale->__('%s/%s method', '%s/%s methods', $this->testMethodNumber), $this->testMethodNumber - $this->voidMethodNumber - $this->skippedMethodNumber, $this->testMethodNumber) . PHP_EOL, sprintf($this->locale->__('%s void method', '%s void methods', $this->voidMethodNumber), $this->voidMethodNumber) . PHP_EOL, sprintf($this->locale->__('%s skipped method', '%s skipped methods', $this->skippedMethodNumber), $this->skippedMethodNumber) . PHP_EOL, sprintf($this->locale->__('%s assertion', '%s assertions', $this->assertionNumber), $this->assertionNumber) . PHP_EOL ); } else { $title = 'Failure !'; $message = sprintf( $this->locale->_('%s %s %s %s %s %s %s %s'), sprintf($this->locale->__('%s test', '%s tests', $this->testNumber), $this->testNumber) . PHP_EOL, sprintf($this->locale->__('%s/%s method', '%s/%s methods', $this->testMethodNumber), $this->testMethodNumber - $this->voidMethodNumber - $this->skippedMethodNumber - $this->uncompletedMethodNumber, $this->testMethodNumber) . PHP_EOL, sprintf($this->locale->__('%s void method', '%s void methods', $this->voidMethodNumber), $this->voidMethodNumber) . PHP_EOL, sprintf($this->locale->__('%s skipped method', '%s skipped methods', $this->skippedMethodNumber), $this->skippedMethodNumber) . PHP_EOL, sprintf($this->locale->__('%s uncompleted method', '%s uncompleted methods', $this->uncompletedMethodNumber), $this->uncompletedMethodNumber) . PHP_EOL, sprintf($this->locale->__('%s failure', '%s failures', $this->failNumber), $this->failNumber) . PHP_EOL, sprintf($this->locale->__('%s error', '%s errors', $this->errorNumber), $this->errorNumber) . PHP_EOL, sprintf($this->locale->__('%s exception', '%s exceptions', $this->exceptionNumber), $this->exceptionNumber) . PHP_EOL ); } return $this->send($title, $message, $success); } public function setAdapter(atoum\adapter $adapter = null) { $this->adapter = $adapter ?: new atoum\adapter(); return $this; } public function getAdapter() { return $this->adapter; } public function send($title, $message, $success) { return $this->adapter->system(sprintf( $this->getCommand(), escapeshellarg($title), escapeshellarg($message), escapeshellarg($success) )); } protected abstract function getCommand(); } testMethodNumber <= 0 ? '' : '1..' . $this->testMethodNumber . PHP_EOL); } public function handleEvent($event, \mageekguy\atoum\observable $observable) { if (parent::handleEvent($event, $observable) === false) { return false; } else { $this->testMethodNumber = $observable->getTestMethodNumber(); return true; } } } setTitlePrompt() ->setClassPrompt() ->setMethodPrompt() ->setTitleColorizer() ->setCoverageColorizer() ; } public function __toString() { $string = ''; if ($this->coverage !== null && sizeof($this->coverage) > 0) { $string .= $this->titlePrompt . sprintf( $this->locale->_('%s: %s'), $this->titleColorizer->colorize($this->locale->_('Code coverage value')), $this->coverageColorizer->colorize(sprintf('%3.2f%%', $this->coverage->getValue() * 100.0)) ) . PHP_EOL ; foreach ($this->coverage->getMethods() as $class => $methods) { $classCoverage = $this->coverage->getValueForClass($class); if ($classCoverage < 1.0) { $string .= $this->classPrompt . sprintf( $this->locale->_('%s: %s'), $this->titleColorizer->colorize(sprintf($this->locale->_('Class %s'), $class)), $this->coverageColorizer->colorize(sprintf('%3.2f%%', $classCoverage * 100.0)) ) . PHP_EOL ; foreach (array_keys($methods) as $method) { $methodCoverage = $this->coverage->getValueForMethod($class, $method); if ($methodCoverage < 1.0) { $string .= $this->methodPrompt . sprintf( $this->locale->_('%s: %s'), $this->titleColorizer->colorize(sprintf($this->locale->_('%s::%s()'), $class, $method)), $this->coverageColorizer->colorize(sprintf('%3.2f%%', $methodCoverage * 100.0)) ) . PHP_EOL ; } } } } } return $string; } public function setTitlePrompt(prompt $prompt = null) { $this->titlePrompt = $prompt ?: new prompt(); return $this; } public function getTitlePrompt() { return $this->titlePrompt; } public function setClassPrompt(prompt $prompt = null) { $this->classPrompt = $prompt ?: new prompt(); return $this; } public function getClassPrompt() { return $this->classPrompt; } public function setMethodPrompt(prompt $prompt = null) { $this->methodPrompt = $prompt ?: new prompt(); return $this; } public function getMethodPrompt() { return $this->methodPrompt; } public function setTitleColorizer(colorizer $colorizer = null) { $this->titleColorizer = $colorizer ?: new colorizer(); return $this; } public function getTitleColorizer() { return $this->titleColorizer; } public function setCoverageColorizer(colorizer $colorizer = null) { $this->coverageColorizer = $colorizer ?: new colorizer(); return $this; } public function getCoverageColorizer() { return $this->coverageColorizer; } } coverage !== null && sizeof($this->coverage) > 0) { $string .= $this->titlePrompt . sprintf( $this->locale->_('%s : %s'), $this->titleColorizer->colorize($this->locale->_('Code coverage value')), $this->coverageColorizer->colorize(sprintf('%3.2f%%', $this->coverage->getValue() * 100.0)) ) . PHP_EOL ; if ($this->showMissingCodeCoverage === true) { foreach ($this->coverage->getMethods() as $class => $methods) { $classCoverage = $this->coverage->getValueForClass($class); if ($classCoverage < 1.0) { $string .= $this->classPrompt . sprintf( $this->locale->_('%s : %s'), $this->titleColorizer->colorize(sprintf($this->locale->_('Class %s'), $class)), $this->coverageColorizer->colorize(sprintf('%3.2f%%', $classCoverage * 100.0)) ) . PHP_EOL ; foreach (array_keys($methods) as $method) { $methodCoverage = $this->coverage->getValueForMethod($class, $method); if ($methodCoverage < 1.0) { $string .= $this->methodPrompt . sprintf( $this->locale->_('%s : %s'), $this->titleColorizer->colorize(sprintf($this->locale->_(' ::%s()'), $method)), $this->coverageColorizer->colorize(sprintf('%3.2f%%', $methodCoverage * 100.0)) ) . PHP_EOL ; } } } } } } return $string; } public function showMissingCodeCoverage() { $this->showMissingCodeCoverage = true; return $this; } public function hideMissingCodeCoverage() { $this->showMissingCodeCoverage = false; return $this; } public function missingCodeCoverageIsShowed() { return $this->showMissingCodeCoverage; } } setPrompt() ->setTitleColorizer() ->setDurationColorizer() ; } public function __toString() { return $this->prompt . sprintf( $this->locale->_('%s: %s.'), $this->titleColorizer->colorize($this->locale->__('Total test duration', 'Total tests duration', $this->testNumber)), $this->durationColorizer->colorize( sprintf( $this->value === null ? $this->locale->_('unknown') : $this->locale->__('%4.2f second', '%4.2f seconds', $this->value), $this->value ) ) ) . PHP_EOL ; } public function setPrompt(prompt $prompt = null) { $this->prompt = $prompt ?: new prompt(); return $this; } public function getPrompt() { return $this->prompt; } public function setTitleColorizer(colorizer $titleColorizer = null) { $this->titleColorizer = $titleColorizer ?: new colorizer(); return $this; } public function getTitleColorizer() { return $this->titleColorizer; } public function setDurationColorizer(colorizer $durationColorizer = null) { $this->durationColorizer = $durationColorizer ?: new colorizer(); return $this; } public function getDurationColorizer() { return $this->durationColorizer; } } setPrompt() ->setTitleColorizer() ->setMemoryColorizer() ; } public function __toString() { $title = $this->locale->__('Total test memory usage', 'Total tests memory usage', $this->testNumber); if ($this->value === null) { $memory = $this->locale->_('unknown'); } else { $memory = sprintf($this->locale->_('%4.2f Mb'), $this->value / 1048576); } return $this->prompt . sprintf($this->locale->_('%s: %s.'), $this->titleColorizer->colorize($title), $this->memoryColorizer->colorize($memory)) . PHP_EOL; } public function setPrompt(prompt $prompt = null) { $this->prompt = $prompt ?: new prompt(); return $this; } public function getPrompt() { return $this->prompt; } public function setTitleColorizer(colorizer $colorizer = null) { $this->titleColorizer = $colorizer ?: new colorizer(); return $this; } public function getTitleColorizer() { return $this->titleColorizer; } public function setMemoryColorizer(colorizer $colorizer = null) { $this->memoryColorizer = $colorizer ?: new colorizer(); return $this; } public function getMemoryColorizer() { return $this->memoryColorizer; } } locale->__('Total test memory usage', 'Total tests memory usage', $this->testNumber); $memory = ($this->value === null ? $this->locale->_('unknown') : sprintf($this->locale->_('%4.2f Mb'), $this->value / 1048576)); return $this->prompt . sprintf($this->locale->_('%s: %s.'), $this->titleColorizer->colorize($title), $this->memoryColorizer->colorize($memory)); } } setTitlePrompt() ->setTitleColorizer() ->setMethodPrompt() ->setMethodColorizer() ->setMessageColorizer() ; } public function __toString() { $string = ''; if ($this->runner !== null) { $skippedMethods = $this->runner->getScore()->getSkippedMethods(); $sizeOfSkippedMethod = sizeof($skippedMethods); if ($sizeOfSkippedMethod > 0) { $string .= $this->titlePrompt . sprintf( $this->locale->_('%s:'), $this->titleColorizer->colorize(sprintf($this->locale->__('There is %d skipped method', 'There are %d skipped methods', $sizeOfSkippedMethod), $sizeOfSkippedMethod)) ) . PHP_EOL ; foreach ($skippedMethods as $skippedMethod) { $string .= $this->methodPrompt . sprintf($this->locale->_('%s: %s'), $this->methodColorizer->colorize(sprintf('%s::%s()', $skippedMethod['class'], $skippedMethod['method'])), $this->messageColorizer->colorize($skippedMethod['message'])) . PHP_EOL; } } } return $string; } public function setTitlePrompt(prompt $prompt = null) { $this->titlePrompt = $prompt ?: new prompt(); return $this; } public function getTitlePrompt() { return $this->titlePrompt; } public function setTitleColorizer(colorizer $colorizer = null) { $this->titleColorizer = $colorizer ?: new colorizer(); return $this; } public function getTitleColorizer() { return $this->titleColorizer; } public function setMethodPrompt(prompt $prompt = null) { $this->methodPrompt = $prompt ?: new prompt(); return $this; } public function getMethodPrompt() { return $this->methodPrompt; } public function setMethodColorizer(colorizer $colorizer = null) { $this->methodColorizer = $colorizer ?: new colorizer(); return $this; } public function getMethodColorizer() { return $this->methodColorizer; } public function setMessageColorizer(colorizer $colorizer = null) { $this->messageColorizer = $colorizer ?: new colorizer(); return $this; } public function getMessageColorizer() { return $this->messageColorizer; } } setTitlePrompt() ->setTitleColorizer() ->setMethodPrompt() ->setMethodColorizer() ->setOutputPrompt() ->setOutputColorizer() ; } public function __toString() { $string = ''; if ($this->runner !== null) { $uncompletedMethods = $this->runner->getScore()->getUncompletedMethods(); $sizeOfUncompletedMethod = sizeof($uncompletedMethods); if ($sizeOfUncompletedMethod > 0) { $string .= $this->titlePrompt . sprintf( $this->locale->_('%s:'), $this->titleColorizer->colorize(sprintf($this->locale->__('There is %d uncompleted method', 'There are %d uncompleted methods', $sizeOfUncompletedMethod), $sizeOfUncompletedMethod)) ) . PHP_EOL ; foreach ($uncompletedMethods as $uncompletedMethod) { $string .= $this->methodPrompt . sprintf( $this->locale->_('%s:'), $this->methodColorizer->colorize(sprintf('%s::%s() with exit code %d', $uncompletedMethod['class'], $uncompletedMethod['method'], $uncompletedMethod['exitCode'])) ) . PHP_EOL ; $lines = explode(PHP_EOL, trim($uncompletedMethod['output'])); $string .= $this->outputPrompt . 'output(' . strlen($uncompletedMethod['output']) . ') "' . array_shift($lines); foreach ($lines as $line) { $string .= PHP_EOL . $this->outputPrompt . $line; } $string .= '"' . PHP_EOL; } } } return $string; } public function setTitlePrompt(prompt $prompt = null) { $this->titlePrompt = $prompt ?: new prompt(); return $this; } public function getTitlePrompt() { return $this->titlePrompt; } public function setTitleColorizer(colorizer $colorizer = null) { $this->titleColorizer = $colorizer ?: new colorizer(); return $this; } public function getTitleColorizer() { return $this->titleColorizer; } public function setMethodPrompt(prompt $prompt = null) { $this->methodPrompt = $prompt ?: new prompt(); return $this; } public function getMethodPrompt() { return $this->methodPrompt; } public function setMethodColorizer(colorizer $colorizer = null) { $this->methodColorizer = $colorizer ?: new colorizer(); return $this; } public function getMethodColorizer() { return $this->methodColorizer; } public function setOutputPrompt(prompt $prompt = null) { $this->outputPrompt = $prompt ?: new prompt(); return $this; } public function getOutputPrompt() { return $this->outputPrompt; } public function setOutputColorizer(colorizer $colorizer = null) { $this->outputColorizer = $colorizer ?: new colorizer(); return $this; } public function getOutputColorizer() { return $this->outputColorizer; } } setTitlePrompt() ->setTitleColorizer() ->setMethodPrompt() ->setMethodColorizer() ; } public function __toString() { $string = ''; if ($this->runner !== null) { $voidMethods = $this->runner->getScore()->getVoidMethods(); $sizeOfVoidMethod = sizeof($voidMethods); if ($sizeOfVoidMethod > 0) { $string .= $this->titlePrompt . sprintf( $this->locale->_('%s:'), $this->titleColorizer->colorize(sprintf($this->locale->__('There is %d void method', 'There are %d void methods', $sizeOfVoidMethod), $sizeOfVoidMethod)) ) . PHP_EOL ; foreach ($voidMethods as $voidMethod) { $string .= $this->methodPrompt . $this->methodColorizer->colorize(sprintf('%s::%s()', $voidMethod['class'], $voidMethod['method'])) . PHP_EOL; } } } return $string; } public function setTitlePrompt(prompt $prompt = null) { $this->titlePrompt = $prompt ?: new prompt(); return $this; } public function getTitlePrompt() { return $this->titlePrompt; } public function setTitleColorizer(colorizer $colorizer = null) { $this->titleColorizer = $colorizer ?: new colorizer(); return $this; } public function getTitleColorizer() { return $this->titleColorizer; } public function setMethodPrompt(prompt $prompt = null) { $this->methodPrompt = $prompt ?: new prompt(); return $this; } public function getMethodPrompt() { return $this->methodPrompt; } public function setMethodColorizer(colorizer $colorizer = null) { $this->methodColorizer = $colorizer ?: new colorizer(); return $this; } public function getMethodColorizer() { return $this->methodColorizer; } } coverage; } public function handleEvent($event, atoum\observable $observable) { if (parent::handleEvent($event, $observable) === false) { return false; } else { $this->coverage = $observable->getScore()->getCoverage(); return true; } } } value; } public function getTestNumber() { return $this->testNumber; } public function handleEvent($event, atoum\observable $observable) { if (parent::handleEvent($event, $observable) === false) { return false; } else { $this->value = $observable->getScore()->getTotalDuration(); $this->testNumber = $observable->getTestNumber(); return true; } } } value; } public function getTestNumber() { return $this->testNumber; } public function handleEvent($event, atoum\observable $observable) { if (parent::handleEvent($event, $observable) === false) { return false; } else { $this->value = $observable->getScore()->getTotalMemoryUsage(); $this->testNumber = $observable->getTestNumber(); return true; } } } runner; } public function handleEvent($event, observable $observable) { if (parent::handleEvent($event, $observable) === false) { return false; } else { $this->runner = $observable; return true; } } } runner; } public function handleEvent($event, observable $observable) { if (parent::handleEvent($event, $observable) === false) { return false; } else { $this->runner = $observable; return true; } } } runner; } public function handleEvent($event, observable $observable) { if (parent::handleEvent($event, $observable) === false) { return false; } else { $this->runner = $observable; return true; } } } author; } public function getVersion() { return $this->version; } public function getPath() { return $this->path; } public function handleEvent($event, \mageekguy\atoum\observable $observable) { if (parent::handleEvent($event, $observable) === false) { return false; } else { $this->author = \mageekguy\atoum\author; $this->path = $observable->getScore()->getAtoumPath(); $this->version = $observable->getScore()->getAtoumVersion(); return true; } } } coverage; } public function handleEvent($event, \mageekguy\atoum\observable $observable) { if (parent::handleEvent($event, $observable) === false) { return false; } else { $this->coverage = $observable->getScore()->getCoverage(); return true; } } } value; } public function handleEvent($event, observable $observable) { if (parent::handleEvent($event, $observable) === false) { return false; } else { $this->value = $observable->getRunningDuration(); return true; } } } runner; } public function handleEvent($event, observable $observable) { if (parent::handleEvent($event, $observable) === false) { return false; } else { $this->runner = $observable; return true; } } public static function getType($error) { switch ($error) { case E_ERROR: return 'E_ERROR'; case E_WARNING: return 'E_WARNING'; case E_NOTICE: return 'E_NOTICE'; case E_USER_NOTICE: return 'E_USER_NOTICE'; case E_USER_WARNING: return 'E_USER_WARNING'; case E_USER_ERROR: return 'E_USER_ERROR'; case E_RECOVERABLE_ERROR: return 'E_RECOVERABLE_ERROR'; case E_DEPRECATED: return 'E_DEPRECATED'; case E_USER_DEPRECATED: return 'E_USER_DEPRECATED'; default: return strtoupper($error); } } } runner; } public function handleEvent($event, observable $observable) { if (parent::handleEvent($event, $observable) === false) { return false; } else { $this->runner = $observable; return true; } } } runner; } public function handleEvent($event, observable $observable) { if (parent::handleEvent($event, $observable) === false) { return false; } else { $this->runner = $observable; return true; } } } runner; } public function handleEvent($event, observable $observable) { if (parent::handleEvent($event, $observable) === false) { return false; } else { $this->runner = $observable; return true; } } } testNumber; } public function getTestMethodNumber() { return $this->testMethodNumber; } public function getAssertionNumber() { return $this->assertionNumber; } public function getFailNumber() { return $this->failNumber; } public function getErrorNumber() { return $this->errorNumber; } public function getExceptionNumber() { return $this->exceptionNumber; } public function getVoidMethodNumber() { return $this->voidMethodNumber; } public function getUncompletedMethodNumber() { return $this->uncompletedMethodNumber; } public function getSkippedMethodNumber() { return $this->skippedMethodNumber; } public function handleEvent($event, observable $observable) { if (parent::handleEvent($event, $observable) === false) { return false; } else { $score = $observable->getScore(); $this->testNumber = $observable->getTestNumber(); $this->testMethodNumber = $observable->getTestMethodNumber(); $this->assertionNumber = $score->getAssertionNumber(); $this->failNumber = $score->getFailNumber(); $this->errorNumber = $score->getErrorNumber(); $this->exceptionNumber = $score->getExceptionNumber(); $this->voidMethodNumber = $score->getVoidMethodNumber(); $this->uncompletedMethodNumber = $score->getUncompletedMethodNumber(); $this->skippedMethodNumber = $score->getSkippedMethodNumber(); return true; } } } setPrompt() ->setTitleColorizer() ->setDurationColorizer() ; } public function __toString() { return $this->prompt . sprintf( $this->locale->_('%1$s: %2$s.'), $this->titleColorizer->colorize($this->locale->_('Test duration')), $this->durationColorizer->colorize( $this->value === null ? $this->locale->_('unknown') : sprintf( $this->locale->__('%4.2f second', '%4.2f seconds', $this->value), $this->value ) ) ) . PHP_EOL ; } public function setPrompt(prompt $prompt = null) { $this->prompt = $prompt ?: new prompt(); return $this; } public function getPrompt() { return $this->prompt; } public function setTitleColorizer(colorizer $colorizer = null) { $this->titleColorizer = $colorizer ?: new colorizer(); return $this; } public function getTitleColorizer() { return $this->titleColorizer; } public function setDurationColorizer(colorizer $colorizer = null) { $this->durationColorizer = $colorizer ?: new colorizer(); return $this; } public function getDurationColorizer() { return $this->durationColorizer; } } prompt . sprintf( $this->locale->_('%1$s'), $this->durationColorizer->colorize($this->value === null ? $this->locale->_('unknown') : sprintf($this->locale->__('%4.2f s', '%4.2f s', $this->value), $this->value)) ) ; } } setProgressBar(); } public function __toString() { $string = ''; if ($this->observable !== null) { switch ($this->event) { case test::runStop: case test::runtimeException: $string = PHP_EOL; break; default: switch ($this->event) { case test::runStart: $this->progressBar->reset()->setIterations(sizeof($this->observable)); break; case test::success: $this->progressBar->refresh('S'); break; case test::fail: $this->progressBar->refresh('F'); break; case test::error: $this->progressBar->refresh('E'); break; case test::exception: $this->progressBar->refresh('X'); break; case test::void: $this->progressBar->refresh('0'); break; case test::uncompleted: $this->progressBar->refresh('U'); break; case test::skipped: $this->progressBar->refresh('-'); break; case test::runStop: $this->progressBar->reset(); break; } $string = (string) $this->progressBar; } } return $string; } public function setProgressBar(progressBar $progressBar = null) { $this->progressBar = $progressBar ?: new progressBar(); return $this; } public function getProgressBar() { return $this->progressBar; } } event) { case atoum\test::runStart: return '['; case atoum\test::runStop: return '] '; case atoum\test::success: return 'S'; case atoum\test::void: return '0'; case atoum\test::uncompleted: return 'U'; case atoum\test::fail: return 'F'; case atoum\test::error: return 'e'; case atoum\test::exception: return 'E'; default: return ''; } } } testLine; } public function handleEvent($event, atoum\observable $observable) { $eventHandled = parent::handleEvent($event, $observable); if ($eventHandled === true) { switch ($this->event) { case runner::runStart: $this->testPoint = 0; $this->testLine = ''; break; case test::success: $this->testLine = 'ok ' . ++$this->testPoint . PHP_EOL; $this->testLine .= '# ' . $observable->getClass() . '::' . $observable->getCurrentMethod() . '()' . PHP_EOL; break; case test::error: $lastError = $observable->getScore()->getLastErroredMethod(); $this->testLine = 'not ok ' . ++$this->testPoint . ' - ' . trim($lastError['class']) . '::' . trim($lastError['method']) . '()' . PHP_EOL . '# ' . str_replace(PHP_EOL, PHP_EOL . '# ', trim($lastError['message'])) . PHP_EOL; $this->testLine .= '# ' . (isset($lastError['errorFile']) ? $lastError['errorFile'] : $lastError['file']) . ':' . (isset($lastError['errorLine']) ? $lastError['errorLine'] : $lastError['line']) . PHP_EOL; break; case test::fail: $lastFailAssertion = $observable->getScore()->getLastFailAssertion(); $this->testLine = 'not ok ' . ++$this->testPoint . ' - ' . trim($lastFailAssertion['class']) . '::' . trim($lastFailAssertion['method']) . '()' . PHP_EOL . '# ' . str_replace(PHP_EOL, PHP_EOL . '# ', trim($lastFailAssertion['fail'])) . PHP_EOL; $this->testLine .= '# ' . $lastFailAssertion['file'] . ':' . $lastFailAssertion['line'] . PHP_EOL; break; case test::void: $lastVoidMethod = $observable->getScore()->getLastVoidMethod(); $this->testLine = 'not ok ' . ++$this->testPoint . ' # TODO ' . trim($lastVoidMethod['class']) . '::' . trim($lastVoidMethod['method']) . '()' . PHP_EOL; $this->testLine .= '# ' . $lastVoidMethod['file'] . PHP_EOL; break; case test::uncompleted: $lastUncompleteMethod = $observable->getScore()->getLastUncompleteMethod(); $this->testLine = 'not ok ' . ++$this->testPoint . ' - ' . trim($lastUncompleteMethod['class']) . '::' . trim($lastUncompleteMethod['method']) . '()' . PHP_EOL . '# ' . str_replace(PHP_EOL, PHP_EOL . '# ', trim($lastUncompleteMethod['output'])) . PHP_EOL; break; case test::skipped: $lastSkippedMethod = $observable->getScore()->getLastSkippedMethod(); $this->testLine = 'ok ' . ++$this->testPoint . ' # SKIP ' . trim($lastSkippedMethod['class']) . '::' . trim($lastSkippedMethod['method']) . '()' . PHP_EOL . '# ' . str_replace(PHP_EOL, PHP_EOL . '# ', trim($lastSkippedMethod['message'])) . PHP_EOL; break; case test::exception: $lastException = $observable->getScore()->getLastException(); $this->testLine = 'not ok ' . ++$this->testPoint . ' - ' . trim($lastException['class']) . '::' . trim($lastException['method']) . '()' . PHP_EOL . '# ' . str_replace(PHP_EOL, PHP_EOL . '# ', trim($lastException['value'])) . PHP_EOL; $this->testLine .= '# ' . $lastException['file'] . ':' . $lastException['line'] . PHP_EOL; break; case test::runtimeException: $lastRuntimeException = $observable->getScore()->getLastRuntimeException(); $this->testLine = 'Bail out!' . ($lastRuntimeException->getMessage() ? ' ' . trim($lastRuntimeException->getMessage()) : '') . PHP_EOL; break; } } return $eventHandled; } } setPrompt() ->setTitleColorizer() ->setMemoryColorizer() ; } public function __toString() { return $this->prompt . sprintf( $this->locale->_('%1$s: %2$s.'), $this->titleColorizer->colorize($this->locale->_('Memory usage')), $this->memoryColorizer->colorize( $this->value === null ? $this->locale->_('unknown') : sprintf( $this->locale->_('%4.2f Mb'), $this->value / 1048576 ) ) ) . PHP_EOL ; } public function setPrompt(prompt $prompt = null) { $this->prompt = $prompt ?: new prompt(); return $this; } public function getPrompt() { return $this->prompt; } public function setTitleColorizer(colorizer $colorizer = null) { $this->titleColorizer = $colorizer ?: new colorizer(); return $this; } public function getTitleColorizer() { return $this->titleColorizer; } public function setMemoryColorizer(colorizer $colorizer = null) { $this->memoryColorizer = $colorizer ?: new colorizer(); return $this; } public function getMemoryColorizer() { return $this->memoryColorizer; } } prompt . sprintf( $this->locale->_('%1$s'), $this->memoryColorizer->colorize($this->value === null ? $this->locale->_('unknown') : sprintf($this->locale->_('%4.2f Mb'), $this->value / 1048576)) ) ; } } setPrompt() ->setColorizer() ; } public function __toString() { return $this->prompt . ( $this->testClass === null ? $this->colorizer->colorize($this->locale->_('There is currently no test running.')) : sprintf($this->locale->_('%s...'), $this->colorizer->colorize($this->testClass)) ) . PHP_EOL ; } public function setPrompt(prompt $prompt = null) { $this->prompt = $prompt ?: new prompt(); return $this; } public function getPrompt() { return $this->prompt; } public function setColorizer(colorizer $colorizer = null) { $this->colorizer = $colorizer ?: new colorizer(); return $this; } public function getColorizer() { return $this->colorizer; } } prompt . ($this->testClass === null ? $this->colorizer->colorize($this->locale->_('There is currently no test running.')) : sprintf($this->locale->_('%s : '), $this->colorizer->colorize($this->testClass))); } } value; } public function handleEvent($event, observable $observable) { if (parent::handleEvent($event, $observable) === false) { return false; } else { $this->value = $observable->getScore()->getTotalDuration(); return true; } } } value; } public function handleEvent($event, atoum\observable $observable) { if (parent::handleEvent($event, $observable) === false) { return false; } else { $this->value = $observable->getScore()->getTotalMemoryUsage(); return true; } } } testClass; } public function handleEvent($event, atoum\observable $observable) { if (parent::handleEvent($event, $observable) === false) { return false; } else { $this->testClass = $observable->getClass(); return true; } } } observable; } public function getEvent() { return $this->event; } public function handleEvent($event, atoum\observable $observable) { if (parent::handleEvent($event, $observable) === false) { $this->observable = null; $this->event = null; return false; } else { $this->observable = $observable; $this->event = $event; return true; } } } events = $events; $this->setLocale(); } public function setLocale(atoum\locale $locale = null) { $this->locale = $locale ?: new atoum\locale(); return $this; } public function getLocale() { return $this->locale; } public function getEvents() { return $this->events; } public function canHandleEvent($event) { return ($this->events === null ? true : in_array($event, $this->events)); } public function handleEvent($event, atoum\observable $observable) { return $this->canHandleEvent($event); } abstract public function __toString(); } addField(new runner\php\path\cli()); $phpVersionField = new runner\php\version\cli(); $phpVersionField->setVersionPrompt($secondLevelPrompt); $this->addField($phpVersionField); $this ->addField(new runner\duration\cli()) ->addField(new runner\result\cli()) ; $failuresField = new runner\failures\cli(); $failuresField->setMethodPrompt($secondLevelPrompt); $this->addField($failuresField); $outputsField = new runner\outputs\cli(); $outputsField->setMethodPrompt($secondLevelPrompt); $this->addField($outputsField); $errorsField = new runner\errors\cli(); $errorsField ->setMethodPrompt($secondLevelPrompt) ->setErrorPrompt($thirdLevelPrompt) ; $this->addField($errorsField); $exceptionsField = new runner\exceptions\cli(); $exceptionsField ->setMethodPrompt($secondLevelPrompt) ->setExceptionPrompt($thirdLevelPrompt) ; $this->addField($exceptionsField); $uncompletedField = new runner\tests\uncompleted\cli(); $uncompletedField ->setMethodPrompt($secondLevelPrompt) ->setOutputPrompt($thirdLevelPrompt) ; $this->addField($uncompletedField); $this ->addField(new runner\tests\duration\cli()) ->addField(new runner\tests\memory\cli()) ; $coverageField = new runner\tests\coverage\cli(); $coverageField ->setClassPrompt($secondLevelPrompt) ->setMethodPrompt($thirdLevelPrompt) ; $this ->addField($coverageField) ->addField(new test\run\cli()) ; $durationField = new test\duration\cli(); $durationField->setPrompt($secondLevelPrompt); $this->addField($durationField); $memoryField = new test\memory\cli(); $memoryField->setPrompt($secondLevelPrompt); $this->addField($memoryField); } } setAdapter($adapter); if ($this->adapter->extension_loaded('libxml') === false) { throw new exceptions\runtime('libxml PHP extension is mandatory for clover report'); } } public function getTitle() { return ($this->title ?: self::defaultTitle); } public function getPackage() { return ($this->package ?: self::defaultPackage); } public function setPackage($package) { $this->package = (string) $package; return $this; } public function handleEvent($event, atoum\observable $observable) { $this->score = ($event !== atoum\runner::runStop ? null : $observable->getScore()); return parent::handleEvent($event, $observable); } public function build($event) { if ($event === atoum\runner::runStop) { $document = new \DOMDocument('1.0', 'UTF-8'); $document->formatOutput = true; $document->appendChild($this->makeRootElement($document, $this->score->getCoverage())); $this->string = $document->saveXML(); } return $this; } protected function makeRootElement(\DOMDocument $document, score\coverage $coverage) { $root = $document->createElement('coverage'); $root->setAttribute('generated', $this->getAdapter()->time()); $root->setAttribute('clover', $this->getAdapter()->uniqid()); $root->appendChild($this->makeProjectElement($document, $coverage)); return $root; } protected function makeProjectElement(\DOMDocument $document, score\coverage $coverage) { $project = $document->createElement('project'); $project->setAttribute('timestamp', $this->getAdapter()->time()); $project->setAttribute('name', $this->getTitle()); $project->appendChild($this->makePackageElement($document, $coverage)); $project->appendChild($this->makeProjectMetricsElement($document, sizeof($coverage->getClasses()))); return $project; } protected function makeProjectMetricsElement(\DOMDocument $document, $files) { $metrics = $this->makePackageMetricsElement($document, $files); $metrics->setAttribute('packages', 1); return $metrics; } protected function makePackageElement(\DOMDocument $document, score\coverage $coverage) { $package = $document->createElement('package'); $package->setAttribute('name', $this->getPackage()); foreach ($coverage->getClasses() as $class => $file) { $package->appendChild($this->makeFileElement($document, $file, $class, $coverage->getCoverageForClass($class))); } $package->appendChild($this->makePackageMetricsElement($document, sizeof($coverage->getClasses()))); return $package; } protected function makePackageMetricsElement(\DOMDocument $document, $files) { $metrics = $this->makeFileMetricsElement($document, $this->loc, $this->coveredLoc, $this->methods, $this->coveredMethods, $files); $metrics->setAttribute('files', $files); return $metrics; } protected function makeFileElement(\DOMDocument $document, $filename, $class, array $coverage) { $file = $document->createElement('file'); $file->setAttribute('name', basename($filename)); $file->setAttribute('path', $filename); $methods = count($coverage); $coveredMethods = 0; $totalLines = 0; $coveredLines = 0; foreach ($coverage as $lines) { if (sizeof($lines) > 0) { foreach ($lines as $lineNumber => $cover) { if ($cover >= -1) { $totalLines++; } if ($cover === 1) { $coveredLines++; $file->appendChild($this->makeLineElement($document, $lineNumber)); } else { $file->appendChild($this->makeLineElement($document, $lineNumber, 0)); } } if ($coveredLines === $totalLines) { ++$coveredMethods; } } } $this ->addLoc($totalLines) ->addCoveredLoc($coveredLines) ->addMethod($methods) ->addCoveredMethod($coveredMethods) ->addClasses(1) ; $file->appendChild($this->makeClassElement($document, $class, $coverage)); $file->appendChild($this->makeFileMetricsElement($document, $totalLines, $coveredLines, $methods, $coveredMethods, 1)); return $file; } protected function makeFileMetricsElement(\DOMDocument $document, $loc, $cloc, $methods, $coveredMethods, $classes) { $metrics = $this->makeClassMetricsElement($document, $loc, $cloc, $methods, $coveredMethods); $metrics->setAttribute('classes', $classes); $metrics->setAttribute('loc', $loc); $metrics->setAttribute('ncloc', $loc); return $metrics; } protected function makeClassElement(\DOMDocument $document, $classname, array $coverage) { $class = $document->createElement('class'); $class->setAttribute('name', basename(str_replace('\\', DIRECTORY_SEPARATOR, $classname))); $methods = count($coverage); $coveredMethods = 0; $totalLines = 0; $coveredLines = 0; foreach ($coverage as $lines) { if (sizeof($lines) > 0) { ++$coveredMethods; } foreach ($lines as $cover) { if ($cover >= -1) { $totalLines++; } if ($cover === 1) { $coveredLines++; } } } $class->appendChild($this->makeClassMetricsElement($document, $totalLines, $coveredLines, $methods, $coveredMethods)); return $class; } protected function makeClassMetricsElement(\DOMDocument $document, $loc, $cloc, $methods, $cmethods) { $metrics = $document->createElement('metrics'); $metrics->setAttribute('complexity', 0); $metrics->setAttribute('elements', $loc); $metrics->setAttribute('coveredelements', $cloc); $metrics->setAttribute('conditionals', 0); $metrics->setAttribute('coveredconditionals', 0); $metrics->setAttribute('statements', $loc); $metrics->setAttribute('coveredstatements', $cloc); $metrics->setAttribute('methods', $methods); $metrics->setAttribute('coveredmethods', $cmethods); $metrics->setAttribute('testduration', 0); $metrics->setAttribute('testfailures', 0); $metrics->setAttribute('testpasses', 0); $metrics->setAttribute('testruns', 0); return $metrics; } protected function makeLineElement(\DOMDocument $document, $linenum, $count = 1) { $line = $document->createElement('line'); $line->setAttribute('num', $linenum); $line->setAttribute('type', self::lineTypeStatement); $line->setAttribute('complexity', 0); $line->setAttribute('count', $count); $line->setAttribute('falsecount', 0); $line->setAttribute('truecount', 0); $line->setAttribute('signature', ''); $line->setAttribute('testduration', 0); $line->setAttribute('testsuccess', 0); return $line; } protected function addLoc($count) { $this->loc += $count; return $this; } protected function addCoveredLoc($count) { $this->coveredLoc += $count; return $this; } protected function addMethod($count) { $this->methods += $count; return $this; } protected function addCoveredMethod($count) { $this->coveredMethods += $count; return $this; } protected function addClasses($count) { $this->classes += $count; return $this; } } '); $secondLevelPrompt = new prompt('=> '); $thirdLevelPrompt = new prompt('==> '); $phpPathField = new runner\php\path\cli(); $phpPathField->setPrompt($firstLevelPrompt); $this->addField($phpPathField); $phpVersionField = new runner\php\version\cli(); $phpVersionField ->setTitlePrompt($firstLevelPrompt) ->setVersionPrompt($secondLevelPrompt) ; $this->addField($phpVersionField); $testsDurationField = new runner\tests\duration\cli(); $testsDurationField->setPrompt($firstLevelPrompt); $this->addField($testsDurationField); $memoryField = new runner\tests\memory\cli(); $memoryField->setPrompt($firstLevelPrompt); $this->addField($memoryField); $coverageField = new runner\tests\coverage\cli(); $coverageField ->setTitlePrompt($firstLevelPrompt) ->setClassPrompt($secondLevelPrompt) ->setMethodPrompt($thirdLevelPrompt) ; $runnerDurationField = new runner\duration\cli(); $runnerDurationField->setPrompt($firstLevelPrompt); $this->addField($runnerDurationField); $resultField = new runner\result\cli(); $this->addField($resultField); $failuresField = new runner\failures\cli(); $failuresField ->setTitlePrompt($firstLevelPrompt) ->setMethodPrompt($secondLevelPrompt) ; $this->addfield($failuresField); $errorsField = new runner\errors\cli(); $errorsField ->setTitlePrompt($firstLevelPrompt) ->setMethodPrompt($secondLevelPrompt) ->setErrorPrompt($thirdLevelPrompt) ; $this->addField($errorsField); $exceptionsField = new runner\exceptions\cli(); $exceptionsField ->setTitlePrompt($firstLevelPrompt) ->setMethodPrompt($secondLevelPrompt) ->setExceptionPrompt($thirdLevelPrompt) ; $this->addField($exceptionsField); $uncompletedField = new runner\tests\uncompleted\cli(); $uncompletedField ->setTitlePrompt($firstLevelPrompt) ->setMethodPrompt($secondLevelPrompt) ->setOutputPrompt($thirdLevelPrompt) ; $this->addField($uncompletedField); $voidField = new runner\tests\void\cli(); $voidField ->setTitlePrompt($firstLevelPrompt) ->setMethodPrompt($secondLevelPrompt) ; $this->addField($voidField); $skippedField = new runner\tests\skipped\cli(); $skippedField ->setTitlePrompt($firstLevelPrompt) ->setMethodPrompt($secondLevelPrompt) ; $this->addField($skippedField); $outputField = new runner\outputs\cli(); $outputField ->setTitlePrompt($firstLevelPrompt) ->setMethodPrompt($secondLevelPrompt) ; $this->addField($outputField); $testRunField = new test\run\cli(); $testRunField->setPrompt($firstLevelPrompt); $this->addField($testRunField); $testDurationField = new test\duration\cli(); $testDurationField->setPrompt($secondLevelPrompt); $this->addField($testDurationField); $testMemoryField = new test\memory\cli(); $testMemoryField->setPrompt($secondLevelPrompt); $this->addField($testMemoryField); } } setAdapter($adapter); if ($this->adapter->extension_loaded('libxml') === false) { throw new exceptions\runtime('libxml PHP extension is mandatory for xunit report'); } } public function handleEvent($event, atoum\observable $observable) { $this->score = ($event !== atoum\runner::runStop) ? null : $observable->getScore(); return parent::handleEvent($event, $observable); } protected function getTestedClasses() { $durations = $this->score->getDurations(); $errors = $this->score->getErrors(); $excepts = $this->score->getExceptions(); $fails = $this->score->getFailAssertions(); $uncomplete = $this->score->getUncompletedMethods(); $skipped = $this->score->getSkippedMethods(); $filterClass = function ($element) use (& $clname) { return ($element['class'] == $clname); }; $extractClasses = function($list) use (& $clname, & $classes, $durations, $errors, $excepts, $fails, $uncomplete, $skipped, $filterClass) { foreach ($list as $entry) { $clname = $entry['class']; if (isset($classes[$clname]) === false) { $classes[$clname] = array( 'errors' => array_filter($errors, $filterClass), 'excepts' => array_filter($excepts, $filterClass), 'fails' => array_filter($fails, $filterClass), 'durations' => array_filter($durations, $filterClass), 'uncomplete' => array_filter($uncomplete, $filterClass), 'skipped' => array_filter($skipped, $filterClass), ); } } }; $classes = array(); $extractClasses($durations); $extractClasses($errors); $extractClasses($excepts); $extractClasses($fails); $extractClasses($uncomplete); $extractClasses($skipped); return $classes; } public function build($event) { $this->string = ''; if ($event === atoum\runner::runStop) { $this->title = $this->title ?: self::defaultTitle; $document = new \DOMDocument('1.0', 'UTF-8'); $document->formatOutput = true; $document->appendChild($root = $document->createElement('testsuites')); $root->setAttribute('name', $this->title); $classes = $this->getTestedClasses(); foreach ($classes as $name => $class) { $testCase = null; $clname = $package = $name; $antiSlashOffset = strrpos($clname, '\\'); if ($antiSlashOffset !== false) { $clname = substr($clname, $antiSlashOffset + 1); $package = substr($name, 0, $antiSlashOffset); } $root->appendChild($testSuite = $document->createElement('testsuite')); $testSuite->setAttribute('name', $clname); $testSuite->setAttribute('package', $package); $testSuite->setAttribute('tests', sizeof($class['durations']) + ($fails = sizeof($class['fails'])) + ($errors = sizeof($class['excepts']) + sizeof($class['errors']) + sizeof($class['uncomplete'])) + sizeof($class['skipped'])); $testSuite->setAttribute('failures', $fails); $testSuite->setAttribute('errors', $errors); $testSuite->setAttribute('skipped', sizeof($class['skipped'])); $time = 0; foreach ($class['durations'] as $duration) { $time += $duration['value']; static::getTestCase($document, $testSuite, $name, $duration['method'], $duration['value'], $duration['path']); } $testSuite->setAttribute('time', $time); foreach ($class['errors'] as $error) { $testCase = static::getTestCase($document, $testSuite, $name, $error['method'], 0, $error['file']); $testCase->appendChild($xError = $document->createElement('error')); $xError->setAttribute('type', $error['type']); $xError->appendChild($document->createCDATASection($error['message'])); } foreach ($class['uncomplete'] as $uncomplete) { $testCase = static::getTestCase($document, $testSuite, $name, $uncomplete['method'], 0, null); $testCase->appendChild($xFail = $document->createElement('error')); $xFail->setAttribute('type', $uncomplete['exitCode']); $xFail->appendChild($document->createCDATASection($uncomplete['output'])); } foreach ($class['fails'] as $fail) { $testCase = static::getTestCase($document, $testSuite, $name, $fail['method'], 0, $fail['file']); $testCase->appendChild($xFail = $document->createElement('failure')); $xFail->setAttribute('type', 'Failure'); $xFail->setAttribute('message', $fail['asserter']); $xFail->appendChild($document->createCDATASection($fail['fail'])); } foreach ($class['excepts'] as $exc) { $testCase = static::getTestCase($document, $testSuite, $name, $exc['method'], 0, $exc['file']); $testCase->appendChild($xError = $document->createElement('error')); $xError->setAttribute('type', 'Exception'); $xError->appendChild($document->createCDATASection($exc['value'])); } foreach ($class['skipped'] as $skipped) { $testCase = static::getTestCase($document, $testSuite, $name, $skipped['method'], 0, null); $testCase->appendChild($xFail = $document->createElement('skipped')); $xFail->setAttribute('type', 'Skipped'); $xFail->appendChild($document->createCDATASection($skipped['message'])); } } $this->string = $document->saveXML(); } return $this; } private static function getTestCase(\DOMDocument $document, \DOMElement $testSuite, $class, $method, $time, $path) { if (($testCase = static::findTestCase($document, $class, $method)) === null) { $testCase = $document->createElement('testcase'); $testCase->setAttribute('name', $method); $testCase->setIdAttribute('name', true); $testCase->setAttribute('time', $time); $testCase->setAttribute('file', $path); $testCase->setAttribute('classname', $class); $testSuite->appendChild($testCase); } return $testCase; } private static function findTestCase(\DOMDocument $document, $class, $method) { $xpath = new \DOMXPath($document); $query = $xpath->query("//testcase[@classname='$class' and @name='$method']"); if ($query->length > 0) { return $query->item(0); } return null; } } '); $secondLevelPrompt = new prompt('=> ', $firstLevelColorizer); $thirdLevelPrompt = new prompt('==> ', $firstLevelColorizer); $this->addField(new runner\event\cli()); $resultField = new runner\result\cli(); $resultField ->setSuccessColorizer(new colorizer('0;37', '42')) ->setFailureColorizer(new colorizer('0;37', '41')) ; $this->addField($resultField); $failureColorizer = new colorizer('0;31'); $failurePrompt = clone $secondLevelPrompt; $failurePrompt->setColorizer($failureColorizer); $failuresField = new runner\failures\cli(); $failuresField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($firstLevelColorizer) ->setMethodPrompt($secondLevelPrompt) ; $this->addField($failuresField); $outputsField = new runner\outputs\cli(); $outputsField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($firstLevelColorizer) ->setMethodPrompt($secondLevelPrompt) ; $this->addField($outputsField); $errorColorizer = new colorizer('0;33'); $errorMethodPrompt = clone $secondLevelPrompt; $errorMethodPrompt->setColorizer($errorColorizer); $errorPrompt = clone $thirdLevelPrompt; $errorPrompt->setColorizer($errorColorizer); $errorsField = new runner\errors\cli(); $errorsField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($errorColorizer) ->setMethodPrompt($errorMethodPrompt) ->setErrorPrompt($errorPrompt) ; $this->addField($errorsField); $exceptionColorizer = new colorizer('0;35'); $exceptionMethodPrompt = clone $secondLevelPrompt; $exceptionMethodPrompt->setColorizer($exceptionColorizer); $exceptionPrompt = clone $thirdLevelPrompt; $exceptionPrompt->setColorizer($exceptionColorizer); $exceptionsField = new runner\exceptions\cli(); $exceptionsField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($exceptionColorizer) ->setMethodPrompt($exceptionMethodPrompt) ->setExceptionPrompt($exceptionPrompt) ; $this->addField($exceptionsField); $uncompletedTestColorizer = new colorizer('0;37'); $uncompletedTestMethodPrompt = clone $secondLevelPrompt; $uncompletedTestMethodPrompt->setColorizer($uncompletedTestColorizer); $uncompletedTestOutputPrompt = clone $thirdLevelPrompt; $uncompletedTestOutputPrompt->setColorizer($uncompletedTestColorizer); $uncompletedTestField = new runner\tests\uncompleted\cli(); $uncompletedTestField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($uncompletedTestColorizer) ->setMethodPrompt($uncompletedTestMethodPrompt) ->setOutputPrompt($uncompletedTestOutputPrompt) ; $this->addField($uncompletedTestField); $voidTestColorizer = new colorizer('0;34'); $voidTestMethodPrompt = clone $secondLevelPrompt; $voidTestMethodPrompt->setColorizer($voidTestColorizer); $voidTestOutputPrompt = clone $thirdLevelPrompt; $voidTestOutputPrompt->setColorizer($voidTestColorizer); $voidTestField = new runner\tests\void\cli(); $voidTestField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($voidTestColorizer) ->setMethodPrompt($voidTestMethodPrompt) ; $this->addField($voidTestField); $skippedTestColorizer = new colorizer('0;90'); $skippedTestMethodPrompt = clone $secondLevelPrompt; $skippedTestMethodPrompt->setColorizer($skippedTestColorizer); $skippedTestField = new runner\tests\skipped\cli(); $skippedTestField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($skippedTestColorizer) ->setMethodPrompt($skippedTestMethodPrompt) ; $this->addField($skippedTestField); } } '); $secondLevelPrompt = new prompt('=> ', $defaultColorizer); $thirdLevelPrompt = new prompt('==> ', $defaultColorizer); $phpPathField = new runner\php\path\cli(); $phpPathField ->setPrompt($firstLevelPrompt) ->setTitleColorizer($defaultColorizer) ; $this->addField($phpPathField); $phpVersionField = new runner\php\version\cli(); $phpVersionField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($defaultColorizer) ->setVersionPrompt($secondLevelPrompt) ; $this->addField($phpVersionField); $runnerTestsDurationField = new runner\tests\duration\cli(); $runnerTestsDurationField ->setPrompt($firstLevelPrompt) ->setTitleColorizer($defaultColorizer) ; $this->addField($runnerTestsDurationField); $runnerTestsMemoryField = new runner\tests\memory\cli(); $runnerTestsMemoryField ->setPrompt($firstLevelPrompt) ->setTitleColorizer($defaultColorizer) ; $this->addField($runnerTestsMemoryField); $runnerTestsCoverageField = new runner\tests\coverage\cli(); $runnerTestsCoverageField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($defaultColorizer) ->setClassPrompt($secondLevelPrompt) ->setMethodPrompt(new prompt('==> ', $defaultColorizer)) ; $this->addField($runnerTestsCoverageField); $runnerDurationField = new runner\duration\cli(); $runnerDurationField ->setPrompt($firstLevelPrompt) ->setTitleColorizer($defaultColorizer) ; $this->addField($runnerDurationField); $runnerResultField = new runner\result\cli(); $runnerResultField ->setSuccessColorizer(new colorizer('0;37', '42')) ->setFailureColorizer(new colorizer('0;37', '41')) ; $this->addField($runnerResultField); $failureColorizer = new colorizer('0;31'); $failurePrompt = clone $secondLevelPrompt; $failurePrompt->setColorizer($failureColorizer); $runnerFailuresField = new runner\failures\cli(); $runnerFailuresField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($failureColorizer) ->setMethodPrompt($failurePrompt) ; $this->addField($runnerFailuresField); $runnerOutputsField = new runner\outputs\cli(); $runnerOutputsField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($defaultColorizer) ->setMethodPrompt($secondLevelPrompt) ; $this->addField($runnerOutputsField); $errorColorizer = new colorizer('0;33'); $errorMethodPrompt = clone $secondLevelPrompt; $errorMethodPrompt->setColorizer($errorColorizer); $errorPrompt = clone $thirdLevelPrompt; $errorPrompt->setColorizer($errorColorizer); $runnerErrorsField = new runner\errors\cli(); $runnerErrorsField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($errorColorizer) ->setMethodPrompt($errorMethodPrompt) ->setErrorPrompt($errorPrompt) ; $this->addField($runnerErrorsField); $exceptionColorizer = new colorizer('0;35'); $exceptionMethodPrompt = clone $secondLevelPrompt; $exceptionMethodPrompt->setColorizer($exceptionColorizer); $exceptionPrompt = clone $thirdLevelPrompt; $exceptionPrompt->setColorizer($exceptionColorizer); $runnerExceptionsField = new runner\exceptions\cli(); $runnerExceptionsField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($exceptionColorizer) ->setMethodPrompt($exceptionMethodPrompt) ->setExceptionPrompt($exceptionPrompt) ; $this->addField($runnerExceptionsField); $uncompletedTestColorizer = new colorizer('0;37'); $uncompletedTestMethodPrompt = clone $secondLevelPrompt; $uncompletedTestMethodPrompt->setColorizer($uncompletedTestColorizer); $uncompletedTestOutputPrompt = clone $thirdLevelPrompt; $uncompletedTestOutputPrompt->setColorizer($uncompletedTestColorizer); $runnerUncompletedField = new runner\tests\uncompleted\cli(); $runnerUncompletedField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($uncompletedTestColorizer) ->setMethodPrompt($uncompletedTestMethodPrompt) ->setOutputPrompt($uncompletedTestOutputPrompt) ; $this->addField($runnerUncompletedField); $voidTestColorizer = new colorizer('0;34'); $voidTestMethodPrompt = clone $secondLevelPrompt; $voidTestMethodPrompt->setColorizer($voidTestColorizer); $runnerVoidField = new runner\tests\void\cli(); $runnerVoidField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($voidTestColorizer) ->setMethodPrompt($voidTestMethodPrompt) ; $this->addField($runnerVoidField); $skippedTestColorizer = new colorizer('0;90'); $skippedTestMethodPrompt = clone $secondLevelPrompt; $skippedTestMethodPrompt->setColorizer($skippedTestColorizer); $runnerSkippedField = new runner\tests\skipped\cli(); $runnerSkippedField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($skippedTestColorizer) ->setMethodPrompt($skippedTestMethodPrompt) ; $this->addField($runnerSkippedField); $testRunField = new test\run\cli(); $testRunField ->setPrompt($firstLevelPrompt) ->setColorizer($defaultColorizer) ; $this->addField($testRunField); $this->addField(new test\event\cli()); $testDurationField = new test\duration\cli(); $testDurationField ->setPrompt($secondLevelPrompt) ; $this->addField($testDurationField); $testMemoryField = new test\memory\cli(); $testMemoryField ->SetPrompt($secondLevelPrompt) ; $this->addField($testMemoryField); } } build(); } public function showProgress() { $this->showProgress = true; return $this->build(); } public function hideProgress() { $this->showProgress = false; return $this->build(); } public function progressIsShowed() { return $this->showProgress; } public function showCodeCoverage() { $this->showCodeCoverage = true; return $this->build(); } public function hideCodeCoverage() { $this->showCodeCoverage = false; return $this->build(); } public function codeCoverageIsShowed() { return $this->showCodeCoverage; } public function showMissingCodeCoverage() { $this->showMissingCodeCoverage = true; return $this->build(); } public function hideMissingCodeCoverage() { $this->showMissingCodeCoverage = false; return $this->build(); } public function missingCodeCoverageIsShowed() { return $this->showMissingCodeCoverage; } public function showDuration() { $this->showDuration = true; return $this->build(); } public function hideDuration() { $this->showDuration = false; return $this->build(); } public function durationIsShowed() { return $this->showDuration; } public function showMemory() { $this->showMemory = true; return $this->build(); } public function hideMemory() { $this->showMemory = false; return $this->build(); } public function memoryIsShowed() { return $this->showMemory; } public function setCodeCoverageReportPath($path = null) { $this->codeCoverageReportPath = $path; return $this; } public function getCodeCoverageReportPath() { return $this->codeCoverageReportPath; } public function setCodeCoverageReportProjectName($url = null) { $this->codeCoverageReportProjectName = $url; return $this; } public function getCodeCoverageReportProjectName() { return $this->codeCoverageReportProjectName; } public function setCodeCoverageReportUrl($url = null) { $this->codeCoverageReportUrl = $url; return $this; } public function getCodeCoverageReportUrl() { return $this->codeCoverageReportUrl; } protected function build() { $this->resetFields(); $firstLevelPrompt = new prompt(PHP_EOL); $firstLevelColorizer = new colorizer('1;36'); $secondLevelPrompt = new prompt(' ', $firstLevelColorizer); $failureColorizer = new colorizer('0;31'); $failurePrompt = clone $secondLevelPrompt; $failurePrompt->setColorizer($failureColorizer); $errorColorizer = new colorizer('0;33'); $errorPrompt = clone $secondLevelPrompt; $errorPrompt->setColorizer($errorColorizer); $exceptionColorizer = new colorizer('0;35'); $exceptionPrompt = clone $secondLevelPrompt; $exceptionPrompt->setColorizer($exceptionColorizer); $uncompletedTestColorizer = new colorizer('0;37'); $uncompletedTestMethodPrompt = clone $secondLevelPrompt; $uncompletedTestMethodPrompt->setColorizer($uncompletedTestColorizer); $uncompletedTestOutputPrompt = new prompt(' ', $uncompletedTestColorizer); $voidTestColorizer = new colorizer('0;34'); $voidTestMethodPrompt = clone $secondLevelPrompt; $voidTestMethodPrompt->setColorizer($voidTestColorizer); $skippedTestColorizer = new colorizer('0;90'); $skippedTestMethodPrompt = clone $secondLevelPrompt; $skippedTestMethodPrompt->setColorizer($skippedTestColorizer); $phpPathField = new runner\php\path\cli(); $phpPathField ->setPrompt($firstLevelPrompt) ->setTitleColorizer($firstLevelColorizer) ; $this->addField($phpPathField); $phpVersionField = new runner\php\version\cli(); $phpVersionField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($firstLevelColorizer) ->setVersionPrompt($secondLevelPrompt) ; $this->addField($phpVersionField); if ($this->showDuration === true) { $runnerDurationField = new runner\duration\cli(); $runnerDurationField ->setPrompt($firstLevelPrompt) ->setTitleColorizer($firstLevelColorizer) ; $this->addField($runnerDurationField); } if ($this->showMemory === true) { $runnerTestsMemoryField = new runner\tests\memory\phing(); $runnerTestsMemoryField ->setPrompt($firstLevelPrompt) ->setTitleColorizer($firstLevelColorizer) ; $this->addField($runnerTestsMemoryField); } if ($this->showCodeCoverage === true) { $runnerTestsCoverageField = new runner\tests\coverage\phing(); $runnerTestsCoverageField ->setTitlePrompt($firstLevelPrompt) ->setClassPrompt($secondLevelPrompt) ->setMethodPrompt(new prompt(' ', $firstLevelColorizer)) ->setTitleColorizer($firstLevelColorizer) ; if ($this->showMissingCodeCoverage === false) { $runnerTestsCoverageField->hideMissingCodeCoverage(); } $this->addField($runnerTestsCoverageField); } $resultField = new runner\result\cli(); $resultField ->setPrompt($firstLevelPrompt) ->setSuccessColorizer(new colorizer('0;37', '42')) ->setFailureColorizer(new colorizer('0;37', '41')) ; $this->addField($resultField); $failuresField = new runner\failures\cli(); $failuresField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($failureColorizer) ->setMethodPrompt($failurePrompt) ; $this->addField($failuresField); $outputsField = new runner\outputs\cli(); $outputsField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($firstLevelColorizer) ->setMethodPrompt($secondLevelPrompt) ; $this->addField($outputsField); $errorsField = new runner\errors\cli(); $errorsField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($errorColorizer) ->setMethodPrompt($errorPrompt) ; $this->addField($errorsField); $exceptionsField = new runner\exceptions\cli(); $exceptionsField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($exceptionColorizer) ->setMethodPrompt($exceptionPrompt) ; $this->addField($exceptionsField); $runnerUncompletedField = new runner\tests\uncompleted\cli(); $runnerUncompletedField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($uncompletedTestColorizer) ->setMethodPrompt($uncompletedTestMethodPrompt) ->setOutputPrompt($uncompletedTestOutputPrompt) ; $this->addField($runnerUncompletedField); $runnerVoidField = new runner\tests\void\cli(); $runnerVoidField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($voidTestColorizer) ->setMethodPrompt($voidTestMethodPrompt) ; $this->addField($runnerVoidField); $runnerSkippedField = new runner\tests\skipped\cli(); $runnerSkippedField ->setTitlePrompt($firstLevelPrompt) ->setTitleColorizer($skippedTestColorizer) ->setMethodPrompt($skippedTestMethodPrompt) ; $this->addField($runnerSkippedField); if ($this->showProgress === true) { $runField = new test\run\phing(); $runField ->setPrompt($firstLevelPrompt) ->setColorizer($firstLevelColorizer) ; $this ->addField($runField) ->addField(new test\event\phing()) ; } if ($this->showDuration === true) { $durationField = new test\duration\phing(); $durationField ->setPrompt($secondLevelPrompt) ; $this->addField($durationField); } if ($this->showMemory === true) { $memoryField = new test\memory\phing(); $memoryField ->setPrompt($secondLevelPrompt) ; $this->addField($memoryField); } if ($this->codeCoverageReportPath !== null) { $coverageField = new atoum\report\fields\runner\coverage\html($this->codeCoverageReportProjectName ?: '', $this->codeCoverageReportPath); $coverageField->setRootUrl($this->codeCoverageReportUrl ?: 'file:////' . realpath($this->codeCoverageReportPath)); $this->addField($coverageField); } return $this; } } addField(new fields\runner\tap\plan()) ->addField(new fields\test\event\tap()) ; } } string; } public function handleEvent($event, atoum\observable $observable) { switch ($event) { case atoum\test::fail: case atoum\test::error: case atoum\test::exception: case atoum\test::uncompleted: $this->fail = true; break; } parent::handleEvent($event, $observable)->build($event); if ($event === atoum\runner::runStop) { if ($this->title !== null) { $this->title = sprintf($this->title, $this->adapter->date($this->locale->_('Y-m-d')), $this->adapter->date($this->locale->_('H:i:s')), $this->fail === true ? $this->locale->_('FAIL') : $this->locale->_('SUCCESS')); } foreach ($this->writers as $writer) { $writer->writeAsynchronousReport($this); } } return $this; } public function addWriter(report\writers\asynchronous $writer) { return $this->doAddWriter($writer); } protected function build($event) { foreach ($this->lastSetFields as $field) { $this->string .= (string) $field; } return $this; } } write($event); } public function addWriter(report\writers\realtime $writer) { return $this->doAddWriter($writer); } protected function write($event) { foreach ($this->writers as $writer) { $writer->writeRealtimeReport($this, $event); } return $this; } } phpPath = null; $this->phpVersion = null; $this->atoumPath = null; $this->atoumVersion = null; return parent::reset(); } public function setAtoumPath($path) { if ($this->atoumPath !== null) { throw new exceptions\runtime('Path of atoum is already set'); } $this->atoumPath = (string) $path; return $this; } public function getAtoumPath() { return $this->atoumPath; } public function setAtoumVersion($version) { if ($this->atoumVersion !== null) { throw new exceptions\runtime('Version of atoum is already set'); } $this->atoumVersion = (string) $version; return $this; } public function getAtoumVersion() { return $this->atoumVersion; } public function setPhpPath($path) { if ($this->phpPath !== null) { throw new exceptions\runtime('PHP path is already set'); } $this->phpPath = (string) $path; return $this; } public function getPhpPath() { return $this->phpPath; } public function setPhpVersion($version) { if ($this->phpVersion !== null) { throw new exceptions\runtime('PHP version is already set'); } $this->phpVersion = trim($version); return $this; } public function getPhpVersion() { return $this->phpVersion; } } setAdapter($adapter) ->setReflectionClassFactory($reflectionClassFactory) ; } public function setAdapter(atoum\adapter $adapter = null) { $this->adapter = $adapter ?: new atoum\adapter(); return $this; } public function getAdapter() { return $this->adapter; } public function setReflectionClassFactory(\closure $factory = null) { $this->reflectionClassFactory = $factory ?: function($class) { return new \reflectionClass($class); }; return $this; } public function getReflectionClassFactory() { return $this->reflectionClassFactory; } public function serialize() { return serialize(array( $this->classes, $this->methods, $this->excludedClasses, $this->excludedNamespaces, $this->excludedDirectories ) ); } public function unserialize($string, \closure $reflectionClassFactory = null) { $this->setReflectionClassFactory($reflectionClassFactory); list( $this->classes, $this->methods, $this->excludedClasses, $this->excludedNamespaces, $this->excludedDirectories ) = unserialize($string); return $this; } public function getClasses() { return $this->classes; } public function getMethods() { return $this->methods; } public function reset() { $this->classes = array(); $this->methods = array(); return $this; } public function resetExcludedClasses() { $this->excludedClasses = array(); return $this; } public function resetExcludedNamespaces() { $this->excludedNamespaces = array(); return $this; } public function resetExcludedDirectories() { $this->excludedDirectories = array(); return $this; } public function addXdebugDataForTest(atoum\test $test, array $data) { return $this->addXdebugDataForClass($test->getTestedClassName(), $data); } public function addXdebugDataForClass($class, array $data) { if (sizeof($data) > 0) { try { $reflectedClass = call_user_func($this->reflectionClassFactory, $class); if ($this->isExcluded($reflectedClass) === false) { $reflectedClassName = $reflectedClass->getName(); $this->classes[$reflectedClassName] = $reflectedClass->getFileName(); $this->methods[$reflectedClassName] = array(); foreach ($reflectedClass->getMethods() as $method) { if ($method->isAbstract() === false) { $declaringClass = $this->getDeclaringClass($method); if ($this->isExcluded($declaringClass) === false) { $declaringClassName = $declaringClass->getName(); $declaringClassFile = $declaringClass->getFilename(); if (isset($this->classes[$declaringClassName]) === false) { $this->classes[$declaringClassName] = $declaringClassFile; $this->methods[$declaringClassName] = array(); } if (isset($data[$declaringClassFile]) === true) { for ($line = $method->getStartLine(), $endLine = $method->getEndLine(); $line <= $endLine; $line++) { if (isset($data[$declaringClassFile][$line]) === true && (isset($this->methods[$declaringClassName][$method->getName()][$line]) === false || $this->methods[$declaringClassName][$method->getName()][$line] < $data[$declaringClassFile][$line])) { $this->methods[$declaringClassName][$method->getName()][$line] = $data[$declaringClassFile][$line]; } } } } } } } } catch (\exception $exception) {} } return $this; } public function merge(score\coverage $coverage) { $classes = $coverage->getClasses(); $methods = $coverage->getMethods(); foreach ($methods as $class => $methods) { $reflectedClass = call_user_func($this->reflectionClassFactory, $class); if (isset($this->classes[$class]) === false) { if ($this->isExcluded($reflectedClass) === false) { $this->classes[$class] = $classes[$class]; } } foreach ($methods as $method => $lines) { if (isset($this->methods[$class][$method]) === true || $this->isExcluded($this->getDeclaringClass($reflectedClass->getMethod($method))) === false) { foreach ($lines as $line => $call) { if (isset($this->methods[$class][$method][$line]) === false || $this->methods[$class][$method][$line] < $call) { $this->methods[$class][$method][$line] = $call; } } } } } return $this; } public function getValue() { $value = null; if (sizeof($this) > 0) { $totalLines = 0; $coveredLines = 0; foreach ($this->methods as $methods) { foreach ($methods as $lines) { foreach ($lines as $call) { if ($call >= -1) { $totalLines++; } if ($call === 1) { $coveredLines++; } } } } if ($totalLines > 0) { $value = (float) $coveredLines / $totalLines; } } return $value; } public function getValueForClass($class) { $value = null; if (isset($this->methods[$class]) === true) { $totalLines = 0; $coveredLines = 0; foreach ($this->methods[$class] as $lines) { foreach ($lines as $call) { if ($call >= -1) { $totalLines++; } if ($call === 1) { $coveredLines++; } } } if ($totalLines > 0) { $value = (float) $coveredLines / $totalLines; } } return $value; } public function getCoverageForClass($class) { $coverage = array(); $class = (string) $class; if (isset($this->methods[$class]) === true && $this->isInExcludedClasses($class) === false) { $coverage = $this->methods[$class]; } return $coverage; } public function getNumberOfCoverableLinesInClass($class) { $coverableLines = 0; $class = (string) $class; if (isset($this->methods[$class]) === true && $this->isInExcludedClasses($class) === false) { foreach ($this->methods[$class] as $lines) { foreach ($lines as $call) { if ($call >= -1) { $coverableLines++; } } } } return $coverableLines; } public function getNumberOfCoveredLinesInClass($class) { $coveredLines = 0; $class = (string) $class; if (isset($this->methods[$class]) === true && $this->isInExcludedClasses($class) === false) { foreach ($this->methods[$class] as $lines) { foreach ($lines as $call) { if ($call === 1) { $coveredLines++; } } } } return $coveredLines; } public function getValueForMethod($class, $method) { $value = null; if (isset($this->methods[$class][$method]) === true) { $totalLines = 0; $coveredLines = 0; foreach ($this->methods[$class][$method] as $call) { if ($call >= -1) { $totalLines++; } if ($call === 1) { $coveredLines++; } } if ($totalLines > 0) { $value = (float) $coveredLines / $totalLines; } } return $value; } public function getCoverageForMethod($class, $method) { $class = $this->getCoverageForClass($class); return (isset($class[$method]) === false ? array() : $class[$method]); } public function excludeClass($class) { $class = (string) $class; if (in_array($class, $this->excludedClasses) === false) { $this->excludedClasses[] = $class; } return $this; } public function getExcludedClasses() { return $this->excludedClasses; } public function excludeNamespace($namespace) { $namespace = trim((string) $namespace, '\\'); if (in_array($namespace, $this->excludedNamespaces) === false) { $this->excludedNamespaces[] = $namespace; } return $this; } public function getExcludedNamespaces() { return $this->excludedNamespaces; } public function excludeDirectory($directory) { $directory = rtrim((string) $directory, DIRECTORY_SEPARATOR); if (in_array($directory, $this->excludedDirectories) === false) { $this->excludedDirectories[] = $directory; } return $this; } public function getExcludedDirectories() { return $this->excludedDirectories; } public function count() { return sizeof($this->methods); } public function isInExcludedClasses($class) { return (in_array($class, $this->excludedClasses) === true); } public function isInExcludedNamespaces($class) { return self::itemIsExcluded($this->excludedNamespaces, $class, '\\'); } public function isInExcludedDirectories($file) { return self::itemIsExcluded($this->excludedDirectories, $file, DIRECTORY_SEPARATOR); } protected function isExcluded(\reflectionClass $class) { $className = $class->getName(); if ($this->isInExcludedClasses($className) === true || $this->isInExcludedNamespaces($className) === true) { return true; } else { $fileName = $class->getFileName(); return ($fileName === false || $this->isInExcludedDirectories($fileName) === true); } } protected function getDeclaringClass(\reflectionMethod $method) { $declaringClass = $method->getDeclaringClass(); $traits = ($this->adapter->method_exists($declaringClass, 'getTraits') === false ? array() : $declaringClass->getTraits()); if (sizeof($traits) > 0) { $methodFileName = $method->getFileName(); if ($methodFileName !== $declaringClass->getFileName() || $method->getStartLine() < $declaringClass->getStartLine() || $method->getEndLine() > $declaringClass->getEndLine()) { if (sizeof($traits) > 0) { $methodName = $method->getName(); foreach ($traits as $trait) { if ($methodFileName === $trait->getFileName() && $trait->hasMethod($methodName) === true) { return $trait; } } } } } return $declaringClass; } protected static function itemIsExcluded(array $excludedItems, $item, $delimiter) { foreach ($excludedItems as $excludedItem) { $excludedItem .= $delimiter; if (substr($item, 0, strlen($excludedItem)) === $excludedItem) { return true; } } return false; } } setSuperglobals($superglobals ?: new atoum\superglobals()); } public function setSuperglobals(atoum\superglobals $superglobals) { $this->superglobals = $superglobals; return $this; } public function getSuperglobals() { return $this->superglobals; } public function resetValues() { $this->values = array(); return $this; } public function getHandlers() { return $this->handlers; } public function getPriorities() { return $this->priorities; } public function getIterator() { return new \arrayIterator($this->getValues()); } public function parse(atoum\script $script, array $array = array()) { $this->init($array); $priorities = $this->priorities; uksort($this->values, function($arg1, $arg2) use ($priorities) { switch (true) { case isset($priorities[$arg1]) === false: case isset($priorities[$arg2]) === false: return - PHP_INT_MAX; default: return ($priorities[$arg1] > $priorities[$arg2] ? -1 : ($priorities[$arg1] == $priorities[$arg2] ? 0 : 1)); } } ); foreach ($this->values as $argument => $values) { $this->triggerHandlers($argument, $values, $script); } return $this; } public function getValues($argument = null) { return ($argument === null ? $this->values : (isset($this->values[$argument]) === false ? null : $this->values[$argument])); } public function addHandler(\closure $handler, array $arguments, $priority = 0) { $invoke = new \reflectionMethod($handler, '__invoke'); if ($invoke->getNumberOfParameters() < 3) { throw new exceptions\runtime('Handler must take three arguments'); } foreach ($arguments as $argument) { if (self::isArgument($argument) === false) { throw new exceptions\runtime('Argument \'' . $argument . '\' is invalid'); } $this->handlers[$argument][] = $handler; $this->priorities[$argument] = (int) $priority; } return $this; } public function resetHandlers() { $this->handlers = array(); $this->priorities = array(); return $this; } public function argumentIsHandled($argument) { return (isset($this->values[$argument]) === true); } public function argumentsAreHandled(array $arguments) { return (sizeof(array_intersect(array_keys($this->values), $arguments)) > 0); } public function init(array $array = array()) { if (sizeof($array) <= 0) { $array = array_slice($this->superglobals->_SERVER['argv'], 1); } $this->resetValues(); $arguments = new \arrayIterator($array); if (sizeof($arguments) > 0) { $value = $arguments->current(); if (self::isArgument($value) === false) { throw new exceptions\runtime\unexpectedValue('First argument \'' . $value . '\' is invalid'); } $argument = $value; $this->values[$argument] = array(); $arguments->next(); while ($arguments->valid() === true) { $value = $arguments->current(); if (self::isArgument($value) === false) { $this->values[$argument][] = $value; } else { $argument = $value; $this->values[$argument] = array(); } $arguments->next(); } } return $this; } public function triggerHandlers($argument, array $values, atoum\script $script) { if (isset($this->handlers[$argument]) === true) { $this->invokeHandlers($script, $argument, $values); } else { $argumentMetaphone = metaphone($argument); $min = null; $closestArgument = null; $handlerArguments = array_keys($this->handlers); natsort($handlerArguments); foreach ($handlerArguments as $handlerArgument) { $levenshtein = levenshtein($argumentMetaphone, metaphone($handlerArgument)); if ($min === null || $levenshtein < $min) { $min = $levenshtein; $closestArgument = $handlerArgument; } } if ($closestArgument === null) { throw new exceptions\runtime\unexpectedValue('Argument \'' . $argument . '\' is unknown'); } else if ($min > 0) { throw new exceptions\runtime\unexpectedValue('Argument \'' . $argument . '\' is unknown, did you mean \'' . $closestArgument . '\' ?'); } else { $this->invokeHandlers($script, $closestArgument, $values); } } return $this; } public function invokeHandlers(atoum\script $script, $argument, array $values) { $position = array_search($argument, array_keys($this->values)) + 1; foreach ($this->handlers[$argument] as $handler) { $handler->__invoke($script, $argument, $values, $position); } return $this; } public static function isArgument($value) { return (preg_match('/^(\+|-{1,2})[a-z][-_a-z0-9]*/i', $value) === 1); } } setIncluder(); } public function setIncluder(atoum\includer $includer = null) { $this->includer = $includer ?: new atoum\includer(); return $this; } public function getIncluder() { return $this->includer; } public function run(array $arguments = array()) { $this->useDefaultConfigFiles(); return parent::run($arguments); } public function useConfigFile($path) { return $this->includeConfigFile($path); } public function useDefaultConfigFiles($startDirectory = null) { if ($startDirectory === null) { $startDirectory = $this->adapter->getcwd(); } foreach (self::getSubDirectoryPath($startDirectory) as $directory) { try { $this->useConfigFile($directory . static::defaultConfigFile); } catch (atoum\includer\exception $exception) {} } return $this; } public static function getSubDirectoryPath($directory, $directorySeparator = null) { $directorySeparator = $directorySeparator ?: DIRECTORY_SEPARATOR; $paths = array(); if ($directory != '') { if ($directory == $directorySeparator) { $paths[] = $directory; } else { $directory = rtrim($directory, $directorySeparator); $path = ''; foreach (explode($directorySeparator, $directory) as $subDirectory) { $path .= $subDirectory . $directorySeparator; $paths[] = $path; } } } return $paths; } protected function setArgumentHandlers() { parent::setArgumentHandlers() ->addArgumentHandler( function($script, $argument, $values) { if (sizeof($values) !== 0) { throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName())); } $script->help(); }, array('-h', '--help'), null, $this->locale->_('Display this help') ) ->addArgumentHandler( function($script, $argument, $files) { if (sizeof($files) <= 0) { throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName())); } foreach ($files as $path) { try { $script->useConfigFile($path); } catch (includer\exception $exception) { throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Configuration file \'%s\' does not exist'), $path)); } } }, array('-c', '--configurations'), '...', $this->locale->_('Use all configuration files '), 1 ) ; return $this; } protected function includeConfigFile($path, \closure $callback = null) { if ($callback === null) { $script = $this; $callback = function($path) use ($script) { include_once($path); }; } try { $this->includer->includePath($path, $callback); } catch (atoum\includer\exception $exception) { throw new atoum\includer\exception(sprintf($this->getLocale()->_('Unable to find configuration file \'%s\''), $path)); } return $this; } } setInputReader() ->setOutputWriter() ; } public function getInputReader() { return $this->inputReader; } public function setInputReader(reader $inputReader = null) { $this->inputReader = $inputReader ?: new std\in(); return $this; } public function getOutputWriter() { return $this->outputWriter; } public function setOutputWriter(writer $writer = null) { $this->outputWriter = $writer ?: new writers\std\out(); return $this; } public function ask($message) { $this->outputWriter->write($message); return $this->inputReader->read(); } } repositoryUrl === null) { throw new exceptions\runtime('Unable to get logs, repository url is undefined'); } if ($this->adapter->extension_loaded('svn') === false) { throw new exceptions\runtime('PHP extension svn is not available, please install it'); } $this->adapter->svn_auth_set_parameter(PHP_SVN_AUTH_PARAM_IGNORE_SSL_VERIFY_ERRORS, true); $nextRevisions = array(); foreach ($this->adapter->svn_log($this->repositoryUrl, $this->revision ?: 1, \SVN_REVISION_HEAD) as $log) { if (is_array($log) && isset($log['rev']) === true && $log['rev'] != $this->revision) { $nextRevisions[] = $log['rev']; } } return $nextRevisions; } public function exportRepository() { if ($this->repositoryUrl === null) { throw new exceptions\runtime('Unable to export repository, repository url is undefined'); } if ($this->workingDirectory === null) { throw new exceptions\runtime('Unable to export repository, working directory is undefined'); } if ($this->adapter->extension_loaded('svn') === false) { throw new exceptions\runtime('PHP extension svn is not available, please install it'); } $this ->cleanWorkingDirectory() ->adapter->svn_auth_set_parameter(PHP_SVN_AUTH_PARAM_IGNORE_SSL_VERIFY_ERRORS, true) ; if ($this->username !== null) { $this->adapter->svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_USERNAME, $this->username); if ($this->password !== null) { $this->adapter->svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_PASSWORD, $this->password); } } if ($this->adapter->svn_checkout($this->repositoryUrl, $this->workingDirectory, $this->revision) === false) { throw new exceptions\runtime('Unable to checkout repository \'' . $this->repositoryUrl . '\' in directory \'' . $this->workingDirectory . '\''); } return $this; } } setAdapter($adapter ?: new atoum\adapter()); } public function setAdapter(atoum\adapter $adapter) { $this->adapter = $adapter; return $this; } public function getAdapter() { return $this->adapter; } public function setWorkingDirectory($workingDirectory) { $this->workingDirectory = (string) $workingDirectory; return $this; } public function getWorkingDirectory() { return $this->workingDirectory; } public function getWorkingDirectoryIterator() { if ($this->workingDirectory === null) { throw new exceptions\runtime('Unable to clean working directory because it is undefined'); } return new \recursiveIteratorIterator(new \recursiveDirectoryIterator($this->workingDirectory, \filesystemIterator::KEY_AS_PATHNAME | \filesystemIterator::CURRENT_AS_FILEINFO | \filesystemIterator::SKIP_DOTS), \recursiveIteratorIterator::CHILD_FIRST); } public function setRepositoryUrl($url) { $this->repositoryUrl = (string) $url; return $this; } public function getRepositoryUrl() { return $this->repositoryUrl; } public function setRevision($revisionNumber) { $this->revision = (int) $revisionNumber; return $this; } public function getRevision() { return $this->revision; } public function setUsername($username) { $this->username = (string) $username; return $this; } public function getUsername() { return $this->username; } public function setPassword($password) { $this->password = (string) $password; return $this; } public function getPassword() { return $this->password; } public abstract function getNextRevisions(); public abstract function exportRepository(); public function cleanWorkingDirectory() { foreach ($this->getWorkingDirectoryIterator() as $inode) { if ($inode->isDir() === false) { $this->adapter->unlink($inode->getPathname()); } else if (($pathname = $inode->getPathname()) !== $this->workingDirectory) { $this->adapter->rmdir($pathname); } } return $this; } } setPharFactory(); } public function setPharFactory(\closure $factory = null) { $this->pharFactory = $factory ?: function($path) { return new \phar($path); }; return $this; } public function getPharFactory() { return $this->pharFactory; } public function setOriginDirectory($directory) { $originDirectory = $this->cleanPath($directory); if ($originDirectory == '') { throw new exceptions\runtime('Empty origin directory is invalid'); } else if ($this->adapter->is_dir($originDirectory) === false) { throw new exceptions\runtime('Path \'' . $originDirectory . '\' of origin directory is invalid'); } else if ($this->destinationDirectory !== null && $originDirectory === $this->destinationDirectory) { throw new exceptions\runtime('Origin directory must be different from destination directory'); } $this->originDirectory = $originDirectory; return $this; } public function getOriginDirectory() { return $this->originDirectory; } public function setDestinationDirectory($directory) { $destinationDirectory = $this->cleanPath($directory); if ($destinationDirectory == '') { throw new exceptions\runtime('Empty destination directory is invalid'); } else if ($this->adapter->is_dir($destinationDirectory) === false) { throw new exceptions\runtime('Path \'' . $destinationDirectory . '\' of destination directory is invalid'); } else if ($this->originDirectory !== null && $destinationDirectory === $this->originDirectory) { throw new exceptions\runtime('Destination directory must be different from origin directory'); } $this->destinationDirectory = $destinationDirectory; return $this; } public function setStubFile($stubFile) { $stubFile = $this->cleanPath($stubFile); if ($stubFile == '') { throw new exceptions\runtime('Stub file is invalid'); } if ($this->adapter->is_file($stubFile) === false) { throw new exceptions\runtime('Stub file is not a valid file'); } $this->stubFile = $stubFile; return $this; } public function getDestinationDirectory() { return $this->destinationDirectory; } public function getStubFile() { return $this->stubFile; } public function run(array $arguments = array()) { $this->generate = true; parent::run($arguments); if ($this->generate === true) { $this->generate(); } return $this; } public function help() { $this->generate = false; return parent::help(); } protected function generate() { if ($this->originDirectory === null) { throw new exceptions\runtime(sprintf($this->locale->_('Origin directory must be defined'), $this->originDirectory)); } if ($this->destinationDirectory === null) { throw new exceptions\runtime(sprintf($this->locale->_('Destination directory must be defined'), $this->originDirectory)); } if ($this->stubFile === null) { throw new exceptions\runtime(sprintf($this->locale->_('Stub file must be defined'), $this->originDirectory)); } if ($this->adapter->is_readable($this->originDirectory) === false) { throw new exceptions\runtime(sprintf($this->locale->_('Origin directory \'%s\' is not readable'), $this->originDirectory)); } if ($this->adapter->is_writable($this->destinationDirectory) === false) { throw new exceptions\runtime(sprintf($this->locale->_('Destination directory \'%s\' is not writable'), $this->destinationDirectory)); } if ($this->adapter->is_readable($this->stubFile) === false) { throw new exceptions\runtime(sprintf($this->locale->_('Stub file \'%s\' is not readable'), $this->stubFile)); } $pharFile = $this->destinationDirectory . DIRECTORY_SEPARATOR . self::phar; @$this->adapter->unlink($pharFile); $description = @$this->adapter->file_get_contents($this->originDirectory . DIRECTORY_SEPARATOR . 'ABOUT'); if ($description === false) { throw new exceptions\runtime(sprintf($this->locale->_('ABOUT file is missing in \'%s\''), $this->originDirectory)); } $licence = @$this->adapter->file_get_contents($this->originDirectory . DIRECTORY_SEPARATOR . 'COPYING'); if ($licence === false) { throw new exceptions\runtime(sprintf($this->locale->_('COPYING file is missing in \'%s\''), $this->originDirectory)); } $stub = @$this->adapter->file_get_contents($this->stubFile); if ($stub === false) { throw new exceptions\runtime(sprintf($this->locale->_('Unable to read stub file \'%s\''), $this->stubFile)); } $phar = call_user_func($this->pharFactory, $pharFile); $phar['versions'] = serialize(array('1' => atoum\version, 'current' => '1')); $phar->setStub($stub); $phar->setMetadata( array( 'version' => atoum\version, 'author' => atoum\author, 'support' => atoum\mail, 'repository' => atoum\repository, 'description' => $description, 'licence' => $licence ) ); $phar->buildFromIterator(new iterators\recursives\atoum\source($this->originDirectory, '1')); $phar->setSignatureAlgorithm(\phar::SHA1); return $this; } protected function cleanPath($path) { $path = $this->adapter->realpath((string) $path); if ($path === false) { $path = ''; } else if (DIRECTORY_SEPARATOR != '/' || $path != '/') { $path = rtrim($path, DIRECTORY_SEPARATOR); } return $path; } protected function setArgumentHandlers() { return $this ->addArgumentHandler( function($script, $argument, $values) { if (sizeof($values) !== 0) { throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName())); } $script->help(); }, array('-h', '--help'), null, 'Display this help' ) ->addArgumentHandler( function($script, $argument, $values) { if (sizeof($values) !== 1) { throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName())); } $script->setDestinationDirectory($values[0]); }, array('-d', '--directory'), '', $this->locale->_('Destination directory ') ) ; } } setPharFactory(); } public function setPharFactory(\closure $factory = null) { $this->pharFactory = $factory ?: function($path) { return new \phar($path); }; return $this; } public function getPharFactory() { return $this->pharFactory; } public function listScripts() { $this->writeMessage($this->locale->_('Available scripts are:') . PHP_EOL); $this->writeMessage(self::padding . 'builder'); $this->writeMessage(self::padding . 'tagger'); $this->writeMessage(self::padding . 'treemap'); $this->runTests = false; return $this; } public function useScript($script) { $scriptFile = self::getScriptFile($script); if (file_exists($scriptFile) === false) { throw new exceptions\logic\invalidArgument(sprintf($this->getLocale()->_('Script %s does not exist'), $script)); } require_once $scriptFile; exit(0); } public function infos() { $phar = call_user_func($this->pharFactory, $this->getName()); $this ->writeMessage($this->locale->_('Informations:') . PHP_EOL) ->writeLabels($phar->getMetadata()) ; $this->runTests = false; return $this; } public function signature() { $phar = call_user_func($this->pharFactory, $this->getName()); $signature = $phar->getSignature(); $this->writeLabel($this->locale->_('Signature'), $signature['hash']); $this->runTests = false; return $this; } public function extractTo($directory) { if (($versions = $this->getVersions($phar = call_user_func($this->pharFactory, $this->getName()))) === null) { throw new exceptions\runtime('Unable to extract the PHAR to \'' . $directory . '\', the versions\'s file is invalid'); } $directory = rtrim($directory, DIRECTORY_SEPARATOR); $pharName = \phar::running(); foreach (new \recursiveIteratorIterator($phar) as $pharFile) { $pharFilePath = ltrim(str_replace($pharName, '', $pharFile), DIRECTORY_SEPARATOR); if (strpos($pharFilePath, $versions['current']) === 0) { $path = $directory . '/' . ltrim(substr($pharFilePath, strlen($versions['current'])), DIRECTORY_SEPARATOR); $pathDirectory = dirname($path); @mkdir($pathDirectory, 0777, true); if (is_dir($pathDirectory) === false) { throw new exceptions\runtime('Unable to create directory \'' . $pathDirectory . '\''); } $data = file_get_contents($pharFile); if (file_put_contents($path, $data) != strlen($data)) { throw new exceptions\runtime('Unable to extract file \'' . $pharFilePath . '\' in directory \'' . $pathDirectory . '\''); } } } $this->runTests = false; return $this; } public function extractResourcesTo($directory) { if (($versions = $this->getVersions($phar = call_user_func($this->pharFactory, $this->getName()))) === null) { throw new exceptions\runtime('Unable to extract resources from PHAR in \'' . $directory . '\', the versions\'s file is invalid'); } if (isset($phar[$versions['current'] . '/resources']) === false) { throw new exceptions\logic('Resources directory does not exist in PHAR \'' . $this->getName() . '\''); } $directory = rtrim($directory, DIRECTORY_SEPARATOR); $resourcesDirectory = 'phar://' . $this->getName() . '/' . $versions['current'] . '/resources'; foreach (new \recursiveIteratorIterator(new \recursiveDirectoryIterator($resourcesDirectory)) as $resourceFile) { $resourceFilePath = ltrim(str_replace($resourcesDirectory, '', $resourceFile), DIRECTORY_SEPARATOR); $resourceFileDirectory = $directory . '/' . dirname($resourceFilePath); @mkdir($resourceFileDirectory, 0777, true); if (is_dir($resourceFileDirectory) === false) { throw new exceptions\runtime('Unable to create directory \'' . $resourceFileDirectory . '\''); } $data = file_get_contents($resourceFile); if (file_put_contents($directory . '/' . $resourceFilePath, $data) != strlen($data)) { throw new exceptions\runtime('Unable to extract resource file \'' . $resourceFilePath . '\' in directory \'' . $directory . '\''); } } $this->runTests = false; return $this; } public function useDefaultConfigFiles($startDirectory = null) { if ($startDirectory === null) { $startDirectory = dirname($this->getName()); } return parent::useDefaultConfigFiles($startDirectory); } public function version() { $this ->writeMessage(sprintf($this->locale->_('atoum version %s by %s (%s)'), atoum\version, atoum\author, \phar::running()) . PHP_EOL) ; $this->runTests = false; return $this; } public function update() { if ($this->adapter->ini_get('phar.readonly') == true) { throw new exceptions\runtime('Unable to update the PHAR, phar.readonly is set, use \'-d phar.readonly=0\''); } if ($this->adapter->ini_get('allow_url_fopen') == false) { throw new exceptions\runtime('Unable to update the PHAR, allow_url_fopen is not set, use \'-d allow_url_fopen=1\''); } if (($versions = $this->getVersions($currentPhar = call_user_func($this->pharFactory, $this->getName()))) === null) { throw new exceptions\runtime('Unable to update the PHAR, the versions\'s file is invalid'); } unset($versions['current']); $this->writeMessage($this->locale->_('Checking if a new version is available...'), false); $data = json_decode($this->adapter->file_get_contents(sprintf(self::updateUrl, json_encode(array_values($versions)))), true); $this ->clearMessage() ->writeMessage($this->locale->_('Checking if a new version is available... Done !')) ; if (is_array($data) === false || isset($data['version']) === false || isset($data['phar']) === false) { $this->writeMessage($this->locale->_('There is no new version available !')); } else { $tmpFile = $this->adapter->realpath($this->adapter->sys_get_temp_dir()) . '/' . md5($data['version']) . '.phar'; if ($this->adapter->file_put_contents($tmpFile, utf8_decode($data['phar'])) === false) { throw new exceptions\runtime('Unable to create temporary file to update to version \'' . $data['version']); } $this->writeMessage(sprintf($this->locale->_('Update to version \'%s\'...'), $data['version']), false); $pharPathLength = strlen($pharPath = 'phar://' . $tmpFile . '/1/'); $newCurrentDirectory = 1; while (isset($versions[$newCurrentDirectory]) === true) { $newCurrentDirectory++; } $newFiles = new \arrayIterator(); foreach (new \recursiveIteratorIterator(new \recursiveDirectoryIterator($pharPath)) as $newFile) { $newFiles[$newCurrentDirectory . '/' . substr($newFile, $pharPathLength)] = ($newFile = (string) $newFile); } $currentPhar->buildFromIterator($newFiles); $this ->clearMessage() ->writeMessage(sprintf($this->locale->_('Update to version \'%s\'... Done !'), $data['version'])) ; @$this->adapter->unlink($tmpFile); $this->writeMessage(sprintf($this->locale->_('Enable version \'%s\'...'), $data['version']), false); $versions[$newCurrentDirectory] = $data['version']; $versions['current'] = $newCurrentDirectory; $currentPhar['versions'] = serialize($versions); $this ->clearMessage() ->writeMessage(sprintf($this->locale->_('Enable version \'%s\'... Done !'), $data['version'])) ; $this->writeMessage(sprintf($this->locale->_('Atoum has been updated from version \'%s\' to \'%s\' successfully !'), atoum\version, $data['version'])); } $this->runTests = false; return $this; } public function listAvailableVersions() { $currentPhar = call_user_func($this->pharFactory, $this->getName()); if (isset($currentPhar['versions']) === false) { throw new exceptions\runtime('Unable to list available versions in PHAR, the versions\'s file does not exist'); } $versions = unserialize(file_get_contents($currentPhar['versions'])); if (is_array($versions) === false || sizeof($versions) <= 0 || isset($versions['current']) === false) { throw new exceptions\runtime('Unable to list available versions in PHAR, the versions\'s file is invalid'); } $currentDirectory = $versions['current']; unset($versions['current']); asort($versions); foreach ($versions as $directory => $version) { $this->writeMessage(($directory == $currentDirectory ? '*' : ' ') . ' ' . $version); } $this->runTests = false; return $this; } public function enableVersion($versionName, \phar $phar = null) { if ($this->adapter->ini_get('phar.readonly') == true) { throw new exceptions\runtime('Unable to update the PHAR, phar.readonly is set, use \'-d phar.readonly=0\''); } if ($phar === null) { $phar = call_user_func($this->pharFactory, $this->getName()); } if (($versions = $this->getVersions($phar)) === null) { throw new exceptions\runtime('Unable to enable version \'' . $versionName . '\', the versions\'s file is invalid'); } $versionDirectory = array_search($versionName, $versions); if ($versionDirectory === false) { throw new exceptions\runtime('Unable to enable version \'' . $versionName . '\' because it does not exist'); } $versions['current'] = $versionDirectory; $phar['versions'] = serialize($versions); $this->runTests = false; return $this; } public function deleteVersion($versionName, \phar $phar = null) { if ($this->adapter->ini_get('phar.readonly') == true) { throw new exceptions\runtime('Unable to update the PHAR, phar.readonly is set, use \'-d phar.readonly=0\''); } if ($phar === null) { $phar = call_user_func($this->pharFactory, $this->getName()); } if (($versions = $this->getVersions($phar)) === null) { throw new exceptions\runtime('Unable to delete version \'' . $versionName . '\', the versions\'s file is invalid'); } $versionDirectory = array_search($versionName, $versions); if ($versionDirectory === false) { throw new exceptions\runtime('Unable to delete version \'' . $versionName . '\' because it does not exist'); } if ($versionDirectory == $versions['current']) { throw new exceptions\runtime('Unable to delete version \'' . $versionName . '\' because it is the current version'); } unset($versions[$versionDirectory]); unset($phar[$versionDirectory]); $phar['versions'] = serialize($versions); $this->runTests = false; return $this; } protected function setArgumentHandlers() { return parent::setArgumentHandlers() ->addArgumentHandler( function($script, $argument, $values) { if (sizeof($values) !== 0) { throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName())); } $script->infos(); }, array('-i', '--infos'), null, $this->locale->_('Display informations, do not run any script') ) ->addArgumentHandler( function($script, $argument, $values) { if (sizeof($values) !== 0) { throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName())); } $script->signature(); }, array('-s', '--signature'), null, $this->locale->_('Display phar signature, do not run any script') ) ->addArgumentHandler( function($script, $argument, $values) { if (sizeof($values) !== 1) { throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName())); } $script->extractTo($values[0]); }, array('-e', '--extract-to'), '', $this->locale->_('Extract all file from phar to , do not run any script') ) ->addArgumentHandler( function($script, $argument, $values) { if (sizeof($values) !== 1) { throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName())); } $script->extractResourcesTo($values[0]); }, array('-er', '--extract-resources-to'), '', $this->locale->_('Extract resources from phar to , do not run any script') ) ->addArgumentHandler( function($script, $argument, $values, $position) { if ($position !== 1 || sizeof($values) !== 1) { throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName())); } unset($_SERVER['argv'][1]); unset($_SERVER['argv'][2]); $script->useScript($values[0]); }, array('-u', '--use'), '

/

Treemap made with atoum, the simple, modern and intuitive unit testing framework for PHP ≥ 5.3

PNG  IHDRh pHYs  *iTXtXML:com.adobe.xmp 2012-11-24T02:11:80 Pixelmator 2.1.3 1 72 5 1 72 176 65535 144 yIDATx17Eb'tE{Evf8 2) Écf6i΢,>e$ ճ].߶m h<1DzC491 _Hx _Hx _HxW}8ȯ6Ovv%] o0pykk[{U}w_vCT;\=Hyϻ%T0TrlKDxJ.m `SSE- y*}f6XGoJg^ S `T,Kd|* { `^O%VُU|Ka|tp{x.7L ; "c''@d<y ZM4훟_lvvbV^MbbbVN3{WNW+&!9E+Bĭ |T[_~.@%p_st7`'Vg^%}!` /{ٿpuPf>uF> Rd~A1X||0 f ,2^I?Q􉣩*؁+p xa++p pfSgsWaV["!0<$``E5 l-)X"nM@n \~Uprm O{X)Lܚ &!9E+Bĭ ``kyHNqk}`罼zܾ $_>1;p/Qs\ ҋ `Qs\ ҋ `Qs\ ҋ `Qs}U7g/ֻhh}_8lMw#dL8>kw Τ0p7B&$3v7}}n.8["18V?:/D5؁йlkйl>'[7Q)Re>A.0q>A.0q>A.0q>A.V|\x4vgA[@G `gA`3)O;;WcV["!0<$``E5 l-)X"nM`>RG}^ŏX"nM[CrV["!0<$``E5xű|IENDB`PNG  IHDRh pHYs  *iTXtXML:com.adobe.xmp 2012-11-24T02:11:24 Pixelmator 2.1.3 1 72 5 1 72 176 65535 144 noIDATx흱U1E *XX!bc#~vj9O"ةڌSX̍=eee<79koB8gU?8'V]-N 0BW%x _!N+D~U;cՇs/rPέ0pzss뛾: ^b8w8;V_|?]LQ}: /pM7Pxq9.0EdK$8 J.- `P0p(H$K"C}`UM+W}{ƹ(V JC `ټn%0PlJdPx(~6o%[ 2(>ʾwPn<~LJjw-V DGc@dq߁Ǖg>YϪ~9):Y=x2):Y=}^7ՇO Dܚ & ^߱.`zyUj}ħo^-G l%KK``+9Hf_{ {US \c%ɖ0pIq(K&z\fg*}CpSN a `3g ` a ;>j?rWV["!0<$``E5 l-)X"nM@Gg?{rI'ո ^_9ĭ ``kyHNqkZS0"Dܚ &0w<|m5NN@Us%jN Dzu·9 l. `:0@W'|؝񆦨s9r~h>H;<% <% <% <ػ^aQ@+|0'pwlГIAO={߹~Y pG.׾ @H EX0p,pt  \.Bk; 0H#?IENDB`setRunner($runner); } public function setRunner(atoum\runner $runner = null) { $this->runner = $runner; return $this; } public function getRunner() { if ($this->runner === null) { $this->runner = new atoum\runner(); } return $this->runner; } public function codeCoverageEnabled() { return ($this->codeCoverage === true || $this->codeCoverageReportPath !== null || $this->codeCoverageTreemapPath !== null); } public function createFileSet() { $this->fileSets[] = $fileSet = new Fileset(); return $fileSet; } private function getFiles() { $files = array(); foreach ($this->fileSets as $fs) { $ds = $fs->getDirectoryScanner($this->project); $dir = $fs->getDir($this->project); $srcFiles = $ds->getIncludedFiles(); foreach ($srcFiles as $file) { $files[] = $dir . FileSystem::getFileSystem()->getSeparator() . $file; } } return $files; } public function main() { if ($this->codeCoverage && extension_loaded('xdebug') === false) { throw new exception('AtoumTask depends on Xdebug being installed to gather code coverage information'); } if ($this->atoumPharPath !== null) { require_once $this->atoumPharPath; } else if ($this->atoumAutoloaderPath !== null) { require_once $this->atoumAutoloaderPath; } else if (class_exists('mageekguy\atoum\scripts\runner', false) === false) { throw new exception('Unknown class mageekguy\\atoum\\scripts\\runner, consider setting atoumPharPath parameter'); } atoum\scripts\runner::disableAutorun(); foreach ($this->getFiles() as $file) { include_once $file; } return $this->execute(); } public function execute() { $report = $this->configureDefaultReport(); $runner = $this->getRunner(); $runner->addReport($report); if ($this->phpPath !== null) { $this->runner->setPhpPath($this->phpPath); } if ($this->bootstrap !== null) { $this->runner->setBootstrapFile($this->bootstrap); } if ($this->maxChildren > 0) { $this->runner->setMaxChildrenNumber($this->maxChildren); } if ($this->codeCoverageEnabled() === false) { $this->runner->disableCodeCoverage(); } else { $this->runner->enableCodeCoverage(); if (($path = $this->codeCoverageCloverPath) !== null) { $clover = new atoum\reports\asynchronous\clover(); $this->runner->addReport($this->configureAsynchronousReport($clover, $path)); } $coverageReportUrl = null; if (($path = $this->codeCoverageReportPath) !== null) { $coverageHtmlField = new coverage\html(isset($this->project) === true ? $this->project->getName() : 'Code coverage report', $path); $coverageHtmlField->setRootUrl($this->codeCoverageReportUrl ?: 'file://' . $path . '/index.html'); $report->addField($coverageHtmlField); } if (($path = $this->codeCoverageTreemapPath) !== null) { $report->addField($this->configureCoverageTreemapField($path, $coverageReportUrl)); } } if (($path = $this->codeCoverageXunitPath) !== null) { $xUnit = new atoum\reports\asynchronous\xunit(); $this->runner->addReport($this->configureAsynchronousReport($xUnit, $path)); } $score = $this->runner->run(); $failures = ($score->getUncompletedMethodNumber() + $score->getFailNumber() + $score->getErrorNumber() + $score->getExceptionNumber() + $score->getRuntimeExceptionNumber()); if ($failures > 0) { throw new BuildException("Tests did not pass"); } return $this; } public function configureDefaultReport(realtime\phing $report = null) { $report = $report ?: new realtime\phing(); $report->addWriter(new atoum\writers\std\out()); if ($this->showProgress === true) { $report->showProgress(); } else { $report->hideProgress(); } if ($this->showDuration === true) { $report->showDuration(); } else { $report->hideDuration(); } if ($this->showMemory === true) { $report->showMemory(); } else { $report->hideMemory(); } if ($this->showCodeCoverage === true) { $report->showCodeCoverage(); } else { $report->hideCodeCoverage(); } if ($this->showMissingCodeCoverage === true) { $report->showMissingCodeCoverage(); } else { $report->hideMissingCodeCoverage(); } return $report; } public function configureAsynchronousReport(reports\asynchronous $report, $path) { $report->addWriter(new atoum\writers\file($path)); return $report; } public function configureCoverageTreemapField($coverageTreemapPath, $coverageReportUrl = null) { $coverageTreemapField = new coverage\treemap(isset($this->project) ? $this->project->getName() : 'Code coverage treemap', $coverageTreemapPath); $coverageTreemapField->setTreemapUrl($this->codeCoverageTreemapUrl ?: 'file://' . $coverageTreemapPath . '/index.html'); if ($coverageReportUrl !== null) { $coverageTreemapField->setHtmlReportBaseUrl($coverageReportUrl); } return $coverageTreemapField; } public function setBootstrap($bootstrap) { $this->bootstrap = (string) $bootstrap; return $this; } public function getBootstrap() { return $this->bootstrap; } public function setCodeCoverage($codeCoverage) { $this->codeCoverage = (boolean) $codeCoverage; return $this; } public function getCodeCoverage() { return $this->codeCoverage; } public function setAtoumPharPath($atoumPharPath) { $this->atoumPharPath = (string) $atoumPharPath; return $this; } public function getAtoumPharPath() { return $this->atoumPharPath; } public function setPhpPath($phpPath) { $this->phpPath = (string) $phpPath; return $this; } public function getPhpPath() { return $this->phpPath; } public function setShowCodeCoverage($showCodeCoverage) { $this->showCodeCoverage = (boolean) $showCodeCoverage; return $this; } public function getShowCodeCoverage() { return $this->showCodeCoverage; } public function setShowDuration($showDurationReport) { $this->showDuration = (boolean) $showDurationReport; return $this; } public function getShowDuration() { return $this->showDuration; } public function setShowMemory($showMemoryReport) { $this->showMemory = (boolean) $showMemoryReport; return $this; } public function getShowMemory() { return $this->showMemory; } public function setShowMissingCodeCoverage($showMissingCodeCoverage) { $this->showMissingCodeCoverage = (boolean) $showMissingCodeCoverage; return $this; } public function getShowMissingCodeCoverage() { return $this->showMissingCodeCoverage; } public function setShowProgress($showProgress) { $this->showProgress = (boolean) $showProgress; return $this; } public function getShowProgress() { return $this->showProgress; } public function setAtoumAutoloaderPath($atoumAutoloaderPath) { $this->atoumAutoloaderPath = (string) $atoumAutoloaderPath; return $this; } public function getAtoumAutoloaderPath() { return $this->atoumAutoloaderPath; } public function setCodeCoverageReportPath($codeCoverageReportPath) { $this->codeCoverageReportPath = (string) $codeCoverageReportPath; return $this; } public function getCodeCoverageReportPath() { return $this->codeCoverageReportPath; } public function setCodeCoverageTreemapPath($codeCoverageTreemapPath) { $this->codeCoverageTreemapPath = (string) $codeCoverageTreemapPath; return $this; } public function setCodeCoverageTreemapUrl($codeCoverageTreemapUrl) { $this->codeCoverageTreemapUrl = (string) $codeCoverageTreemapUrl; return $this; } public function setCodeCoverageReportUrl($codeCoverageReportUrl) { $this->codeCoverageReportUrl = (string) $codeCoverageReportUrl; return $this; } public function getCodeCoverageReportUrl() { return $this->codeCoverageReportUrl; } public function setMaxChildren($maxChildren) { $this->maxChildren = (int) $maxChildren; return $this; } public function getMaxChildren() { return $this->maxChildren; } public function setCodeCoverageXunitPath($codeCoverageXunitPath) { $this->codeCoverageXunitPath = (string) $codeCoverageXunitPath; return $this; } public function getCodeCoverageXunitPath() { return $this->codeCoverageXunitPath; } public function setCodeCoverageCloverPath($codeCoverageCloverPath) { $this->codeCoverageCloverPath = (string) $codeCoverageCloverPath; return $this; } public function getCodeCoverageCloverPath() { return $this->codeCoverageCloverPath; } } 4.0.0 [GROUP ID] [ARTIFACT ID] [PROJECT NAME] [PROJECT VERSION] pom ${basedir}/src ${basedir}/test php [EXCLUDE PATTERNS] true true false false false mageekguy.atoum.phar ${basedir}/.atoum.php ${basedir}/.atoum.bootstrap.php <tpl:projectName /> : code coverage of <tpl:className />

Methods

  • n/a
    %

Source

LineCode
Code coverage of <tpl:projectName />
  • n/a
    %
* {margin: 0; padding: 0; font-family:verdana,arial,helvetica,sans-serif;} body {font-size: 13px; min-width: 500px;} a {color: #155EA8; text-decoration: none;} a:visited {color: #74bff9;} a:hover {color: #3d91e7;} #header {z-index: 1; padding: 0 10px 0 100px; min-height: 80px; background-color: #3d91e7; border-bottom: 10px solid #74bff9; box-shadow: 0 5px 10px #aaa; background-size:80px 60px; background-position: 10px 10px; background-repeat:no-repeat; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALAAAACQCAMAAACfxRFaAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAABhQTFRFAAAAdL/5wrS0PZHnwdPyWlpa////////o/eTdwAAAAh0Uk5T/////////wDeg71ZAAABLklEQVR42uzaUa6CMBBAUZSn7n/HTxNITFNwSkEae+5nE+X4MalpGR5Tw9SjsVLXAAwMDPxj4LRWwYsBAwMD/wj4/uz6rBX47HiZXjZgYGDgXsBzw8m9W4CBgYF7BEebP//3oRwkGjDwt8CXhYCBWwTnhm0NXDN8wMAR8K2wyLCtDd/W5wEDp+DwSXdSZNgiwxdt8SYUGLgGfNkWMPAR4NKD5r3Axc8HBgYG7hT8aeOY11Ncbj23cQADAwMDr0PHqb3B6fcCAwMDA8deOD7qIAUYGBgY2MkPcEfgHS4WgYHPAte+4AEMDAwMvA2c20C+8acHGPhI8BgMGLhF8FgYMHCr4KUfsPXyBRj4LHB0DRjYxgEMXAcuhddCgYGBgYHLDrprD66BgYGBOwH/CzAA6hWUSCPTAz8AAAAASUVORK5CYII=);} #header:after {clear: both;} #header:before, #header:after {content: " "; display: table;} #header a {color: #74bff9;} #header a:hover {color: #fff;} h1 {font-size: 18px; font-weight: bold; margin: 0.5em 0; color: #fff; float: left;} h2 {font-size: 14px; font-weight: bold; margin: 2.5em 0 0.5em 0; color: #fff; float: right;} h2 span {font-size: 30px;} h3 {font-size: 1.2em; margin: 0.5em 0;} #page, #footer {margin: 2em;} #footer {text-align: right; color:#74bff9;} .summary {margin: 1em 0 0 0; border: solid 1px #ddd;} table {width: 100%; border-collapse: collapse; table-layout: fixed;} th, td {padding: 0.2em; border: solid 1px #eee;} th {color: #fff; background: #3d91e7;} td.bar {padding: 0.2em;} td.date {text-align: right;} div.bar {position: relative; width: 100%; height: 30px; padding: 0;} div.bar div.label {position: absolute; top: 0; left: 0; background: none; padding: 6px 0 2px 4px;} div.bar div.graph {position: absolute; top: 0; left: 0; background: #8eff9b; height: 30px;} div.bar div.background {position: absolute; top: 0; left: 0; width: 100%; background: #ff8c76; height: 30px;} li {list-style-type: none; border: solid 1px #eee; border-left: none; border-top: none;} li.classes, li.methods {margin-left: 4em;} table.source th.number {width: 4em;} table.source td {overflow: hidden; width: 100%;} table.source td.number {width: 4em; text-align: right; background: #ddd;} table.source tr.notCovered td {background: #ff8c76;} table.source tr.covered td {background: #8eff9b;} @media (max-width: 900px) { h1 {clear: both;} h2 span {font-size: 20px;} }

" Vimball Archiver by Charles E. Campbell, Jr., Ph.D. UseVimball finish autoload/atoum.vim [[[1 <<<<<<< HEAD <<<<<<< HEAD 153 ======= 150 >>>>>>> Improve vim plugin. ======= 153 >>>>>>> Typo. "============================================================================= " Author: Frédéric Hardy - http://blog.mageekbox.net " Date: Fri Sep 25 14:29:10 CEST 2009 " Licence: BSD "============================================================================= if !exists('g:atoum#php') let g:atoum#php = 'php' endif if !exists('g:atoum#debug') let g:atoum#debug = 0 endif if !exists('g:atoum#_') let g:atoum#_ = '' endif "run {{{1 function atoum#run(file, bang, args) let _ = a:bang != '' ? g:atoum#_ : g:atoum#php . ' -f ' . a:file . ' -- -c ' . g:atoum#configuration if (_ != '') let g:atoum#_ = _ let g:atoum#cursorline = &cursorline let bufnr = bufnr('%') let winnr = bufwinnr('^' . fnameescape(_) . '$') execute winnr < 0 ? 'new ' . fnameescape(_) : winnr . 'wincmd w' set filetype=atoum setlocal buftype=nowrite bufhidden=wipe nobuflisted noswapfile nowrap nonumber nocursorline %d _ let message = 'Execute ' . _ . ' ' . a:args . '…' call append(0, message) echo message 2d _ | resize 1 | redraw execute 'silent! %!' . _ . ' ' . a:args . (g:atoum#debug ? ' --debug' : '') execute 'resize ' . line('$') execute 'nnoremap :call atoum#run(''' . a:file . ''', '''', ''' . a:args . ''')' execute 'nnoremap g :execute bufwinnr(' . bufnr . ') . ''wincmd w''' nnoremap _ :execute 'resize ' . line('$') nnoremap :call atoum#goToFailure(getline('.')) augroup atoum au! execute 'autocmd BufUnload execute bufwinnr(' . bufnr . ') . ''wincmd w''' execute 'autocmd BufEnter execute ''resize '' . line(''$'')' autocmd BufEnter let g:atoum#cursorline = &cursorline | set nocursorline | call atoum#highlightStatusLine() autocmd BufLeave if (g:atoum#cursorline) | set cursorline | endif autocmd BufWinLeave au! atoum augroup end let g:atoum#success = search('^Success ', 'w') if (g:atoum#success > 0) execute g:atoum#success else let result = getline(1, '$') let oldErrorFormat = &errorformat let &errorformat = 'In\ file\ %f\ on\ line\ %l\,\ %m' cgete filter(result, 'v:val =~ "^In file "') let &errorformat = oldErrorFormat let failure = search('^Failure ', 'w') if (failure > 0) execute failure endif endif call atoum#highlightStatusLine() echo '' endif endfunction "defineConfiguration {{{1 function atoum#defineConfiguration(directory, configuration, extension) augroup atoumConfiguration silent! execute 'au BufEnter *' . a:extension . ' if (expand(''%:p'') =~ ''^' . a:directory . ''') | let g:atoum#configuration = ''' . a:configuration . ''' | endif' augroup end endfunction "goToFailure {{{1 function atoum#goToFailure(line) let pattern = '^In file \(\f\+\) on line \(\d\+\).*$' if (matchstr(a:line, pattern) != '') execute bufwinnr('^' . substitute(a:line, pattern, '\1', '') . '$') . 'wincmd w' execute substitute(a:line, pattern, '\2', '') wincmd _ endif endfunction "makeVimball {{{1 function atoum#makeVimball() split atoumVimball setlocal bufhidden=delete setlocal nobuflisted setlocal noswapfile let files = 0 for file in split(globpath(&runtimepath, '**/atoum*'), "\n") for runtimepath in split(&runtimepath, ',') if file =~ '^' . runtimepath if getftype(file) != 'dir' let files += 1 call setline(files, substitute(file, '^' . runtimepath . '/', '', '')) else for subFile in split(glob(file . '/**'), "\n") if getftype(subFile) != 'dir' let files += 1 call setline(files, substitute(subFile, '^' . runtimepath . '/', '', '')) endif endfor endif endif endfor endfor try execute '%MkVimball! atoum' setlocal nomodified bwipeout echomsg 'Vimball is in ''' . getcwd() . '''' catch /.*/ call atoum#displayError(v:exception) endtry endfunction "highlightStatusLine {{{1 function atoum#highlightStatusLine() if g:atoum#success hi statusline guibg=DarkGreen guifg=White gui=NONE else hi statusline guibg=DarkRed guifg=White gui=NONE endif endfunction "displayError {{{1 function atoum#displayError(error) echohl ErrorMsg echomsg a:error echohl None endfunction " vim:filetype=vim foldmethod=marker shiftwidth=3 tabstop=3 doc/atoum.txt [[[1 54 *atoum.txt* Plugin for using atoum, the simple, modern and intuitive unit testing framework for PHP 5.3+ *atoum* *atoum-plugin* Contents: Introduction.............|atoum-introduction| Variables...................|atoum-variables| Commands.....................|atoum-commands| Mappings.....................|atoum-mappings| Author: Frederic Hardy *atoum-author* Licence: BSD This plugin is only available if 'compatible' is not set. INTRODUCTION *atoum-introduction* Install in ~/.vim, or in ~\vimfiles if you're on Windows and feeling lucky. If you're in a hurry to get started, here are some things to try: Open a PHP file which contain atoum unit test, run |:Atoum|. A buffer will be open by VIM to display report about unit test execution. VARIABLES *atoum-variables* g:atoum#disable If its value is 1, disable the plug-in. g:atoum#configuration Path to atoum configuration file which will be used by atoum to execute unit tests. g:atoum#php Path to php binary which will be used to execute unit tests. COMMANDS *atoum-commands* These commands are only available if current buffer contains a PHP file. *atoum-:Atoum* :Atoum Run unit tests in current buffer. MAPPINGS *atoum-mappings* These maps are available in buffer opened by atoum plug-ins. *atoum-* Re-execute unit tests. *fugitive-* If cursor is on a failure, go to the unit test file at line of failure. vim:ts=8 sw=8 noexpandtab tw=78 ft=help: ftplugin/php/atoum.php [[[1 25 addWriter($stdOutWriter) ; $runner->addReport($vimReport); ftplugin/php/atoum.vim [[[1 29 "============================================================================= " Author: Frédéric Hardy - http://blog.mageekbox.net " Date: Fri Sep 25 14:48:22 CEST 2009 " Licence: BSD "============================================================================= if (!exists('atoum#disable') || atoum#disable <= 0) && !exists('b:atoum_loaded') let b:atoum_loaded = 1 if &cp echomsg 'No compatible mode is required by atoum.vim' else let s:cpo = &cpo setlocal cpo&vim if !exists('g:atoum#configuration') let g:atoum#configuration = expand(':h') . '/atoum.php' endif command -buffer -nargs=* -bang Atoum call atoum#run(expand('%'), '', '') command -buffer -nargs=0 AtoumDebugSwitch let g:atoum#debug=!g:atoum#debug | echomsg 'Atoum debug mode ' . (g:atoum#debug ? 'enabled' : 'disabled') command -buffer -nargs=0 AtoumVimball call atoum#makeVimball() let &cpo = s:cpo unlet s:cpo endif endif finish " vim:filetype=vim foldmethod=marker shiftwidth=3 tabstop=3 syntax/atoum.vim [[[1 189 "============================================================================= " Author: Frédéric Hardy - http://blog.mageekbox.net " Licence: BSD "============================================================================= if !exists('b:current_syntax') syn case match syntax match atoumFirstLevelTitle '^> .*\.\.\.$' contains=atoumFirstLevelPrompt syntax match atoumFirstLevelTitle '^> .\+\(:\)\@=:' contains=atoumFirstLevelPrompt syntax match atoumFirstLevelTitle '^> atoum .*$' contains=atoumFirstLevelPrompt highlight default atoumFirstLevelTitle guifg=Cyan ctermfg=Cyan syntax match atoumSecondLevelTitle '^=> .\+$' contains=atoumSecondLevelPrompt highlight default atoumSecondLevelTitle guifg=White ctermfg=White syntax match atoumFirstLevelPrompt '^> ' contained highlight default atoumFirstLevelPrompt guifg=White ctermfg=White syntax match atoumSecondLevelPrompt '^=> ' contained highlight default atoumSecondLevelPrompt guifg=Cyan ctermfg=Cyan syntax match atoumValue '\s\+\zs\d\+\(\.\d\+\)[^.]*.' syntax match atoumValue ' .\+$' highlight default atoumValue guifg=White ctermfg=White syntax region atoumTestDetails matchgroup=atoumFirstLevelPrompt start='^> .\+\.\.\.$'rs=s+2 end="^\(> \|/\*\)"me=s-2 contains=atoumFirstLevelPrompt,atoumTestTitle,atoumTestPrompt,AtoumTestTitle,AtoumTestResult syntax match atoumTestResult '.\+$' contained highlight default atoumTestResult guifg=White ctermfg=White syntax match atoumTestTitle '.\+\.\.\.$' contained highlight default atoumTestTitle guifg=LightBlue ctermfg=LightBlue syntax match atoumTestPrompt '^=> ' contained highlight default atoumTestPrompt guifg=LightBlue ctermfg=LightBlue syntax match atoumTestTitle '.\+:' contained highlight default atoumTestTitle guifg=LightBlue ctermfg=LightBlue syntax region atoumFailureDetails matchgroup=atoumFirstLevelPrompt start='^> There \(is\|are\) \d\+ failures\?:$'rs=s+2 end="^\(> \|/\*\)"me=s-2 contains=atoumFirstLevelPrompt,atoumFailureTitle,atoumFailurePrompt,atoumFailureMethod,atoumFailureDescription,diffRemoved,diffAdded,diffSubname,diffLine syntax match atoumFailureMethod '.\+\(::\)\@!:$' contained highlight default atoumFailureMethod guifg=Red ctermfg=Red syntax match atoumFailureTitle 'There \(is\|are\) \d\+ failures\?:$' contained highlight default atoumFailureTitle guifg=Red ctermfg=Red syntax match atoumFailureDescription '^.*$' contained highlight default atoumFailureDescription guifg=White ctermfg=White syntax match atoumFailurePrompt '^=> ' contained highlight default atoumFailurePrompt guifg=Red ctermfg=Red syntax region atoumErrorDetails matchgroup=atoumFirstLevelPrompt start='^> There \(is\|are\) \d\+ errors\?:$'rs=s+2 end="^\(> \|/\*\)"me=s-2 contains=atoumFirstLevelPrompt,atoumErrorTitle,atoumErrorMethodPrompt,atoumErrorMethod,atoumErrorDescriptionPrompt,atoumErrorDescription,atoumErrorValue syntax match atoumErrorValue '^.*$' contained highlight default atoumErrorValue guifg=White ctermfg=White syntax match atoumErrorDescription 'Error .\+:$' contained highlight default atoumErrorDescription guifg=Yellow ctermfg=Yellow syntax match atoumErrorMethod '.\+::.\+():$' contained highlight default atoumErrorMethod guifg=Yellow ctermfg=Yellow syntax match atoumErrorTitle 'There \(is\|are\) \d\+ errors\?:$' contained highlight default atoumErrorTitle guifg=Yellow ctermfg=Yellow syntax match atoumErrorMethodPrompt '^=> ' contained highlight default atoumErrorMethodPrompt guifg=Yellow ctermfg=Yellow syntax match atoumErrorDescriptionPrompt '^==> ' contained highlight default atoumErrorDescriptionPrompt guifg=Yellow ctermfg=Yellow syntax region atoumUncompletedMethodDetails matchgroup=atoumFirstLevelPrompt start='^> There \(is\|are\) \d\+ uncompleted methods\?:$'rs=s+2 end="^\(> \|/\*\)"me=s-2 contains=atoumFirstLevelPrompt,atoumUncompletedMethodTitle,atoumUncompletedMethodMethodPrompt,atoumUncompletedMethodMethod,atoumUncompletedMethodDescriptionPrompt,atoumUncompletedMethodDescription,atoumUncompletedMethodOutput syntax match atoumUncompletedMethodOutput '.*$' contained highlight default atoumUncompletedMethodOutput guifg=White ctermfg=White syntax match atoumUncompletedMethodDescription '.\+::.\+() with exit code [^:]\+:' contained highlight default atoumUncompletedMethodDescription guifg=Brown ctermfg=Brown syntax match atoumUncompletedMethodMethod '.\+::.\+():$' contained highlight default atoumUncompletedMethodMethod guifg=Brown ctermfg=Brown syntax match atoumUncompletedMethodTitle 'There \(is\|are\) \d\+ uncompleted methods\?:$' contained highlight default atoumUncompletedMethodTitle guifg=Brown ctermfg=Brown syntax match atoumUncompletedMethodMethodPrompt '^=> ' contained highlight default atoumUncompletedMethodMethodPrompt guifg=Brown ctermfg=Brown syntax match atoumUncompletedMethodDescriptionPrompt '^==> ' contained highlight default atoumUncompletedMethodDescriptionPrompt guifg=Brown ctermfg=Brown syntax region atoumVoidDetails matchgroup=atoumFirstLevelPrompt start='^> There \(is\|are\) \d\+ void methods\?:$'rs=s+2 end="^\(> \|/\*\)"me=s-2 contains=atoumFirstLevelPrompt,atoumVoidTitle,atoumVoidMethodPrompt,atoumVoidMethod,atoumVoidDescriptionPrompt syntax match atoumVoidMethod '.\+::.\+()$' contained highlight default atoumVoidMethod guifg=White ctermfg=White syntax match atoumVoidTitle 'There \(is\|are\) \d\+ void methods\?:$' contained highlight default atoumVoidTitle guifg=Blue ctermfg=Blue syntax match atoumVoidMethodPrompt '^=> ' contained highlight default atoumVoidMethodPrompt guifg=Blue ctermfg=Blue syntax region atoumSkippedDetails matchgroup=atoumFirstLevelPrompt start='^> There \(is\|are\) \d\+ skipped methods\?:$'rs=s+2 end="^\(> \|/\*\)"me=s-2 contains=atoumFirstLevelPrompt,atoumSkippedTitle,atoumSkippedMethodPrompt,atoumSkippedMethod,atoumSkippedDescriptionPrompt syntax match atoumSkippedMethod '.\+::.\+()$' contained highlight default atoumSkippedMethod guifg=DarkGrey ctermfg=White syntax match atoumSkippedTitle 'There \(is\|are\) \d\+ skipped methods\?:$' contained highlight default atoumSkippedTitle guifg=DarkGrey ctermfg=DarkGrey syntax match atoumSkippedMethodPrompt '^=> ' contained highlight default atoumSkippedMethodPrompt guifg=DarkGrey ctermfg=DarkGrey syntax region atoumExceptionDetails matchgroup=atoumFirstLevelPrompt start='^> There \(is\|are\) \d\+ exceptions\?:$'rs=s+2 end="^\(> \|/\*\)"me=s-2 contains=atoumFirstLevelPrompt,atoumExceptionTitle,atoumExceptionMethodPrompt,atoumExceptionMethod,atoumExceptionDescriptionPrompt,atoumExceptionDescription syntax match atoumExceptionDescription '.*$' contained highlight default atoumExceptionDescription guifg=White ctermfg=White syntax match atoumExceptionMethod '.\+::.\+():$' contained syntax match atoumExceptionMethod 'Exception throwed in .\+ on line \d\+:' contained highlight default atoumExceptionMethod guifg=Magenta ctermfg=Magenta syntax match atoumExceptionTitle 'There \(is\|are\) \d\+ exceptions\?:$' contained highlight default atoumExceptionTitle guifg=Magenta ctermfg=Magenta syntax match atoumExceptionMethodPrompt '^=> ' contained highlight default atoumExceptionMethodPrompt guifg=Magenta ctermfg=Magenta syntax match atoumExceptionDescriptionPrompt '^==> ' contained highlight default atoumExceptionDescriptionPrompt guifg=Magenta ctermfg=Magenta syntax region atoumCoverageDetails matchgroup=atoumFirstLevelPrompt start='^> Code coverage value:.\+$'rs=s+2 end="^\(> \|/\*\)"me=s-2 contains=atoumFirstLevelPrompt,atoumCoverageTitle,atoumCoverageClassPrompt,atoumCoverageMethodPrompt,atoumCoverageValue,atoumCoverageClass,atoumCoverageMethod syntax match atoumCoverageValue '.*$' contained highlight default atoumCoverageValue guifg=White ctermfg=White syntax match atoumCoverageTitle '.\+:' contained highlight default atoumCoverageTitle guifg=Green ctermfg=Green syntax match atoumCoverageClass 'Class .\+:' contained highlight default atoumCoverageClass guifg=Green ctermfg=Green syntax match atoumCoverageMethod '.\+::.\+():' contained highlight default atoumCoverageMethod guifg=Green ctermfg=Green syntax match atoumCoverageClassPrompt '^=> ' contained highlight default atoumCoverageClassPrompt guifg=Green ctermfg=Green syntax match atoumCoverageMethodPrompt '^==> ' contained highlight default atoumCoverageMethodPrompt guifg=Green ctermfg=Green syntax region atoumOutputDetails matchgroup=atoumFirstLevelPrompt start='^> There \(is\|are\) \d\+ outputs\?:$'rs=s+2 end="^\(> \|/\*\)"me=s-2 contains=atoumFirstLevelPrompt,atoumOutputTitle,atoumOutputPrompt,atoumOutputMethod,atoumOutputDescription,diffRemoved,diffAdded,diffSubname,diffLine syntax match atoumOutputMethod '.\+\(::\)\@!:$' contained highlight default atoumOutputMethod guifg=Gray ctermfg=Gray syntax match atoumOutputTitle 'There \(is\|are\) \d\+ outputs\?:$' contained highlight default atoumOutputTitle guifg=Gray ctermfg=Gray syntax match atoumOutputDescription '^.*$' contained highlight default atoumOutputDescription guifg=White ctermfg=White syntax match atoumOutputPrompt '^=> ' contained highlight default atoumOutputPrompt guifg=Gray ctermfg=Gray syntax match atoumSuccess '^Success ([^)]\+) !' highlight default atoumSuccess term=bold cterm=bold guifg=White guibg=DarkGreen ctermfg=White ctermbg=DarkGreen syntax match atoumFailure '^Failure ([^)]\+) !' highlight default atoumFailure term=bold cterm=bold guifg=White guibg=DarkRed ctermfg=White ctermbg=DarkRed syntax match diffRemoved "^-.*" syntax match diffAdded "^+.*" syntax match diffSubname " @@..*"ms=s+3 contained syntax match diffLine "^@.*" contains=diffSubname syntax match diffLine "^\<\d\+\>.*" syntax match diffLine "^\*\*\*\*.*" highlight default link diffRemoved Special highlight default link diffAdded Identifier highlight default link diffSubname PreProc highlight default link diffLine Statement let b:current_syntax = "atoum" endif " vim:filetype=vim foldmethod=marker shiftwidth=3 tabstop=3 setOriginDirectory(__DIR__ . '/../..'); $generator->setStubFile(__DIR__ . '/resources/stub.php'); set_error_handler(function($error, $message, $file, $line) use ($generator) { if (error_reporting() !== 0) { $generator->writeError($message); exit($error); } } ); try { $generator->run(); } catch (\exception $exception) { $generator->writeError($exception->getMessage()); exit($exception->getCode()); } exit(0); writeError($message); exit($error); } } ); try { $builder->run(); } catch (\exception $exception) { $builder->writeError($exception->getMessage()); exit($exception->getCode()); } exit(0); writeError($message); exit($error); } } ); try { $tagger->run(); } catch (\exception $exception) { $tagger->writeError($exception->getMessage()); exit($exception->getCode()); } exit(0); writeError($message); exit($error); } } ); try { $treemap->setHtmlDirectory(atoum\directory . '/resources/treemap')->run(); } catch (\exception $exception) { $treemap->writeError($exception->getMessage()); exit($exception->getCode()); } exit(0); value) === false) { $this->fail(sprintf($this->getLocale()->_('Line not found because %s is not an exception'), $this->value)); } if ($this->value->getErrorLine() === $line) { return $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Line is %s instead of %s'), $this->value->getErrorLine(), $line)); } } public function hasErrorOffset($offset, $failMessage = null) { if (self::isException($this->value) === false) { $this->fail(sprintf($this->getLocale()->_('Offset not found because %s is not an exception'), $this->value)); } if ($this->value->getErrorOffset() === $offset) { return $this->pass(); } else { $this->fail($failMessage !== null ? $failMessage : sprintf($this->getLocale()->_('Offset is %s instead of %s'), $this->value->getErrorOffset(), $offset)); } } } string(self::space())->match('/ {1,10}/') ->string(self::space(5))->match('/ {1,5}/') ->string(self::space(5, 3))->match('/ {3,5}/') ; } public function testStar() { $this ->string(self::star())->match('/\*{2,10}/') ->string(self::star(5))->match('/\*{2,5}/') ->string(self::star(5, 3))->match('/\*{3,5}/') ; } public function test__construct() { $this ->if($extractor = new annotations\extractor()) ->then ->array($extractor->getHandlers())->isEmpty() ; } public function testExtract() { $this ->if($extractor = new annotations\extractor()) ->and($extractor->setHandler('ignore', function($value) use (& $ignore) { $ignore = $value; })) ->and($extractor->setHandler('tags', function($value) use (& $tags) { $tags = $value; })) ->and($extractor->setHandler('dataProvider', function($value) use (& $dataProvider) { $dataProvider = $value; })) ->and($extractor->setHandler('namespace', function($value) use (& $namespace) { $namespace = $value; })) ->and($extractor->setHandler('maxChildrenNumber', function($value) use (& $maxChildrenNumber) { $maxChildrenNumber = $value; })) ->then ->object($extractor->extract(''))->isIdenticalTo($extractor) ->variable($ignore)->isNull() ->variable($tags)->isNull() ->variable($dataProvider)->isNull() ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract(uniqid()))->isIdenticalTo($extractor) ->variable($ignore)->isNull() ->variable($tags)->isNull() ->variable($dataProvider)->isNull() ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('//'))->isIdenticalTo($extractor) ->variable($ignore)->isNull() ->variable($tags)->isNull() ->variable($dataProvider)->isNull() ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('//@ignore on'))->isIdenticalTo($extractor) ->variable($ignore)->isNull() ->variable($tags)->isNull() ->variable($dataProvider)->isNull() ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('// @ignore on'))->isIdenticalTo($extractor) ->variable($ignore)->isNull() ->variable($tags)->isNull() ->variable($dataProvider)->isNull() ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('/*/'))->isIdenticalTo($extractor) ->variable($ignore)->isNull() ->variable($tags)->isNull() ->variable($dataProvider)->isNull() ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('/**/'))->isIdenticalTo($extractor) ->variable($ignore)->isNull() ->variable($tags)->isNull() ->variable($dataProvider)->isNull() ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('/* */'))->isIdenticalTo($extractor) ->variable($ignore)->isNull() ->variable($tags)->isNull() ->variable($dataProvider)->isNull() ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('/* @ignore on */'))->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('on') ->variable($tags)->isNull() ->variable($dataProvider)->isNull() ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('/*****@ignore on*****/'))->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('on') ->variable($tags)->isNull() ->variable($dataProvider)->isNull() ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('/* @ignore on */'))->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('on') ->variable($tags)->isNull() ->variable($dataProvider)->isNull() ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('/* @ignore on */'))->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('on') ->variable($tags)->isNull() ->variable($dataProvider)->isNull() ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('/* @ignore ON */'))->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('ON') ->variable($tags)->isNull() ->variable($dataProvider)->isNull() ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('/* @ignore On */'))->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('On') ->variable($tags)->isNull() ->variable($dataProvider)->isNull() ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('/* @ignore oN */'))->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('oN') ->variable($tags)->isNull() ->variable($dataProvider)->isNull() ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('/* @ignore oNo */'))->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('oNo') ->variable($tags)->isNull() ->variable($dataProvider)->isNull() ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('/* @ignore Off */'))->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('Off') ->variable($tags)->isNull() ->variable($dataProvider)->isNull() ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('/* @IGNORE off */'))->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('off') ->variable($tags)->isNull() ->variable($dataProvider)->isNull() ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('/* @tags aTag */'))->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('off') ->string($tags)->isEqualTo('aTag') ->variable($dataProvider)->isNull() ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('/* @tags aTag otherTag anotherTag */'))->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('off') ->string($tags)->isEqualTo('aTag otherTag anotherTag') ->variable($dataProvider)->isNull() ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('/* @dataProvider aDataProvider */'))->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('off') ->string($tags)->isEqualTo('aTag otherTag anotherTag') ->string($dataProvider)->isEqualTo('aDataProvider') ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('/* @DATApROVIDER aDataProvider */'))->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('off') ->string($tags)->isEqualTo('aTag otherTag anotherTag') ->string($dataProvider)->isEqualTo('aDataProvider') ->variable($namespace)->isNull() ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('/* @namespace bar */'))->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('off') ->string($tags)->isEqualTo('aTag otherTag anotherTag') ->string($dataProvider)->isEqualTo('aDataProvider') ->string($namespace)->isEqualTo('bar') ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('/* @foo bar */'))->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('off') ->string($tags)->isEqualTo('aTag otherTag anotherTag') ->string($dataProvider)->isEqualTo('aDataProvider') ->string($namespace)->isEqualTo('bar') ->variable($maxChildrenNumber)->isNull() ->object($extractor->extract('/* @maxChildrenNumber 1 */'))->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('off') ->string($tags)->isEqualTo('aTag otherTag anotherTag') ->string($dataProvider)->isEqualTo('aDataProvider') ->string($namespace)->isEqualTo('bar') ->string($maxChildrenNumber)->isEqualTo('1') ->object($extractor->extract('/* @maxChildrenNumber ' . ($number = rand(1, PHP_INT_MAX)) . ' */'))->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('off') ->string($tags)->isEqualTo('aTag otherTag anotherTag') ->string($dataProvider)->isEqualTo('aDataProvider') ->string($namespace)->isEqualTo('bar') ->string($maxChildrenNumber)->isEqualTo($number) ->object($extractor->extract( '/*' . PHP_EOL . "\t" . '@ignore on' . PHP_EOL . "\t" . '@tags aTag anOtherTag' . PHP_EOL . '*/') ) ->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('on') ->string($tags)->isEqualTo('aTag anOtherTag') ->string($dataProvider)->isEqualTo('aDataProvider') ->string($namespace)->isEqualTo('bar') ->string($maxChildrenNumber)->isEqualTo($number) ->object($extractor->extract( '/*' . "\r\n" . "\t" . '@ignore off' . "\r\n" . '*/') ) ->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('off') ->object($extractor->extract( '/*' . "\n" . "\t" . '@ignore on' . "\n" . '*/') ) ->isIdenticalTo($extractor) ->string($ignore)->isEqualTo('on') ->object($extractor->extract( '/** * @tags ManySetGetPredis * @dataProvider manySetGetDataProvider */') ) ->isIdenticalTo($extractor) ->string($tags)->isEqualTo('ManySetGetPredis') ->string($dataProvider)->isEqualTo('manySetGetDataProvider') ; } public function testResetHandlers() { $this ->if($extractor = new annotations\extractor()) ->then ->object($extractor->resetHandlers())->isIdenticalTo($extractor) ->array($extractor->getHandlers())->isEmpty() ->if($extractor->setHandler(uniqid(), function() {})) ->then ->object($extractor->resetHandlers())->isIdenticalTo($extractor) ->array($extractor->getHandlers())->isEmpty() ; } public function testUnsetHandler() { $this ->if($extractor = new annotations\extractor()) ->then ->object($extractor->unsetHandler(uniqid()))->isIdenticalTo($extractor) ->array($extractor->getHandlers())->isEmpty() ->if($extractor->setHandler($annotation = uniqid(), function() {})) ->then ->object($extractor->unsetHandler(uniqid()))->isIdenticalTo($extractor) ->array($extractor->getHandlers())->isNotEmpty() ->object($extractor->unsetHandler($annotation))->isIdenticalTo($extractor) ->array($extractor->getHandlers())->isEmpty() ; } public function testToBoolean() { $this ->boolean(annotations\extractor::toBoolean(true))->isTrue() ->boolean(annotations\extractor::toBoolean(false))->isFalse() ->boolean(annotations\extractor::toBoolean('on'))->isTrue() ->boolean(annotations\extractor::toBoolean('On'))->isTrue() ->boolean(annotations\extractor::toBoolean('ON'))->isTrue() ->boolean(annotations\extractor::toBoolean('oN'))->isTrue() ->boolean(annotations\extractor::toBoolean('off'))->isFalse() ->boolean(annotations\extractor::toBoolean('Off'))->isFalse() ->boolean(annotations\extractor::toBoolean('OFF'))->isFalse() ; } public function testToArray() { $this ->array(annotations\extractor::toArray(''))->isEqualTo(array('')) ->array(annotations\extractor::toArray($value = uniqid()))->isEqualTo(array($value)) ->array(annotations\extractor::toArray(($value = uniqid()) . ' ' . ($otherValue = uniqid())))->isEqualTo(array($value, $otherValue)) ; } protected static function repeat($char, $max, $min = 1) { return str_repeat($char, rand($min, rand($min, $max))); } protected static function space($max = 10, $min = 1) { return self::repeat(' ', $max, $min); } protected static function star($max = 10, $min = 2) { return self::repeat('*', $max, $min); } } if($generator = new testedClass()) ->then ->object($generator->getLocale())->isEqualTo(new atoum\locale()) ->object($generator->getAdapter())->isEqualTo(new atoum\adapter()) ->string($generator->getAsserterNamespace())->isEqualTo(testedClass::defaultAsserterNamespace) ->if($generator = new testedClass($locale = new atoum\locale(), $adapter = new atoum\adapter(), $asserterNamespace = uniqid())) ->then ->object($generator->getLocale())->isIdenticalTo($locale) ->object($generator->getAdapter())->isIdenticalTo($adapter) ->string($generator->getAsserterNamespace())->isEqualTo($asserterNamespace) ; } public function test__get() { $this ->if($generator = new testedClass()) ->then ->exception(function() use ($generator, & $asserter) { $generator->{$asserter = uniqid()}; }) ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument') ->hasMessage('Asserter \'' . $asserter . '\' does not exist') ->object($generator->variable)->isInstanceOf('mageekguy\atoum\asserters\variable') ; } public function test__set() { $this ->if($generator = new testedClass()) ->then ->when(function() use ($generator, & $alias, & $asserter) { $generator->{$alias = uniqid()} = ($asserter = uniqid()); }) ->array($generator->getAliases())->isEqualTo(array($alias => $asserter)) ->when(function() use ($generator, & $otherAlias, & $otherAsserter) { $generator->{$otherAlias = uniqid()} = ($otherAsserter = uniqid()); }) ->array($generator->getAliases())->isEqualTo(array($alias => $asserter, $otherAlias => $otherAsserter)) ; } public function test__call() { $this ->if($generator = new testedClass()) ->then ->exception(function() use ($generator, & $asserter) { $generator->{$asserter = uniqid()}(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument') ->hasMessage('Asserter \'' . $asserter . '\' does not exist') ->object($generator->variable(uniqid()))->isInstanceOf('mageekguy\atoum\asserters\variable') ; } public function testSetAdapter() { $this ->if($generator = new testedClass()) ->then ->object($generator->setAdapter($adapter = new atoum\adapter()))->isIdenticalTo($generator) ->object($generator->getAdapter())->isIdenticalTo($adapter) ->object($generator->setAdapter())->isIdenticalTo($generator) ->object($generator->getAdapter()) ->isNotIdenticalTo($adapter) ->isEqualTo(new atoum\adapter()) ; } public function testSetLocale() { $this ->if($generator = new testedClass()) ->then ->object($generator->setLocale($locale = new atoum\locale()))->isIdenticalTo($generator) ->object($generator->getLocale())->isIdenticalTo($locale) ->object($generator->setLocale())->isIdenticalTo($generator) ->object($generator->getLocale()) ->isNotIdenticalTo($locale) ->isEqualTo(new atoum\locale()) ; } public function testSetAsserterNamespace() { $this ->if($generator = new testedClass()) ->then ->object($generator->setAsserterNamespace($namespace = uniqid()))->isIdenticalTo($generator) ->string($generator->getAsserterNamespace())->isEqualTo($namespace) ->object($generator->setAsserterNamespace())->isIdenticalTo($generator) ->string($generator->getAsserterNamespace())->isEqualTo(testedClass::defaultAsserterNamespace) ; } public function testSetAlias() { $this ->if($generator = new testedClass()) ->then ->object($generator->setAlias($alias = uniqid(), $asserter = uniqid()))->isIdenticalTo($generator) ->array($generator->getAliases())->isEqualTo(array($alias => $asserter)) ->object($generator->setAlias($otherAlias = 'FOO', $otherAsserter = uniqid()))->isIdenticalTo($generator) ->array($generator->getAliases())->isEqualTo(array($alias => $asserter, 'foo' => $otherAsserter)) ; } public function testResetAliases() { $this ->if($generator = new testedClass()) ->and($generator->setAlias(uniqid(), uniqid())) ->then ->array($generator->getAliases())->isNotEmpty() ->object($generator->resetAliases())->isIdenticalTo($generator) ->array($generator->getAliases())->isEmpty() ; } public function testGetAsserterClass() { $this ->if($generator = new testedClass()) ->and($generator->setAdapter($adapter = new atoum\test\adapter())) ->and($adapter->class_exists = true) ->then ->string($generator->getAsserterClass($asserter = uniqid()))->isEqualTo('mageekguy\atoum\asserters\\' . $asserter) ->string($generator->getAsserterClass('\\' . $asserter))->isEqualTo('\\' . $asserter) ->if($generator->setAlias($alias = uniqid(), $asserter)) ->then ->string($generator->getAsserterClass($asserter))->isEqualTo(testedClass::defaultAsserterNamespace . '\\' . $asserter) ->string($generator->getAsserterClass($alias))->isEqualTo(testedClass::defaultAsserterNamespace . '\\' . $asserter) ->if($generator->setAsserterNamespace($namespace = uniqid())) ->then ->string($generator->getAsserterClass($asserter))->isEqualTo($namespace . '\\' . $asserter) ->string($generator->getAsserterClass($alias))->isEqualTo($namespace . '\\' . $asserter) ->if($adapter->class_exists = false) ->variable($generator->getAsserterClass($asserter))->isNull() ; } } testedClass->extends('mageekguy\atoum\php\call'); } public function test__construct() { $this ->if($call = new call\adapter($adapterAsserter = new asserters\adapter(new asserter\generator()), $adapter = new test\adapter(), $function = uniqid())) ->then ->object($call->getAdapterAsserter())->isIdenticalTo($adapterAsserter) ->object($call->getAdapter())->isIdenticalTo($adapter) ->string($call->getFunction())->isEqualTo($function) ->variable($call->getArguments())->isNull() ->if($call = new call\adapter($adapterAsserter = new asserters\adapter(new asserter\generator()), $adapter = new test\adapter, $function = rand(1, PHP_INT_MAX))) ->then ->object($call->getAdapterAsserter())->isIdenticalTo($adapterAsserter) ->object($call->getAdapter())->isIdenticalTo($adapter) ->string($call->getFunction())->isEqualTo((string) $function) ->variable($call->getArguments())->isNull() ; } public function test__call() { $this ->if($call = new call\adapter($adapterAsserter = new \mock\mageekguy\atoum\asserters\adapter(new asserter\generator()), new test\adapter(), uniqid())) ->and($adapterAsserter->getMockController()->call = $adapterAsserter) ->then ->object($call->call($arg = uniqid()))->isIdenticalTo($adapterAsserter) ->mock($adapterAsserter) ->call('call')->withArguments($arg)->once() ->if($unknownFunction = uniqid()) ->then ->exception(function() use ($call, $unknownFunction) { $call->{$unknownFunction}(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument') ->hasMessage('Method ' . get_class($adapterAsserter) . '::' . $unknownFunction . '() does not exist') ; } public function test__toString() { $this ->if($call = new call\adapter(new asserters\adapter(new asserter\generator()), new test\adapter(), $function = uniqid())) ->then ->castToString($call)->isEqualTo($function . '()') ; } public function testWithArguments() { $this ->if($call = new call\adapter(new asserters\adapter(new asserter\generator()), new test\adapter(), uniqid())) ->then ->object($call->withArguments($arg = uniqid()))->isIdenticalTo($call) ->array($call->getArguments())->isEqualTo(array($arg)) ->object($call->withArguments($arg1 = uniqid(), $arg2 = uniqid()))->isIdenticalTo($call) ->array($call->getArguments())->isEqualTo(array($arg1, $arg2)) ; } public function testGetFirstCall() { $this ->if($call = new call\adapter( new asserters\adapter(new asserter\generator()), $adapter = new test\adapter(), 'md5')) ->then ->variable($call->getFirstCall())->isNull() ->if($otherAdapter = new test\adapter()) ->and($otherAdapter->md5(uniqid())) ->then ->variable($call->getFirstCall())->isNull() ->if($adapter->md5(uniqid())) ->then ->integer($call->getFirstCall())->isEqualTo(2) ->if($adapter->md5(uniqid())) ->then ->integer($call->getFirstCall())->isEqualTo(2) ; } public function testGetLastCall() { $this ->if($call = new call\adapter(new asserters\adapter(new asserter\generator()), $adapter = new test\adapter(), 'md5')) ->then ->variable($call->getLastCall())->isNull() ->if($otherAdapter = new test\adapter()) ->and($otherAdapter->md5(uniqid())) ->then ->variable($call->getLastCall())->isNull() ->if($adapter->md5(uniqid())) ->then ->integer($call->getLastCall())->isEqualTo(2) ->if($adapter->md5(uniqid())) ->then ->integer($call->getLastCall())->isEqualTo(3) ; } } testedClass->extends('mageekguy\atoum\php\call'); } public function test__construct() { $this ->if($call = new call\mock($adapterAsserter = new asserters\adapter(new asserter\generator()), $mockAggregator = new \mock\dummy(), $methodName = uniqid())) ->then ->object($call->getAdapterAsserter())->isIdenticalTo($adapterAsserter) ->object($call->getObject())->isIdenticalTo($mockAggregator) ->string($call->getFunction())->isEqualTo($methodName) ->variable($call->getArguments())->isNull() ->if($call = new call\mock($adapterAsserter = new asserters\adapter(new asserter\generator()), $mockAggregator = new \mock\dummy, $methodName = rand(1, PHP_INT_MAX))) ->then ->object($call->getAdapterAsserter())->isIdenticalTo($adapterAsserter) ->object($call->getObject())->isIdenticalTo($mockAggregator) ->string($call->getFunction())->isEqualTo((string) $methodName) ->variable($call->getArguments())->isNull() ; } public function test__call() { $this ->if($call = new call\mock($adapterAsserter = new \mock\mageekguy\atoum\asserters\adapter(new asserter\generator()), new \mock\dummy(), uniqid())) ->and($adapterAsserter->getMockController()->call = $adapterAsserter) ->then ->object($call->call($arg = uniqid()))->isIdenticalTo($adapterAsserter) ->mock($adapterAsserter) ->call('call')->withArguments($arg)->once() ->if($unknownMethod = uniqid()) ->then ->exception(function() use ($call, $unknownMethod) { $call->{$unknownMethod}(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument') ->hasMessage('Method ' . get_class($adapterAsserter) . '::' . $unknownMethod . '() does not exist') ; } public function test__toString() { $this ->if($call = new call\mock(new \mock\mageekguy\atoum\asserters\adapter(new asserter\generator()), $mockAggregator = new \mock\dummy(), $function = uniqid())) ->then ->castToString($call)->isEqualTo(get_class($mockAggregator) . '::' . $function . '()') ; } public function testWithArguments() { $this ->if($call = new call\mock(new asserters\adapter(new asserter\generator()), new \mock\dummy(), uniqid())) ->then ->object($call->withArguments($arg = uniqid()))->isIdenticalTo($call) ->array($call->getArguments())->isEqualTo(array($arg)) ->object($call->withArguments($arg1 = uniqid(), $arg2 = uniqid()))->isIdenticalTo($call) ->array($call->getArguments())->isEqualTo(array($arg1, $arg2)) ; } public function testGetFirstCall() { $this ->if($call = new call\mock(new asserters\adapter(new asserter\generator()), $mock = new \mock\dummy(), 'foo')) ->then ->variable($call->getFirstCall())->isNull() ->when(function() { $otherMock = new \mock\dummy(); $otherMock->foo(); }) ->variable($call->getFirstCall())->isNull() ->when(function() use ($mock) { $mock->foo(); }) ->integer($call->getFirstCall())->isEqualTo(2) ->when(function() use ($mock) { $mock->foo(); }) ->integer($call->getFirstCall())->isEqualTo(2) ; } public function testGetLastCall() { $this ->if($call = new call\mock(new asserters\adapter(new asserter\generator()), $mock = new \mock\dummy(), 'foo')) ->then ->variable($call->getLastCall())->isNull() ->when(function() { $otherMock = new \mock\dummy(); $otherMock->foo(); }) ->variable($call->getLastCall())->isNull() ->when(function() use ($mock) { $mock->foo(); }) ->integer($call->getLastCall())->isEqualTo(2) ->when(function() use ($mock) { $mock->foo(); }) ->integer($call->getLastCall())->isEqualTo(3) ; } } testedClass->extends('mageekguy\atoum\php\call'); } public function test__construct() { $this ->if($call = new call\adapter( $mockAsserter = new asserters\mock(new asserter\generator()), $adapter = new test\adapter(), $function = uniqid() ) ) ->then ->object($call->getMockAsserter())->isIdenticalTo($mockAsserter) ->object($call->getAdapter())->isIdenticalTo($adapter) ->string($call->getFunction())->isEqualTo($function) ->variable($call->getArguments())->isNull() ; } public function test__call() { $this ->if($call = new call\adapter( $mockAsserter = new \mock\mageekguy\atoum\asserters\mock(new asserter\generator()), new test\adapter(), uniqid() ) ) ->and($mockAsserter->getMockController()->call = $mockAsserter) ->then ->object($call->call($arg = uniqid()))->isIdenticalTo($mockAsserter) ->mock($mockAsserter) ->call('call')->withArguments($arg)->once() ->if($unknownFunction = uniqid()) ->then ->exception(function() use ($call, $unknownFunction) { $call->{$unknownFunction}(); } ) ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument') ->hasMessage('Method ' . get_class($mockAsserter) . '::' . $unknownFunction . '() does not exist') ; } public function testWithArguments() { $this ->if($call = new call\adapter( new asserters\mock(new asserter\generator()), new test\adapter(), uniqid() ) ) ->then ->object($call->withArguments($arg = uniqid()))->isIdenticalTo($call) ->array($call->getArguments())->isEqualTo(array($arg)) ->object($call->withArguments($arg1 = uniqid(), $arg2 = uniqid()))->isIdenticalTo($call) ->array($call->getArguments())->isEqualTo(array($arg1, $arg2)) ; } public function testGetFirstCall() { $this ->if($call = new call\adapter( new asserters\mock(new asserter\generator()), $adapter = new test\adapter(), 'md5' ) ) ->then ->variable($call->getFirstCall())->isNull() ->when(function() { $otherAdapter = new test\adapter(); $otherAdapter->md5(uniqid()); }) ->variable($call->getFirstCall())->isNull() ->when(function() use ($adapter) { $adapter->md5(uniqid()); }) ->integer($call->getFirstCall())->isEqualTo(2) ->when(function() use ($adapter) { $adapter->md5(uniqid()); }) ->integer($call->getFirstCall())->isEqualTo(2) ; } public function testGetLastCall() { $this ->if($call = new call\adapter( new asserters\mock(new asserter\generator()), $adapter = new test\adapter(), 'md5' ) ) ->then ->variable($call->getLastCall())->isNull() ->when(function() { $otherAdapter = new test\adapter(); $otherAdapter->md5(uniqid()); }) ->variable($call->getLastCall())->isNull() ->when(function() use ($adapter) { $adapter->md5(uniqid()); }) ->integer($call->getLastCall())->isEqualTo(2) ->when(function() use ($adapter) { $adapter->md5(uniqid()); }) ->integer($call->getLastCall())->isEqualTo(3) ; } } testedClass->extends('mageekguy\atoum\php\call'); } public function test__construct() { $this ->if($call = new testedClass( $mockAsserter = new asserters\mock(new asserter\generator()), $mockAggregator = new \mock\mageekguy\atoum\tests\units\asserters\mock\call\dummy(), $function = uniqid() ) ) ->then ->object($call->getMockAsserter())->isIdenticalTo($mockAsserter) ->object($call->getObject())->isIdenticalTo($mockAggregator) ->string($call->getFunction())->isEqualTo($function) ->variable($call->getArguments())->isNull() ; } public function test__call() { $this ->if($call = new testedClass( $mockAsserter = new \mock\mageekguy\atoum\asserters\mock(new asserter\generator()), new \mock\mageekguy\atoum\tests\units\asserters\mock\call\dummy(), uniqid() ) ) ->and($mockAsserter->getMockController()->call = $mockAsserter) ->then ->object($call->call($arg = uniqid()))->isIdenticalTo($mockAsserter) ->mock($mockAsserter) ->call('call')->withArguments($arg)->once() ->if($unknownMethod = uniqid()) ->then ->exception(function() use ($call, $unknownMethod) { $call->{$unknownMethod}(); } ) ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument') ->hasMessage('Method ' . get_class($mockAsserter) . '::' . $unknownMethod . '() does not exist') ; } public function test__toString() { $this ->if($call = new testedClass( new asserters\mock(new asserter\generator()), $mockAggregator = new \mock\mageekguy\atoum\tests\units\asserters\mock\call\dummy(), $function = uniqid() ) ) ->then ->castToString($call)->isEqualTo(get_class($mockAggregator) . '::' . $function . '()') ; } public function testWithArguments() { $this ->if($call = new testedClass( new asserters\mock(new asserter\generator()), new \mock\mageekguy\atoum\tests\units\asserters\mock\call\dummy(), uniqid() ) ) ->then ->object($call->withArguments($arg = uniqid()))->isIdenticalTo($call) ->array($call->getArguments())->isEqualTo(array($arg)) ->object($call->withArguments($arg1 = uniqid(), $arg2 = uniqid()))->isIdenticalTo($call) ->array($call->getArguments())->isEqualTo(array($arg1, $arg2)) ; } public function testWithAtLeastArguments() { $this ->if($call = new testedClass( new asserters\mock(new asserter\generator()), new \mock\mageekguy\atoum\tests\units\asserters\mock\call\dummy(), uniqid() ) ) ->then ->object($call->withAtLeastArguments($arguments = array(1 => uniqid(), 3 => uniqid())))->isIdenticalTo($call) ->array($call->getArguments())->isEqualTo(array($arguments)) ->object($call->withAtLeastArguments($otherArguments = array(1 => uniqid(), 3 => uniqid())))->isIdenticalTo($call) ->array($call->getArguments())->isEqualTo(array($otherArguments)) ; } public function testOn() { $this ->if($call = new testedClass( new asserters\mock(new asserter\generator()), new \mock\mageekguy\atoum\tests\units\asserters\mock\call\dummy(), uniqid() ) ) ->and($mockAggregator = new \mock\mageekguy\atoum\tests\units\asserters\mock\call\dummy()) ->then ->object($call->on($mockAggregator))->isIdenticalTo($call) ->object($call->getObject())->isIdenticalTo($mockAggregator) ; } public function testGetFirstCall() { $this ->if($call = new testedClass( new asserters\mock(new asserter\generator()), $mock = new \mock\mageekguy\atoum\tests\units\asserters\mock\call\dummy(), 'foo' ) ) ->then ->variable($call->getFirstCall())->isNull() ->if($otherMock = new \mock\mageekguy\atoum\tests\units\asserters\mock\call\dummy()) ->and($otherMock->foo()) ->then ->variable($call->getFirstCall())->isNull() ->when(function() use ($mock) { $mock->foo(); }) ->integer($call->getFirstCall())->isEqualTo(2) ->when(function() use ($mock) { $mock->foo(); }) ->integer($call->getFirstCall())->isEqualTo(2) ; } public function testGetLastCall() { $this ->if($call = new testedClass( new asserters\mock(new asserter\generator()), $mock = new \mock\mageekguy\atoum\tests\units\asserters\mock\call\dummy(), 'foo' ) ) ->then ->variable($call->getLastCall())->isNull() ->if($otherMock = new \mock\mageekguy\atoum\tests\units\asserters\mock\call\dummy()) ->and($otherMock->foo()) ->then ->variable($call->getLastCall())->isNull() ->when(function() use ($mock) { $mock->foo(); }) ->integer($call->getLastCall())->isEqualTo(2) ->when(function() use ($mock) { $mock->foo(); }) ->integer($call->getLastCall())->isEqualTo(3) ; } } testedClass->isSubclassOf('mageekguy\atoum\asserter'); } public function test__construct() { $this ->if($asserter = new asserters\adapter($generator = new asserter\generator())) ->then ->object($asserter->getLocale())->isIdenticalTo($generator->getLocale()) ->object($asserter->getGenerator())->isIdenticalTo($generator) ->variable($asserter->getCall())->isNull() ->variable($asserter->getAdapter())->isNull() ->array($asserter->getBeforeMethodCalls())->isEmpty() ->array($asserter->getBeforeFunctionCalls())->isEmpty() ->array($asserter->getAfterMethodCalls())->isEmpty() ->array($asserter->getAfterFunctionCalls())->isEmpty() ; } public function testSetWith() { $this ->if($asserter = new asserters\adapter($generator = new asserter\generator())) ->then ->assert('Set the asserter with something else than an adapter throw an exception') ->exception(function() use ($asserter, & $value) { $asserter->setWith($value = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not a test adapter'), $asserter->getTypeOf($value))) ->string($asserter->getAdapter())->isEqualTo($value) ->assert('It is possible to set the asserter with an adapter') ->object($asserter->setWith($adapter = new test\adapter()))->isIdenticalTo($asserter) ->object($asserter->getAdapter())->isIdenticalTo($adapter) ; } public function testReset() { $this ->if($asserter = new asserters\adapter(new asserter\generator())) ->then ->variable($asserter->getAdapter())->isNull() ->object($asserter->reset())->isIdenticalTo($asserter) ->variable($asserter->getAdapter())->isNull() ->if($asserter->setWith($adapter = new atoum\test\adapter())) ->then ->object($asserter->getAdapter())->isIdenticalTo($adapter) ->array($adapter->getCalls())->isEmpty() ->object($asserter->reset())->isIdenticalTo($asserter) ->object($asserter->getAdapter())->isIdenticalTo($adapter) ->array($adapter->getCalls())->isEmpty() ->if($adapter->md5(uniqid())) ->then ->object($asserter->getAdapter())->isIdenticalTo($adapter) ->array($adapter->getCalls())->isNotEmpty() ->object($asserter->reset())->isIdenticalTo($asserter) ->object($asserter->getAdapter())->isIdenticalTo($adapter) ->array($adapter->getCalls())->isEmpty() ; } public function testCall() { $this ->if($asserter = new \mock\mageekguy\atoum\asserters\adapter(new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->call(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Adapter is undefined') ->if($asserter->setWith($adapter = new test\adapter())) ->then ->object($asserter->call($function = uniqid()))->isIdenticalTo($asserter) ->object($asserter->getCall())->isEqualTo(new php\call($function)) ->if($asserter->withArguments()) ->then ->object($asserter->getCall())->isEqualTo(new php\call($function, array())) ->object($asserter->call($function = uniqid()))->isIdenticalTo($asserter) ->object($asserter->getCall())->isEqualTo(new php\call($function)) ; } public function testWithArguments() { $this ->if($asserter = new \mock\mageekguy\atoum\asserters\adapter(new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->withArguments(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Adapter is undefined') ->if($asserter->setWith($adapter = new test\adapter())) ->then ->exception(function() use ($asserter) { $asserter->withArguments(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Called function is undefined') ->if($asserter->call($function = uniqid())) ->then ->object($asserter->withArguments())->isIdenticalTo($asserter) ->object($asserter->getCall())->isEqualTo(new php\call($function, array())) ->object($asserter->withArguments($arg1 = uniqid()))->isIdenticalTo($asserter) ->object($asserter->getCall())->isEqualTo(new php\call($function, array($arg1))) ->object($asserter->withArguments($arg1 = uniqid(), $arg2 = uniqid()))->isIdenticalTo($asserter) ->object($asserter->getCall())->isEqualTo(new php\call($function, array($arg1, $arg2))) ; } public function testWithAnyArguments() { $this ->if($asserter = new \mock\mageekguy\atoum\asserters\adapter(new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->withArguments(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Adapter is undefined') ->if($asserter->setWith($adapter = new test\adapter())) ->then ->exception(function() use ($asserter) { $asserter->withArguments(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Called function is undefined') ->if($asserter->call($function = uniqid())) ->then ->object($asserter->getCall())->isEqualTo(new php\call($function)) ->object($asserter->withAnyArguments())->isIdenticalTo($asserter) ->object($asserter->getCall())->isEqualTo(new php\call($function)) ->if($asserter->withArguments($arg = uniqid())) ->then ->object($asserter->getCall())->isEqualTo(new php\call($function, array($arg))) ->object($asserter->withAnyArguments())->isIdenticalTo($asserter) ->object($asserter->getCall())->isEqualTo(new php\call($function)) ; } public function testWithoutAnyArgument() { $this ->if($asserter = new \mock\mageekguy\atoum\asserters\adapter(new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->withoutAnyArgument(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Adapter is undefined') ->if($asserter->setWith($adapter = new test\adapter())) ->then ->exception(function() use ($asserter) { $asserter->withoutAnyArgument(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Called function is undefined') ->if($asserter->call($function = uniqid())) ->then ->object($asserter->withoutAnyArgument())->isIdenticalTo($asserter) ->object($asserter->getCall())->isEqualTo(new php\call($function, array())) ; } public function testBeforeMethodCall() { $this ->if($mock = new \mock\dummy()) ->and($asserter = new asserters\adapter(new asserter\generator())) ->then ->exception(function() use ($asserter, $mock) { $asserter->beforeMethodCall(uniqid(), $mock); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Adapter is undefined') ->if($asserter->setWith($adapter = new test\adapter())) ->then ->object($asserter->beforeMethodCall('foo', $mock))->isEqualTo($beforeMethodCall = new asserters\adapter\call\mock($asserter, $mock, 'foo')) ->array($asserter->getBeforeMethodCalls())->isEqualTo(array($beforeMethodCall)) ->object($asserter->beforeMethodCall('bar', $mock))->isEqualTo($otherBeforeMethodCall = new asserters\adapter\call\mock($asserter, $mock, 'bar')) ->array($asserter->getBeforeMethodCalls())->isEqualTo(array($beforeMethodCall, $otherBeforeMethodCall)) ; } public function testWithAnyMethodCallsBefore() { $this ->if($asserter = new asserters\adapter(new asserter\generator())) ->then ->array($asserter->getBeforeMethodCalls())->isEmpty() ->object($asserter->withAnyMethodCallsBefore())->isIdenticalTo($asserter) ->array($asserter->getBeforeMethodCalls())->isEmpty() ->if($asserter->setWith($adapter = new test\adapter())) ->and($asserter->beforeMethodCall(uniqid(), new \mock\dummy())) ->then ->array($asserter->getBeforeMethodCalls())->isNotEmpty() ->object($asserter->withAnyMethodCallsBefore())->isIdenticalTo($asserter) ->array($asserter->getBeforeMethodCalls())->isEmpty() ->if($asserter->beforeMethodCall($method1 = uniqid(), new \mock\dummy())->beforeMethodCall($method2 = uniqid(), new \mock\dummy())) ->then ->array($asserter->getBeforeMethodCalls())->isNotEmpty() ->object($asserter->withAnyMethodCallsBefore())->isIdenticalTo($asserter) ->array($asserter->getBeforeMethodCalls())->isEmpty() ; } public function testAfterMethodCall() { $this ->if($mock = new \mock\dummy()) ->and($asserter = new asserters\adapter(new asserter\generator())) ->then ->exception(function() use ($asserter, $mock) { $asserter->afterMethodCall(uniqid(), $mock); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Adapter is undefined') ->if($asserter->setWith($adapter = new test\adapter())) ->then ->object($asserter->afterMethodCall('foo', $mock))->isEqualTo($afterMethodCall = new asserters\adapter\call\mock($asserter, $mock, 'foo')) ->array($asserter->getAfterMethodCalls())->isEqualTo(array($afterMethodCall)) ->object($asserter->afterMethodCall('bar', $mock))->isEqualTo($otherAfterMethodCall = new asserters\adapter\call\mock($asserter, $mock, 'bar')) ->array($asserter->getAfterMethodCalls())->isEqualTo(array($afterMethodCall, $otherAfterMethodCall)) ; } public function testWithAnyMethodCallsAfter() { $this ->if($asserter = new asserters\adapter(new asserter\generator())) ->then ->array($asserter->getAfterMethodCalls())->isEmpty() ->object($asserter->withAnyMethodCallsAfter())->isIdenticalTo($asserter) ->array($asserter->getAfterMethodCalls())->isEmpty() ->if($asserter->setWith($adapter = new test\adapter())) ->and($asserter->afterMethodCall(uniqid(), new \mock\dummy())) ->then ->array($asserter->getAfterMethodCalls())->isNotEmpty() ->object($asserter->withAnyMethodCallsAfter())->isIdenticalTo($asserter) ->array($asserter->getAfterMethodCalls())->isEmpty() ->if($asserter ->afterMethodCall($method1 = uniqid(), new \mock\dummy()) ->afterMethodCall($method2 = uniqid(), new \mock\dummy()) ) ->then ->array($asserter->getAfterMethodCalls())->isNotEmpty() ->object($asserter->withAnyMethodCallsAfter())->isIdenticalTo($asserter) ->array($asserter->getAfterMethodCalls())->isEmpty() ; } public function testBeforeFunctionCall() { $this ->if($mock = new \mock\dummy()) ->and($asserter = new asserters\adapter(new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->beforeFunctionCall(uniqid(), new test\adapter()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Adapter is undefined') ->if($asserter->setWith($adapter = new test\adapter())) ->then ->object($asserter->beforeFunctionCall('foo'))->isEqualTo($beforeFunctionCall = new asserters\adapter\call\adapter($asserter, $adapter, 'foo')) ->array($asserter->getBeforeFunctionCalls())->isEqualTo(array($beforeFunctionCall)) ->object($asserter->beforeFunctionCall('bar'))->isEqualTo($otherBeforeFunctionCall = new asserters\adapter\call\adapter($asserter, $adapter, 'bar')) ->array($asserter->getBeforeFunctionCalls())->isEqualTo(array($beforeFunctionCall, $otherBeforeFunctionCall)) ; } public function testWithAnyFunctionCallsBefore() { $this ->if($asserter = new asserters\adapter(new asserter\generator())) ->then ->array($asserter->getBeforeFunctionCalls())->isEmpty() ->object($asserter->withAnyFunctionCallsBefore())->isIdenticalTo($asserter) ->array($asserter->getBeforeFunctionCalls())->isEmpty() ->if($asserter->setWith($adapter = new test\adapter())) ->and($asserter->beforeFunctionCall(uniqid())) ->then ->array($asserter->getBeforeFunctionCalls())->isNotEmpty() ->object($asserter->withAnyFunctionCallsBefore())->isIdenticalTo($asserter) ->array($asserter->getBeforeFunctionCalls())->isEmpty() ->if($asserter ->beforeFunctionCall($method1 = uniqid()) ->beforeFunctionCall($method2 = uniqid()) ) ->then ->array($asserter->getBeforeFunctionCalls())->isNotEmpty() ->object($asserter->withAnyFunctionCallsBefore())->isIdenticalTo($asserter) ->array($asserter->getBeforeFunctionCalls())->isEmpty() ; } public function testAfterFunctionCall() { $this ->if($mock = new \mock\dummy()) ->and($asserter = new asserters\adapter(new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->afterFunctionCall(uniqid(), new test\adapter()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Adapter is undefined') ->if($asserter->setWith($adapter = new test\adapter())) ->then ->object($asserter->afterFunctionCall('foo'))->isEqualTo($afterFunctionCall = new asserters\adapter\call\adapter($asserter, $adapter, 'foo')) ->array($asserter->getAfterFunctionCalls())->isEqualTo(array($afterFunctionCall)) ->object($asserter->afterFunctionCall('bar'))->isEqualTo($otherAfterFunctionCall = new asserters\adapter\call\adapter($asserter, $adapter, 'bar')) ->array($asserter->getAfterFunctionCalls())->isEqualTo(array($afterFunctionCall, $otherAfterFunctionCall)) ; } public function testWithAnyFunctionCallsAfter() { $this ->if($asserter = new asserters\adapter(new asserter\generator())) ->then ->array($asserter->getAfterFunctionCalls())->isEmpty() ->object($asserter->withAnyFunctionCallsAfter())->isIdenticalTo($asserter) ->array($asserter->getAfterFunctionCalls())->isEmpty() ->if($asserter->setWith($adapter = new test\adapter())) ->and($asserter->afterFunctionCall(uniqid())) ->then ->array($asserter->getAfterFunctionCalls())->isNotEmpty() ->object($asserter->withAnyFunctionCallsAfter())->isIdenticalTo($asserter) ->array($asserter->getAfterFunctionCalls())->isEmpty() ->if($asserter->afterFunctionCall($method1 = uniqid())->afterFunctionCall($method2 = uniqid())) ->then ->array($asserter->getAfterFunctionCalls())->isNotEmpty() ->object($asserter->withAnyFunctionCallsAfter())->isIdenticalTo($asserter) ->array($asserter->getAfterFunctionCalls())->isEmpty() ; } public function testOnce() { $this ->if($asserter = new asserters\adapter($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->once(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Adapter is undefined') ->if($asserter->setWith($adapter = new test\adapter())) ->then ->exception(function() use ($asserter) { $asserter->once(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Called function is undefined') ->if($asserter->call('md5')) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->once(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 0 time instead of 1'), $asserter->getCall())) ->if($call = new php\call('md5')) ->and($adapter->md5($firstArgument = uniqid())) ->then ->object($asserter->once())->isIdenticalTo($asserter) ->if($adapter->md5($secondArgument = uniqid())) ->then ->exception(function() use (& $otherLine, $asserter) { $otherLine = __LINE__; $asserter->once(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 2 times instead of 1'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($firstArgument)) . PHP_EOL . '[2] ' . $call->setArguments(array($secondArgument))) ->if($adapter->resetCalls()) ->and($asserter->withArguments($arg = uniqid())) ->and($adapter->md5($arg)) ->then ->object($asserter->once())->isIdenticalTo($asserter) ->if($asserter->withArguments(uniqid())) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->once(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 0 time instead of 1'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($arg))) ; } public function testTwice() { $this ->if($asserter = new asserters\adapter($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Adapter is undefined') ->if($asserter->setWith($adapter = new test\adapter())) ->then ->exception(function() use ($asserter) { $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Called function is undefined') ->if($asserter->call('md5')) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 0 time instead of 2'), $asserter->getCall())) ->if($call = new php\call('md5')) ->and($adapter->md5($firstArgument = uniqid())) ->then ->exception(function() use (& $otherLine, $asserter) { $otherLine = __LINE__; $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 1 time instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($firstArgument))) ->if($adapter->md5($secondArgument = uniqid())) ->then ->object($asserter->twice())->isIdenticalTo($asserter) ->if($adapter->md5($thirdArgument = uniqid())) ->then ->exception(function() use (& $otherLine, $asserter) { $otherLine = __LINE__; $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 3 times instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($firstArgument)) . PHP_EOL . '[2] ' . $call->setArguments(array($secondArgument)) . PHP_EOL . '[3] ' . $call->setArguments(array($thirdArgument))) ->if($adapter->resetCalls()) ->and($asserter->withArguments($arg = uniqid())) ->and($adapter->md5($arg)) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 1 time instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($arg))) ->if($asserter->withArguments(uniqid())) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 0 time instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($arg))) ; } public function testThrice() { $this ->if($asserter = new asserters\adapter($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Adapter is undefined') ->if($asserter->setWith($adapter = new test\adapter())) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Called function is undefined') ->if($asserter->call('md5')) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 0 time instead of 3'), $asserter->getCall())) ->if($call = new php\call('md5')) ->and($adapter->md5($firstArgument = uniqid())) ->then ->exception(function() use (& $otherLine, $asserter) { $otherLine = __LINE__; $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 1 time instead of 3'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($firstArgument))) ->if($adapter->md5($secondArgument = uniqid())) ->then ->exception(function() use (& $otherLine, $asserter) { $otherLine = __LINE__; $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 2 times instead of 3'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($firstArgument)) . PHP_EOL . '[2] ' . $call->setArguments(array($secondArgument))) ->if($adapter->md5($thirdArgument = uniqid())) ->then ->object($asserter->thrice())->isIdenticalTo($asserter) ->if($adapter->md5($fourthArgument = uniqid())) ->then ->exception(function() use (& $otherLine, $asserter) { $otherLine = __LINE__; $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 4 times instead of 3'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($firstArgument)) . PHP_EOL . '[2] ' . $call->setArguments(array($secondArgument)) . PHP_EOL . '[3] ' . $call->setArguments(array($thirdArgument)) . PHP_EOL . '[4] ' . $call->setArguments(array($fourthArgument))) ->if($adapter->resetCalls()) ->and($asserter->withArguments($arg = uniqid())) ->and($adapter->md5($arg)) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 1 time instead of 3'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($arg))) ->if($asserter->withArguments(uniqid())) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 0 time instead of 3'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($arg))) ; } public function testAtLeastOnce() { $this ->if($asserter = new asserters\adapter($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->atLeastOnce(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Adapter is undefined') ->if($asserter->setWith($adapter = new test\adapter())) ->then ->exception(function() use ($asserter) { $asserter->atLeastOnce(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Called function is undefined') ->if($asserter->call('md5')) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->atLeastOnce(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 0 time'), $asserter->getCall())) ->if($adapter->md5(uniqid())) ->then ->object($asserter->atLeastOnce())->isIdenticalTo($asserter) ->if($adapter->md5(uniqid())) ->then ->object($asserter->atLeastOnce())->isIdenticalTo($asserter) ->if($adapter->resetCalls()) ->and($asserter->withArguments($arg = uniqid())) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->atLeastOnce(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 0 time'), $asserter->getCall())) ->if($call = new php\call('md5')) ->and($adapter->md5($arg)) ->then ->object($asserter->atLeastOnce())->isIdenticalTo($asserter) ->if($asserter->withArguments(uniqid())) ->then ->exception(function() use (& $otherLine, $asserter) { $otherLine = __LINE__; $asserter->atLeastOnce(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 0 time'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($arg))) ; } public function testExactly() { $this ->if($asserter = new asserters\adapter($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->exactly(2); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Adapter is undefined') ->if($asserter->setWith($adapter = new test\adapter())) ->then ->exception(function() use ($asserter) { $asserter->exactly(2); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Called function is undefined') ->if($asserter->call('md5')) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->exactly(2); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 0 time instead of 2'), $asserter->getCall())) ->if($call = new php\call('md5')) ->and($adapter->md5($arg = uniqid())) ->then ->exception(function() use (& $otherLine, $asserter) { $otherLine = __LINE__; $asserter->exactly(2); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 1 time instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($arg))) ->if($adapter->md5($otherArg = uniqid())) ->then ->object($asserter->exactly(2))->isIdenticalTo($asserter) ->if($adapter->md5($anOtherArg = uniqid())) ->then ->exception(function() use (& $anotherLine, $asserter) { $anotherLine = __LINE__; $asserter->exactly(2); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 3 times instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($arg)) . PHP_EOL . '[2] ' . $call->setArguments(array($otherArg)) . PHP_EOL . '[3] ' . $call->setArguments(array($anOtherArg))) ->if($adapter->resetCalls()) ->and($asserter->withArguments($arg = uniqid())) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->exactly(2); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 0 time instead of 2'), $asserter->getCall())) ->if($adapter->md5($usedArg = uniqid())) ->then ->exception(function() use (& $otherLine, $asserter) { $otherLine = __LINE__; $asserter->exactly(2); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 0 time instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg))) ->if($adapter->md5($arg)) ->then ->exception(function() use (& $anotherLine, $asserter) { $anotherLine = __LINE__; $asserter->exactly(2); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 1 time instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[2] ' . $call->setArguments(array($arg))) ->if($adapter->md5($arg)) ->then ->object($asserter->exactly(2))->isIdenticalTo($asserter) ->if($adapter->md5($arg)) ->then ->exception(function() use (& $anAnotherLine, $asserter) { $anAnotherLine = __LINE__; $asserter->exactly(2); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 3 times instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[2] ' . $call->setArguments(array($arg)) . PHP_EOL . '[3] ' . $call->setArguments(array($arg)) . PHP_EOL . '[4] ' . $call->setArguments(array($arg))) ; } public function testNever() { $this ->if($asserter = new asserters\adapter($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->never(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Adapter is undefined') ->if($asserter->setWith($adapter = new test\adapter())) ->then ->exception(function() use ($asserter) { $asserter->never(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Called function is undefined') ->if($call = new php\call('md5')) ->and($asserter->call('md5')) ->then ->object($asserter->never())->isIdenticalTo($asserter) ->if($adapter->md5($usedArg = uniqid())) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->never(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 1 time instead of 0'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg))) ->if($adapter->resetCalls()) ->and($asserter->withArguments($arg = uniqid())) ->then ->object($asserter->never())->isIdenticalTo($asserter) ->if($adapter->md5($arg)) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->never(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 1 time instead of 0'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($arg))) ->if($adapter->md5($arg)) ->then ->exception(function() use (& $otherLine, $asserter) { $otherLine = __LINE__; $asserter->never(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('function %s is called 2 times instead of 0'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($arg)) . PHP_EOL . '[2] ' . $call->setArguments(array($arg))) ->if($asserter->withArguments(uniqid())) ->then ->object($asserter->never())->isIdenticalTo($asserter) ; } } testedClass->isSubclassOf('mageekguy\atoum\asserters\variable'); } public function test__construct() { $this ->if($asserter = new asserters\boolean($generator = new asserter\generator())) ->then ->variable($asserter->getValue())->isNull() ->object($asserter->getLocale())->isIdenticalTo($generator->getLocale()) ->object($asserter->getGenerator())->isIdenticalTo($generator) ->boolean($asserter->wasSet())->isFalse() ; } public function testIsTrue() { $this ->if($asserter = new asserters\boolean($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->isTrue(); }) ->isInstanceOf('logicException') ->hasMessage('Value is undefined') ->if($asserter->setWith(true)) ->then ->object($asserter->isTrue())->isIdenticalTo($asserter) ->if($asserter->setWith(false)) ->and($diff = new diffs\variable()) ->then ->exception(function() use ($asserter) { $asserter->isTrue(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not true'), $asserter) . PHP_EOL . $diff->setReference(true)->setData(false)) ->if($asserter->setWith(true)) ->then ->object($asserter->isTrue)->isIdenticalTo($asserter) ->if($asserter->setWith(false)) ->and($diff = new diffs\variable()) ->then ->exception(function() use ($asserter) { $asserter->isTrue; }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not true'), $asserter) . PHP_EOL . $diff->setReference(true)->setData(false)) ; } public function testIsFalse() { $this ->if($asserter = new asserters\boolean($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->isFalse(); }) ->isInstanceOf('logicException') ->hasMessage('Value is undefined') ->if($asserter->setWith(false)) ->then ->object($asserter->isFalse())->isIdenticalTo($asserter) ->if($asserter->setWith(true)) ->and($diff = new diffs\variable()) ->then ->exception(function() use ($asserter) { $asserter->isFalse(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not false'), $asserter) . PHP_EOL . $diff->setReference(false)->setData(true)) ->if($asserter->setWith(false)) ->then ->object($asserter->isFalse)->isIdenticalTo($asserter) ->if($asserter->setWith(true)) ->and($diff = new diffs\variable()) ->then ->exception(function() use ($asserter) { $asserter->isFalse; }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not false'), $asserter) . PHP_EOL . $diff->setReference(false)->setData(true)) ; } public function testSetWith() { $this ->if($asserter = new asserters\boolean($generator = new asserter\generator())) ->then ->assert('Set the asserter with something else than a boolean throw an exception') ->exception(function() use (& $line, $asserter, & $value) { $line = __LINE__; $asserter->setWith($value = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not a boolean'), $asserter->getTypeOf($value))) ->assert('The asserter was returned when it set with a boolean') ->string($asserter->getValue())->isEqualTo($value) ->object($asserter->setWith(true))->isIdenticalTo($asserter) ->boolean($asserter->getValue())->isTrue() ; } } testedClass->isSubclassOf('mageekguy\atoum\asserters\string'); } public function test__construct() { $this ->if($asserter = new asserters\castToString($generator = new asserter\generator())) ->then ->object($asserter->getLocale())->isIdenticalTo($generator->getLocale()) ->object($asserter->getGenerator())->isIdenticalTo($generator) ->variable($asserter->getValue())->isNull() ->boolean($asserter->wasSet())->isFalse() ; } public function testSetWith() { $this ->if($asserter = new asserters\castToString($generator = new asserter\generator())) ->then ->assert('Set the asserter with something else than an object throw an exception') ->exception(function() use (& $line, $asserter, & $value) { $line = __LINE__; $asserter->setWith($value = rand(- PHP_INT_MAX, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not an object'), $asserter->getTypeOf($value))) ->integer($asserter->getValue())->isEqualTo($value) ->variable($asserter->getCharlist())->isNull() ->assert('The asserter was returned when it set with an object') ->object($asserter->setWith($object = new \exception()))->isIdenticalTo($asserter) ->string($asserter->getValue())->isEqualTo((string) $object) ->variable($asserter->getCharlist())->isNull() ->assert('It is possible to define a character list') ->object($asserter->setWith($object = new \exception, null, $charlist = "\010"))->isIdenticalTo($asserter) ->string($asserter->getValue())->isEqualTo((string) $object) ->string($asserter->getCharlist())->isEqualTo($charlist) ; } public function testToString() { $this ->if($asserter = new asserters\castToString(new asserter\generator())) ->and($asserter->setWith($object = new \exception())) ->then ->castToString($asserter)->isEqualTo('string(' . strlen(($string = (string) $object)) . ') \'' . $string . '\'') ; } } testedClass->isSubclassOf('mageekguy\atoum\asserters\object'); } public function test__construct() { $this ->if($asserter = new asserters\dateInterval($generator = new asserter\generator())) ->then ->object($asserter->getLocale())->isIdenticalTo($generator->getLocale()) ->object($asserter->getGenerator())->isIdenticalTo($generator) ->variable($asserter->getValue())->isNull() ->boolean($asserter->wasSet())->isFalse() ; } public function testSetWith() { $this ->if($asserter = new asserters\dateInterval($generator = new asserter\generator())) ->assert('Set the asserter with something else than a date interval trown an exception') ->exception(function() use ($asserter, & $value) { $asserter->setWith($value = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not an instance of \\dateInterval'), $asserter->getTypeOf($value))) ->string($asserter->getValue())->isEqualTo($value) ->assert('The asserter was returned when it set with a date time') ->object($asserter->setWith($value = new \DateInterval('P0D')))->isIdenticalTo($asserter) ->object($asserter->getValue())->isIdenticalTo($value) ->assert('It is possible to disable type checking') ->object($asserter->setWith($value = uniqid(), false))->isIdenticalTo($asserter) ; } public function testIsGreaterThan() { $this ->if($asserter = new asserters\dateInterval($generator = new asserter\generator())) ->exception(function() use ($asserter) { $asserter->isGreaterThan(new \DateInterval('P1D')); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Interval is undefined') ->if($asserter->setWith(new \DateInterval('P1Y'))) ->then ->object($asserter->isGreaterThan(new \DateInterval('P1M')))->isIdenticalTo($asserter) ->exception(function() use ($asserter, & $interval) { $asserter->isGreaterThan($interval = new \DateInterval('P2Y')); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage('Interval ' . $asserter . ' is not greater than ' . $interval->format('%Y/%M/%D %H:%I:%S')) ->exception(function() use ($asserter, & $interval) { $asserter->isGreaterThan($interval = new \DateInterval('P1Y')); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage('Interval ' . $asserter . ' is not greater than ' . $interval->format('%Y/%M/%D %H:%I:%S')) ; } public function testIsGreaterThanOrEqualTo() { $this ->if($asserter = new asserters\dateInterval($generator = new asserter\generator())) ->exception(function() use ($asserter) { $asserter->isGreaterThanOrEqualTo(new \DateInterval('P1D')); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Interval is undefined') ->if($asserter->setWith(new \DateInterval('P1Y'))) ->then ->object($asserter->isGreaterThanOrEqualTo(new \DateInterval('P1M')))->isIdenticalTo($asserter) ->object($asserter->isGreaterThanOrEqualTo(new \DateInterval('P1Y')))->isIdenticalTo($asserter) ->exception(function() use ($asserter, & $interval) { $asserter->isGreaterThanOrEqualTo($interval = new \DateInterval('P2Y')); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage('Interval ' . $asserter . ' is not greater than or equal to ' . $interval->format('%Y/%M/%D %H:%I:%S')) ; } public function testIsZero() { $this ->if($asserter = new asserters\dateInterval($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->isZero(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Interval is undefined') ->if($asserter->setWith(new \DateInterval('P0Y'))) ->then ->object($asserter->isZero())->isIdenticalTo($asserter) ->if($asserter->setWith($interval = new \DateInterval('P1Y'))) ->then ->exception(function() use ($asserter) { $asserter->isZero(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage('Interval ' . $asserter . ' is not equal to zero') ; } public function testIsLessThan() { $this ->if($asserter = new asserters\dateInterval($generator = new asserter\generator())) ->exception(function() use ($asserter) { $asserter->isLessThan(new \DateInterval('P1D')); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Interval is undefined') ->if($asserter->setWith(new \dateInterval('P2D'))) ->then ->object($asserter->isLessThan(new \dateInterval('P1M')))->isIdenticalTo($asserter) ->exception(function() use ($asserter, & $interval) { $asserter->isLessThan($interval = new \dateInterval('P1D')); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage('Interval ' . $asserter . ' is not less than ' . $interval->format('%Y/%M/%D %H:%I:%S')) ->exception(function() use ($asserter, & $interval) { $asserter->isLessThan($interval = new \dateInterval('P2D')); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage('Interval ' . $asserter . ' is not less than ' . $interval->format('%Y/%M/%D %H:%I:%S')) ; } public function testIsLessThanOrEqualTo() { $this ->if($asserter = new asserters\dateInterval($generator = new asserter\generator())) ->exception(function() use ($asserter) { $asserter->isLessThanOrEqualTo(new \DateInterval('P1D')); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Interval is undefined') ->if($asserter->setWith(new \dateInterval('P2D'))) ->then ->object($asserter->isLessThanOrEqualTo(new \dateInterval('P1M')))->isIdenticalTo($asserter) ->object($asserter->isLessThanOrEqualTo(new \dateInterval('P2D')))->isIdenticalTo($asserter) ->exception(function() use ($asserter, & $interval) { $asserter->isLessThanOrEqualTo($interval = new \dateInterval('P1D')); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage('Interval ' . $asserter . ' is not less than or equal to ' . $interval->format('%Y/%M/%D %H:%I:%S')) ; } public function testIsEqualTo() { $this ->if($asserter = new asserters\dateInterval($generator = new asserter\generator())) ->exception(function() use ($asserter) { $asserter->isEqualTo(new \dateInterval('P1D')); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Interval is undefined') ->if($asserter->setWith(new \DateInterval('P1D'))) ->then ->object($asserter->isEqualTo(new \DateInterval('P1D')))->isIdenticalTo($asserter) ->exception(function() use ($asserter, & $interval) { $asserter->isEqualTo($interval = new \dateInterval('PT1S')); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage('Interval ' . $asserter . ' is not equal to ' . $interval->format('%Y/%M/%D %H:%I:%S')) ->exception(function() use ($asserter, & $interval) { $asserter->isEqualTo($interval = new \dateInterval('P2D')); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage('Interval ' . $asserter . ' is not equal to ' . $interval->format('%Y/%M/%D %H:%I:%S')) ; } } testedClass->isSubclassOf('mageekguy\atoum\asserters\object'); } public function test__construct() { $this ->if($asserter = new asserters\dateTime($generator = new asserter\generator())) ->then ->object($asserter->getLocale())->isIdenticalTo($generator->getLocale()) ->object($asserter->getGenerator())->isIdenticalTo($generator) ->variable($asserter->getValue())->isNull() ->boolean($asserter->wasSet())->isFalse() ; } public function testSetWith() { $this ->if($asserter = new asserters\dateTime($generator = new asserter\generator())) ->assert('Set the asserter with something else than a date time trown an exception') ->exception(function() use ($asserter, & $value) { $asserter->setWith($value = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not an instance of \\dateTime'), $asserter->getTypeOf($value))) ->string($asserter->getValue())->isEqualTo($value) ->assert('The asserter was returned when it set with a date time') ->object($asserter->setWith($value = new \DateTime()))->isIdenticalTo($asserter) ->object($asserter->getValue())->isIdenticalTo($value) ->assert('It is possible to disable type checking') ->object($asserter->setWith($value = uniqid(), false))->isIdenticalTo($asserter) ->string($asserter->getValue())->isEqualTo($value) ; } public function testHasTimezone() { $this ->if($asserter = new asserters\dateTime($generator = new asserter\generator())) ->exception(function() use ($asserter) { $asserter->hasSize(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Instance of \\dateTime is undefined') ->if($asserter->setWith($dateTime = new \DateTime('now', $timezone = new \DateTimezone('Europe/Paris')))) ->then ->exception(function() use (& $line, & $requiredTimezone, $asserter) { $line = __LINE__; $asserter->hasTimezone($requiredTimezone = new \DateTimezone('Europe/London')); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('Timezone is %s instead of %s'), $timezone->getName(), $requiredTimezone->getName())) ->object($asserter->hasTimezone($dateTime->getTimezone()))->isIdenticalTo($asserter); ; } public function testHasYear() { $this ->if($asserter = new asserters\dateTime($generator = new asserter\generator())) ->exception(function() use ($asserter) { $asserter->hasYear(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Instance of \\dateTime is undefined') ->if($asserter->setWith($dateTime = new \DateTime('1976-10-06'))) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->hasYear(1981); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('Year is %s instead of %s'), 1976, 1981)) ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->hasYear(76); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('Year is %s instead of %s'), 1976, 76)) ->object($asserter->hasYear('1976'))->isIdenticalTo($asserter) ->object($asserter->hasYear(1976))->isIdenticalTo($asserter) ; } public function testHasMonth() { $this ->if($asserter = new asserters\dateTime($generator = new asserter\generator())) ->exception(function() use ($asserter) { $asserter->hasMonth(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Instance of \\dateTime is undefined') ->if($asserter->setWith($dateTime = new \DateTime('1976-09-06'))) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->hasMonth(1); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('Month is %02d instead of %02d'), 9, 1)) ->object($asserter->hasMonth(9))->isIdenticalTo($asserter) ->if($asserter->setWith($dateTime = new \DateTime('1980-08-14'))) ->then ->object($asserter->hasMonth('08'))->isIdenticalTo($asserter) ->object($asserter->hasMonth('8'))->isIdenticalTo($asserter) ->object($asserter->hasMonth(8))->isIdenticalTo($asserter) ; } public function testHasDay() { $this ->if($asserter = new asserters\dateTime($generator = new asserter\generator())) ->exception(function() use ($asserter) { $asserter->hasDay(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Instance of \\dateTime is undefined') ->if($asserter->setWith($dateTime = new \DateTime('1976-10-06'))) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->hasDay(1); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('Day is %02d instead of %02d'), 6, 1)) ->object($asserter->hasDay('06'))->isIdenticalTo($asserter) ->object($asserter->hasDay('6'))->isIdenticalTo($asserter) ->object($asserter->hasDay(6))->isIdenticalTo($asserter) ; } public function testHasDate() { $this ->if($asserter = new asserters\dateTime($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasDate(1976, 10, 6); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Instance of \\dateTime is undefined') ->if($asserter->setWith($dateTime = new \DateTime('1976-10-06'))) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->hasDate(1980, 8, 14); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('Date is %s instead of %s'), '1976-10-06', '1980-08-14')) ->object($asserter->hasDate(1976, 10, 6))->isIdenticalTo($asserter) ->object($asserter->hasDate('1976', '10', '6'))->isIdenticalTo($asserter) ->object($asserter->hasDate('1976', '10', '06'))->isIdenticalTo($asserter) ; } public function testHasHours() { $this ->if($asserter = new asserters\dateTime($generator = new asserter\generator())) ->exception(function() use ($asserter) { $asserter->hasHours(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Instance of \\dateTime is undefined') ->if($asserter->setWith($dateTime = new \DateTime('01:02:03'))) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->hasHours(2); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('Hours are %02d instead of %02d'), 1, 2)) ->object($asserter->hasHours('01'))->isIdenticalTo($asserter) ->object($asserter->hasHours('1'))->isIdenticalTo($asserter) ->object($asserter->hasHours(1))->isIdenticalTo($asserter) ; } public function testHasMinutes() { $this ->if($asserter = new asserters\dateTime($generator = new asserter\generator())) ->exception(function() use ($asserter) { $asserter->hasMinutes(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Instance of \\dateTime is undefined') ->if($asserter->setWith($dateTime = new \DateTime('01:02:03'))) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->hasMinutes(1); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('Minutes are %02d instead of %02d'), 2, 1)) ->object($asserter->hasMinutes('02'))->isIdenticalTo($asserter) ->object($asserter->hasMinutes('2'))->isIdenticalTo($asserter) ->object($asserter->hasMinutes(2))->isIdenticalTo($asserter) ; } public function testHasSeconds() { $this ->if($asserter = new asserters\dateTime($generator = new asserter\generator())) ->exception(function() use ($asserter) { $asserter->hasSeconds(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Instance of \\dateTime is undefined') ->if($asserter->setWith($dateTime = new \DateTime('01:02:03'))) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->hasSeconds(1); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('Seconds are %02d instead of %02d'), 3, 1)) ->object($asserter->hasSeconds('03'))->isIdenticalTo($asserter) ->object($asserter->hasSeconds('3'))->isIdenticalTo($asserter) ->object($asserter->hasSeconds(3))->isIdenticalTo($asserter) ; } public function testHasTime() { $this ->if($asserter = new asserters\dateTime($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasTime(1, 2, 3); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Instance of \\dateTime is undefined') ->if($asserter->setWith($dateTime = new \DateTime('01:02:03'))) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->hasTime(4, 5, 6); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('Time is %s instead of %s'), '01:02:03', '04:05:06')) ->object($asserter->hasTime('01', '02', '03'))->isIdenticalTo($asserter) ->object($asserter->hasTime('1', '2', '3'))->isIdenticalTo($asserter) ->object($asserter->hasTime(1, 2, 3))->isIdenticalTo($asserter) ; } public function testHasDateAndTime() { $this ->if($asserter = new asserters\dateTime($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasDateAndTime(1981, 2, 13, 1, 2, 3); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Instance of \\dateTime is undefined') ->if($asserter->setWith($dateTime = new \DateTime('1981-02-13 01:02:03'))) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->hasDateAndTime(1900, 1, 1, 4, 5, 6); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('Datetime is %s instead of %s'), '1981-02-13 01:02:03', '1900-01-01 04:05:06')) ->object($asserter->hasDateAndTime('1981', '02', '13', '01', '02', '03'))->isIdenticalTo($asserter) ->object($asserter->hasDateAndTime('1981', '2', '13', '1', '2', '3'))->isIdenticalTo($asserter) ->object($asserter->hasDateAndTime(1981, 2, 13, 1, 2, 3))->isIdenticalTo($asserter) ; } } testedClass->extends('mageekguy\atoum\asserter'); } public function test__construct() { $this ->if($asserter = new testedClass()) ->then ->object($asserter->getGenerator())->isEqualTo(new asserter\generator()) ->object($asserter->getLocale())->isIdenticalTo($asserter->getGenerator()->getLocale()) ->object($asserter->getScore())->isInstanceOf('mageekguy\atoum\test\score') ->variable($asserter->getMessage())->isNull() ->variable($asserter->getType())->isNull() ->if($asserter = new testedClass($generator = new asserter\generator(), $score = new atoum\test\score())) ->then ->object($asserter->getGenerator())->isIdenticalTo($generator) ->object($asserter->getLocale())->isIdenticalTo($asserter->getGenerator()->getLocale()) ->object($asserter->getScore())->isIdenticalTo($score) ->variable($asserter->getMessage())->isNull() ->variable($asserter->getType())->isNull() ; } public function testInitWithTest() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->object($asserter->setWithTest($this))->isIdenticalTo($asserter) ->object($asserter->getScore())->isIdenticalTo($this->getScore()) ; } public function testGetAsString() { $this ->string(testedClass::getAsString(E_ERROR))->isEqualTo('E_ERROR') ->string(testedClass::getAsString(E_WARNING))->isEqualTo('E_WARNING') ->string(testedClass::getAsString(E_PARSE))->isEqualTo('E_PARSE') ->string(testedClass::getAsString(E_NOTICE))->isEqualTo('E_NOTICE') ->string(testedClass::getAsString(E_CORE_ERROR))->isEqualTo('E_CORE_ERROR') ->string(testedClass::getAsString(E_CORE_WARNING))->isEqualTo('E_CORE_WARNING') ->string(testedClass::getAsString(E_COMPILE_ERROR))->isEqualTo('E_COMPILE_ERROR') ->string(testedClass::getAsString(E_COMPILE_WARNING))->isEqualTo('E_COMPILE_WARNING') ->string(testedClass::getAsString(E_USER_ERROR))->isEqualTo('E_USER_ERROR') ->string(testedClass::getAsString(E_USER_WARNING))->isEqualTo('E_USER_WARNING') ->string(testedClass::getAsString(E_USER_NOTICE))->isEqualTo('E_USER_NOTICE') ->string(testedClass::getAsString(E_STRICT))->isEqualTo('E_STRICT') ->string(testedClass::getAsString(E_RECOVERABLE_ERROR))->isEqualTo('E_RECOVERABLE_ERROR') ->string(testedClass::getAsString(E_DEPRECATED))->isEqualTo('E_DEPRECATED') ->string(testedClass::getAsString(E_USER_DEPRECATED))->isEqualTo('E_USER_DEPRECATED') ->string(testedClass::getAsString(E_ALL))->isEqualTo('E_ALL') ->string(testedClass::getAsString('unknown error'))->isEqualTo('UNKNOWN') ; } public function testSetWith() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->object($asserter->setWith(null, null))->isIdenticalTo($asserter) ->variable($asserter->getMessage())->isNull() ->variable($asserter->getType())->isNull() ->object($asserter->setWith($message = uniqid(), null))->isIdenticalTo($asserter) ->string($asserter->getMessage())->isEqualTo($message) ->variable($asserter->getType())->isNull() ->object($asserter->setWith($message = uniqid(), $type = rand(0, PHP_INT_MAX)))->isIdenticalTo($asserter) ->string($asserter->getMessage())->isEqualTo($message) ->integer($asserter->getType())->isEqualTo($type) ; } public function testExists() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use (& $line, $asserter) { $asserter->exists(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($generator->getLocale()->_('error does not exist')) ->if($asserter->getScore()->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), rand(0, PHP_INT_MAX), uniqid(), uniqid(), rand(1, PHP_INT_MAX))) ->then ->object($asserter->exists())->isIdenticalTo($asserter) ->array($asserter->getScore()->getErrors())->isEmpty() ->if($asserter->setWith($message = uniqid(), null)) ->then ->exception(function() use (& $line, $asserter) { $asserter->exists(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('error with message \'%s\' does not exist'), $message)) ->if($asserter->getScore()->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), rand(0, PHP_INT_MAX), $message, uniqid(), rand(1, PHP_INT_MAX))) ->then ->object($asserter->exists())->isIdenticalTo($asserter) ->array($asserter->getScore()->getErrors())->isEmpty() ->if($asserter->setWith($message = uniqid(), $type = E_USER_ERROR)) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->exists(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('error of type %s with message \'%s\' does not exist'), testedClass::getAsString($type), $message)) ->if($asserter->getScore()->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), $type, $message, uniqid(), rand(1, PHP_INT_MAX))) ->then ->object($asserter->exists())->isIdenticalTo($asserter) ->array($asserter->getScore()->getErrors())->isEmpty() ->if($asserter->setWith(null, $type = E_USER_ERROR)) ->then ->exception(function() use (& $line, $asserter) { $line = __LINE__; $asserter->exists(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('error of type %s does not exist'), testedClass::getAsString($type))) ->if($asserter->getScore()->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), $type, uniqid(), uniqid(), rand(1, PHP_INT_MAX))) ->then ->object($asserter->exists())->isIdenticalTo($asserter) ->array($asserter->getScore()->getErrors())->isEmpty() ->if($asserter->getScore()->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), rand(1, PHP_INT_MAX), $message = uniqid() . 'FOO' . uniqid(), uniqid(), rand(1, PHP_INT_MAX))) ->and($asserter->withPattern('/FOO/')->withType(null)) ->then ->object($asserter->exists())->isIdenticalTo($asserter) ->array($asserter->getScore()->getErrors())->isEmpty() ; } public function testWithType() { $this ->if($asserter = new testedClass(new asserter\generator())) ->then ->object($asserter->withType($type = rand(1, PHP_INT_MAX)))->isIdenticalTo($asserter) ->integer($asserter->getType())->isEqualTo($type) ; } public function testWithAnyType() { $this ->if($asserter = new testedClass(new asserter\generator())) ->and($asserter->withType(rand(1, PHP_INT_MAX))) ->then ->variable($asserter->getType())->isNotNull() ->object($asserter->withAnyType())->isIdenticalTo($asserter) ->variable($asserter->getType())->isNull() ; } public function testWithMessage() { $this ->if($asserter = new testedClass(new asserter\generator())) ->then ->object($asserter->withMessage($message = uniqid()))->isIdenticalTo($asserter) ->string($asserter->getMessage())->isEqualTo($message) ->boolean($asserter->messageIsPattern())->isFalse() ; } public function testWithPattern() { $this ->if($asserter = new testedClass(new asserter\generator())) ->then ->boolean($asserter->messageIsPattern())->isFalse() ->object($asserter->withPattern($pattern = uniqid()))->isIdenticalTo($asserter) ->string($asserter->getMessage())->isEqualTo($pattern) ->boolean($asserter->messageIsPattern())->isTrue() ; } public function testWithAnyMessage() { $this ->if($asserter = new testedClass(new asserter\generator())) ->and($asserter->withMessage(uniqid())) ->then ->variable($asserter->getMessage())->isNotNull() ->boolean($asserter->messageIsPattern())->isFalse() ->object($asserter->withAnyMessage())->isIdenticalTo($asserter) ->variable($asserter->getMessage())->isNull() ->boolean($asserter->messageIsPattern())->isFalse() ->if($asserter->withPattern(uniqid())) ->then ->variable($asserter->getMessage())->isNotNull() ->boolean($asserter->messageIsPattern())->isTrue() ->object($asserter->withAnyMessage())->isIdenticalTo($asserter) ->variable($asserter->getMessage())->isNull() ->boolean($asserter->messageIsPattern())->isFalse() ; } public function testSetScore() { $this ->if($asserter = new testedClass()) ->then ->object($asserter->setScore($score = new atoum\test\score()))->isIdenticalTo($asserter) ->object($asserter->getScore())->isIdenticalTo($score) ->object($asserter->setScore())->isIdenticalTo($asserter) ->object($asserter->getScore()) ->isNotIdenticalTo($score) ->isInstanceOf('mageekguy\atoum\score') ; } } testedClass->isSubclassOf('mageekguy\atoum\asserter'); } public function test__construct() { $this ->if($asserter = new asserters\exception($generator = new asserter\generator())) ->then ->object($asserter->getLocale())->isIdenticalTo($generator->getLocale()) ->object($asserter->getGenerator())->isIdenticalTo($generator) ->variable($asserter->getValue())->isNull() ->boolean($asserter->wasSet())->isFalse() ; } public function testSetWith() { $this ->if($asserter = new asserters\exception($generator = new asserter\generator())) ->then ->assert('It is impossible to set asserter with something else than an exception') ->exception(function() use (& $line, $asserter, & $value) { $line = __LINE__; $asserter->setWith($value = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not an exception'), $asserter->getTypeOf($value))) ->string($asserter->getValue())->isEqualTo($value) ->assert('The asserter was returned when it set with an exception') ->object($asserter->setWith($value = new \exception()))->isIdenticalTo($asserter) ->exception($asserter->getValue())->isIdenticalTo($value) ; } public function testIsInstanceOf() { $this ->if($asserter = new asserters\exception($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasSize(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Exception is undefined') ->if($asserter->setWith(new \exception())) ->then ->object($asserter->isInstanceOf('\Exception'))->isIdenticalTo($asserter) ->object($asserter->isInstanceOf('Exception'))->isIdenticalTo($asserter) ->object($asserter->isInstanceOf('\exception'))->isIdenticalTo($asserter) ->object($asserter->isInstanceOf('exception'))->isIdenticalTo($asserter) ->exception(function() use ($asserter) { $asserter->isInstanceOf(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument') ->hasMessage('Argument of mageekguy\atoum\asserters\exception::isInstanceOf() must be a \exception instance or an exception class name') ->exception(function() use ($asserter) { $asserter->isInstanceOf('mageekguy\atoum\exceptions\runtime'); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not an instance of mageekguy\atoum\exceptions\runtime'), $asserter)) ; } public function testHasCode() { $this ->if($asserter = new asserters\exception($generator = new asserter\generator())) ->then ->boolean($asserter->wasSet())->isFalse() ->exception(function() use ($asserter) { $asserter->hasCode(rand(- PHP_INT_MAX, PHP_INT_MAX)); }) ->isInstanceOf('logicException') ->hasMessage('Exception is undefined') ->if($asserter->setWith(new atoum\exceptions\runtime(uniqid(), $code = rand(2, PHP_INT_MAX)))) ->then ->exception(function() use ($asserter, & $otherCode) { $asserter->hasCode($otherCode = 1); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('code is %d instead of %d'), $code, $otherCode)) ->object($asserter->hasCode($code))->isIdenticalTo($asserter) ; } public function testHasMessage() { $this ->if($asserter = new asserters\exception($generator = new asserter\generator())) ->then ->boolean($asserter->wasSet())->isFalse() ->exception(function() use ($asserter) { $asserter->hasMessage(uniqid()); }) ->isInstanceOf('logicException') ->hasMessage('Exception is undefined') ->if($asserter->setWith(new atoum\exceptions\runtime($message = uniqid()))) ->then ->exception(function() use ($asserter, & $otherMessage) { $asserter->hasMessage($otherMessage = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('message \'%s\' is not identical to \'%s\''), $message, $otherMessage)) ->object($asserter->hasMessage($message))->isIdenticalTo($asserter) ; } public function testHasNestedException() { $this ->if($asserter = new asserters\exception($generator = new asserter\generator())) ->then ->boolean($asserter->wasSet())->isFalse() ->exception(function() use ($asserter) { $asserter->hasNestedException(); }) ->isInstanceOf('logicException') ->hasMessage('Exception is undefined') ->if($asserter->setWith(new atoum\exceptions\runtime('', 0))) ->then ->exception(function() use ($asserter) { $asserter->hasNestedException(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($generator->getLocale()->_('exception does not contain any nested exception')) ->exception(function() use ($asserter) { $asserter->hasNestedException(new \exception()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($generator->getLocale()->_('exception does not contain this nested exception')) ->if($asserter->setWith(new atoum\exceptions\runtime('', 0, $nestedException = new \exception()))) ->then ->object($asserter->hasNestedException())->isIdenticalTo($asserter) ->object($asserter->hasNestedException($nestedException))->isIdenticalTo($asserter) ->exception(function() use ($asserter) { $asserter->hasNestedException(new \exception()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($generator->getLocale()->_('exception does not contain this nested exception')) ; } public function testMessage() { $this ->if($asserter = new asserters\exception($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->message; }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Exception is undefined') ->if($asserter->setWith(new atoum\exceptions\runtime('', 0))) ->then ->object($string = $asserter->message) ->isInstanceOf('mageekguy\atoum\asserters\string') ->string($string->getValue()) ->isEqualTo('') ->if($asserter->setWith(new atoum\exceptions\runtime('Exception message', 0))) ->then ->object($string = $asserter->message) ->isInstanceOf('mageekguy\atoum\asserters\string') ->string($string->getValue()) ->isEqualTo('Exception message') ; } } testedClass->extends('mageekguy\atoum\asserter'); } public function test__construct() { $this ->if($asserter = new sut()) ->then ->object($asserter->getGenerator())->isEqualTo(new asserter\generator()) ->object($asserter->getLocale())->isIdenticalTo($asserter->getGenerator()->getLocale()) ->object($asserter->getAdapter())->isEqualTo(new atoum\adapter()) ->variable($asserter->getName())->isNull() ->if($asserter = new sut($generator = new asserter\generator(), $adapter = new atoum\adapter())) ->then ->object($asserter->getGenerator())->isIdenticalTo($generator) ->object($asserter->getLocale())->isIdenticalTo($generator->getLocale()) ->object($asserter->getAdapter())->isIdenticalTo($adapter) ->variable($asserter->getName())->isNull() ; } public function test__toString() { $this ->if($asserter = new sut(new asserter\generator())) ->then ->castToString($asserter)->isEmpty() ->if($asserter->setWith($extensionName = uniqid())) ->then ->castToString($asserter)->isEqualTo($extensionName) ; } public function testSetWith() { $this ->if($asserter = new sut(new asserter\generator())) ->then ->object($asserter->setWith($extensionName = uniqid()))->isIdenticalTo($asserter) ->string($asserter->getName())->isEqualTo($extensionName) ; } public function testSetAdapter() { $this ->if($asserter = new sut(new asserter\generator())) ->then ->object($asserter->setAdapter($adapter = new atoum\adapter()))->isIdenticalTo($asserter) ->object($asserter->getAdapter())->isIdenticalTo($adapter) ->object($asserter->setAdapter())->isIdenticalTo($asserter) ->object($asserter->getAdapter()) ->isNotIdenticalTo($adapter) ->isEqualTo(new atoum\adapter()) ; } public function testReset() { $this ->if($asserter = new sut(new asserter\generator())) ->then ->object($asserter->reset())->isIdenticalTo($asserter) ->variable($asserter->getName())->isNull() ->if($asserter->setWith(uniqid())) ->then ->object($asserter->reset())->isIdenticalTo($asserter) ->variable($asserter->getName())->isNull() ; } public function testIsLoaded() { $this ->if($asserter = new sut(new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->isLoaded(); } ) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Name of PHP extension is undefined') ->if($asserter->setAdapter($adapter = new atoum\test\adapter())) ->and($adapter->extension_loaded = false) ->and($asserter->setWith($extensionName = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->isLoaded(); } ) ->isInstanceOf('mageekguy\atoum\test\exceptions\skip') ->hasMessage('PHP extension \'' . $extensionName . '\' is not loaded') ->if($adapter->extension_loaded = true) ->then ->object($asserter->isLoaded())->isIdenticalTo($asserter) ; } } testedClass->isSubclassOf('mageekguy\atoum\asserters\integer'); } public function test__construct() { $this ->if($asserter = new asserters\float($generator = new asserter\generator())) ->then ->object($asserter->getLocale())->isIdenticalTo($generator->getLocale()) ->object($asserter->getGenerator())->isIdenticalTo($generator) ->variable($asserter->getValue())->isNull() ->boolean($asserter->wasSet())->isFalse() ; } public function testSetWith() { $this ->if($asserter = new asserters\float($generator = new asserter\generator())) ->exception(function() use (& $line, $asserter, & $value) { $line = __LINE__; $asserter->setWith($value = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not a float'), $asserter->getTypeOf($value))) ->string($asserter->getValue())->isEqualTo($value) ->object($asserter->setWith($value = (float) rand(- PHP_INT_MAX, PHP_INT_MAX)))->isIdenticalTo($asserter) ->float($asserter->getValue())->isEqualTo($value) ; } public function testIsEqualTo() { $this ->if($asserter = new asserters\float($generator = new asserter\generator())) ->and($asserter->setWith($value = (float) rand(1, PHP_INT_MAX))) ->then ->object($asserter->isEqualTo($value))->isIdenticalTo($asserter) ->exception(function() use ($asserter, & $notFloat) { $asserter->isEqualTo($notFloat = uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument') ->hasMessage('Argument of ' . get_class($asserter) . '::isEqualTo() must be a float') ->if($diff = new diffs\variable()) ->and($diff->setReference(- $value)->setData($value)) ->then ->exception(function() use ($asserter, $value) { $asserter->isEqualTo(- $value); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not equal to %s'), $asserter, $asserter->getTypeOf(- $value)) . PHP_EOL . $diff) ; } public function testIsGreaterThan() { $this ->if($asserter = new asserters\float($generator = new asserter\generator())) ->and($asserter->setWith($value = 1.2)) ->then ->object($asserter->isGreaterThan(1.1))->isIdenticalTo($asserter) ->exception(function() use ($asserter, & $notFloat) { $asserter->isGreaterThan($notFloat = uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument') ->hasMessage('Argument of ' . get_class($asserter) . '::isGreaterThan() must be a float') ->exception(function() use ($asserter, & $greaterValue) { $asserter->isGreaterThan($greaterValue = 1.3); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not greater than %s'), $asserter, $asserter->getTypeOf($greaterValue))) ; } public function testIsLessThan() { $this ->if($asserter = new asserters\float($generator = new asserter\generator())) ->and($asserter->setWith($value = 1.2)) ->then ->object($asserter->isLessThan(1.3))->isIdenticalTo($asserter) ->exception(function() use ($asserter, & $notFloat) { $asserter->isLessThan($notFloat = uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument') ->hasMessage('Argument of ' . get_class($asserter) . '::isLessThan() must be a float') ->exception(function() use ($asserter, & $lessValue) { $asserter->isLessThan($lessValue = 1.1); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not less than %s'), $asserter, $asserter->getTypeOf($lessValue))) ; } public function testIsGreaterThanOrEqualTo() { $this ->if($asserter = new asserters\float($generator = new asserter\generator())) ->and($asserter->setWith($value = 1.2)) ->then ->object($asserter->isGreaterThanOrEqualTo(1.1))->isIdenticalTo($asserter) ->object($asserter->isGreaterThanOrEqualTo($value))->isIdenticalTo($asserter) ->exception(function() use ($asserter, & $notFloat) { $asserter->isGreaterThanOrEqualTo($notFloat = uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument') ->hasMessage('Argument of ' . get_class($asserter) . '::isGreaterThanOrEqualTo() must be a float') ->exception(function() use ($asserter, & $greaterValue) { $asserter->isGreaterThanOrEqualTo($greaterValue = 1.3); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not greater than or equal to %s'), $asserter, $asserter->getTypeOf($greaterValue))) ; } public function testIsLessThanOrEqualTo() { $this ->if($asserter = new asserters\float($generator = new asserter\generator())) ->and($asserter->setWith($value = 1.2)) ->then ->object($asserter->isLessThanOrEqualTo(1.3))->isIdenticalTo($asserter) ->object($asserter->isLessThanOrEqualTo($value))->isIdenticalTo($asserter) ->exception(function() use ($asserter, & $notFloat) { $asserter->isLessThanOrEqualTo($notFloat = uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument') ->hasMessage('Argument of ' . get_class($asserter) . '::isLessThanOrEqualTo() must be a float') ->exception(function() use ($asserter, & $lessValue) { $asserter->isLessThanOrEqualTo($lessValue = 1.1); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not less than or equal to %s'), $asserter, $asserter->getTypeOf($lessValue))) ; } /** * @dataProvider dataProviderNearlyEqualTo */ public function testIsNearlyEqualTo($value, $testValue, $epsilon, $pass) { $this ->if($asserter = new asserters\float($generator = new asserter\generator())) ->and($asserter->setWith($value)); if ($pass) { $this->object($asserter->isNearlyEqualTo($testValue, $epsilon)) ->isIdenticalTo($asserter); } else { $this->if($diff = new diffs\variable()) ->and($diff->setReference($testValue)->setData($value)) ->then ->exception(function() use ($asserter, $testValue, $epsilon) { $asserter->isNearlyEqualTo($testValue, $epsilon); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not nearly equal to %s with epsilon %s'), $asserter, $asserter->getTypeOf($testValue), $epsilon) . PHP_EOL . $diff); } ; } protected function dataProviderNearlyEqualTo() { return array( array((float) 100, (float) 100, 1, true), array((float) 100, (float) 101, pow(10, -2), true), array((float) 101, (float) 100, pow(10, -2), true), array((float) 100, (float) 101, pow(10, -3), false), array((float) 101, (float) 100, pow(10, -3), false), array((float) -10001, (float) -10000, pow(10, -5), false), array((float) -10001, (float) -10000, pow(10, -4), true), array((float) -1.0001, (float) -1, pow(10, -4), true), array((float) -1.0001, (float) -1, pow(10, -5), false), array((float) 0.0001, (float) -0.0001, pow(10, -4), true), array((float) INF, (float) -INF, 1, false), array((float) INF, (float) INF, 1, true), ); } } testedClass->isSubclassOf('mageekguy\atoum\asserters\string'); } public function testIsSha1() { $this ->if($asserter = new asserters\hash($generator = new asserter\generator())) ->and($asserter->setWith($value = hash('sha1', 'hello'))) ->then ->object($asserter->isSha1())->isIdenticalTo($asserter) ->if($asserter->setWith($value = strtoupper($value))) ->then ->object($asserter->isSha1())->isIdenticalTo($asserter) ->if($asserter->setWith($newvalue = substr($value, 1))) ->and($diff = new diffs\variable()) ->and($diff->setReference( $newvalue )->setData($value)) ->then ->exception(function() use ($asserter, & $line) { $line = __LINE__; $asserter->isSha1(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($this->getLocale()->_('%s should be a string of %d characters'), $asserter, strlen($value))) ->if($asserter->setWith($newvalue = 'z'.substr($value, 1) )) ->and($diff = new diffs\variable()) ->and($diff->setReference($newvalue)->setData($value)) ->then ->exception(function() use ($asserter, & $line) { $line = __LINE__; $asserter->isSha1(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s does not match given pattern'), $asserter)) ; } public function testIsSha256() { $this ->if($asserter = new asserters\hash($generator = new asserter\generator())) ->and($asserter->setWith($value = hash('sha256', 'hello'))) ->then ->object($asserter->isSha256())->isIdenticalTo($asserter) ->if($asserter->setWith($value = strtoupper($value))) ->then ->object($asserter->isSha256())->isIdenticalTo($asserter) ->if($asserter->setWith($newvalue = substr($value, 1))) ->and($diff = new diffs\variable()) ->and($diff->setReference( $newvalue )->setData($value)) ->then ->exception(function() use ($asserter, & $line) { $line = __LINE__; $asserter->isSha256(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($this->getLocale()->_('%s should be a string of %d characters'), $asserter, strlen($value))) ->if($asserter->setWith($newvalue = 'z'.substr($value, 1) )) ->and($diff = new diffs\variable()) ->and($diff->setReference($newvalue)->setData($value)) ->then ->exception(function() use ($asserter, & $line) { $line = __LINE__; $asserter->isSha256(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s does not match given pattern'), $asserter)) ; } public function testIsSha512() { $this ->if($asserter = new asserters\hash($generator = new asserter\generator())) ->and($asserter->setWith($value = hash('sha512', 'hello'))) ->then ->object($asserter->isSha512())->isIdenticalTo($asserter) ->if($asserter->setWith($value = strtoupper($value))) ->then ->object($asserter->isSha512())->isIdenticalTo($asserter) ->if($asserter->setWith($newvalue = substr($value, 1))) ->and($diff = new diffs\variable()) ->and($diff->setReference( $newvalue )->setData($value)) ->then ->exception(function() use ($asserter, & $line) { $line = __LINE__; $asserter->isSha512(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($this->getLocale()->_('%s should be a string of %d characters'), $asserter, strlen($value))) ->if($asserter->setWith($newvalue = 'z'.substr($value, 1) )) ->and($diff = new diffs\variable()) ->and($diff->setReference($newvalue)->setData($value)) ->then ->exception(function() use ($asserter, & $line) { $line = __LINE__; $asserter->isSha512(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s does not match given pattern'), $asserter)) ; } public function testIsMd5() { $this ->if($asserter = new asserters\hash($generator = new asserter\generator())) ->and($asserter->setWith($value = hash('md5', 'hello'))) ->then ->object($asserter->isMd5())->isIdenticalTo($asserter) ->if($asserter->setWith($value = strtoupper($value))) ->then ->object($asserter->isMd5())->isIdenticalTo($asserter) ->if($asserter->setWith($newvalue = substr($value, 1))) ->and($diff = new diffs\variable()) ->and($diff->setReference( $newvalue )->setData($value)) ->then ->exception(function() use ($asserter, & $line) { $line = __LINE__; $asserter->isMd5(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($this->getLocale()->_('%s should be a string of %d characters'), $asserter, strlen($value))) ->if($asserter->setWith($newvalue = 'z'.substr($value, 1) )) ->and($diff = new diffs\variable()) ->and($diff->setReference($newvalue)->setData($value)) ->then ->exception(function() use ($asserter, & $line) { $line = __LINE__; $asserter->isMd5(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s does not match given pattern'), $asserter)) ; } } testedClass->isSubclassOf('mageekguy\atoum\asserters\variable'); } public function test__construct() { $this ->if($asserter = new asserters\integer($generator = new asserter\generator())) ->then ->object($asserter->getLocale())->isIdenticalTo($generator->getLocale()) ->object($asserter->getGenerator())->isIdenticalTo($generator) ->variable($asserter->getValue())->isNull() ->boolean($asserter->wasSet())->isFalse() ; } public function testSetWith() { $this ->if($asserter = new asserters\integer($generator = new asserter\generator())) ->then ->exception(function() use ($asserter, & $value) { $asserter->setWith($value = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not an integer'), $asserter->getTypeOf($value))) ->string($asserter->getValue())->isEqualTo($value) ->object($asserter->setWith($value = rand(- PHP_INT_MAX, PHP_INT_MAX)))->isIdenticalTo($asserter) ->integer($asserter->getValue())->isEqualTo($value) ; } public function testIsEqualTo() { $this ->if($asserter = new asserters\integer($generator = new asserter\generator())) ->and($asserter->setWith($value = rand(1, PHP_INT_MAX))) ->then ->object($asserter->isEqualTo($value))->isIdenticalTo($asserter) ->if($diff = new diffs\variable()) ->and($diff->setReference(- $value)->setData($value)) ->then ->exception(function() use ($asserter, $value) { $asserter->isEqualTo(- $value); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not equal to %s'), $asserter, $asserter->getTypeOf(- $value)) . PHP_EOL . $diff) ; } public function testIsGreaterThan() { $this ->if($asserter = new asserters\integer($generator = new asserter\generator())) ->and($asserter->setWith($value = rand(1, PHP_INT_MAX - 1))) ->then ->object($asserter->isGreaterThan(0))->isIdenticalTo($asserter) ->if($diff = new diffs\variable()) ->and($diff->setReference(PHP_INT_MAX)->setData($value)) ->then ->exception(function() use ($asserter, $value) { $asserter->isGreaterThan(PHP_INT_MAX); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not greater than %s'), $asserter, $asserter->getTypeOf(PHP_INT_MAX))) ->if($diff = new diffs\variable()) ->and($diff->setReference($value)->setData($value)) ->then ->exception(function() use ($asserter, $value) { $asserter->isGreaterThan($value); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not greater than %s'), $asserter, $asserter->getTypeOf($value))) ; } public function testIsLessThan() { $this ->if($asserter = new asserters\integer($generator = new asserter\generator())) ->and($asserter->setWith($value = - rand(1, PHP_INT_MAX - 1))) ->then ->object($asserter->isLessThan(0))->isIdenticalTo($asserter) ->if($diff = new diffs\variable()) ->and($diff->setReference(- PHP_INT_MAX)->setData($value)) ->then ->exception(function() use ($asserter, $value) { $asserter->isLessThan(- PHP_INT_MAX); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not less than %s'), $asserter, $asserter->getTypeOf(- PHP_INT_MAX))) ->if($diff = new diffs\variable()) ->and($diff->setReference($value)->setData($value)) ->then ->exception(function() use ($asserter, $value) { $asserter->isLessThan($value); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not less than %s'), $asserter, $asserter->getTypeOf($value))) ; } public function testIsGreaterThanOrEqualTo() { $this ->if($asserter = new asserters\integer($generator = new asserter\generator())) ->and($asserter->setWith($value = rand(1, PHP_INT_MAX - 1))) ->then ->object($asserter->isGreaterThanOrEqualTo(0))->isIdenticalTo($asserter) ->object($asserter->isGreaterThanOrEqualTo($value))->isIdenticalTo($asserter) ->if($diff = new diffs\variable()) ->and($diff->setReference(PHP_INT_MAX)->setData($value)) ->then ->exception(function() use ($asserter, $value) { $line = __LINE__; $asserter->isGreaterThanOrEqualTo(PHP_INT_MAX); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not greater than or equal to %s'), $asserter, $asserter->getTypeOf(PHP_INT_MAX))) ; } public function testIsLessThanOrEqualTo() { $this ->if($asserter = new asserters\integer($generator = new asserter\generator())) ->and($asserter->setWith($value = - rand(1, PHP_INT_MAX - 1))) ->then ->object($asserter->isLessThanOrEqualTo(0))->isIdenticalTo($asserter) ->object($asserter->isLessThanOrEqualTo($value))->isIdenticalTo($asserter) ->if($diff = new diffs\variable()) ->and($diff->setReference(- PHP_INT_MAX)->setData($value)) ->then ->exception(function() use ($asserter, $value) { $asserter->isLessThanOrEqualTo(- PHP_INT_MAX); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not less than or equal to %s'), $asserter, $asserter->getTypeOf(- PHP_INT_MAX))) ; } } testedClass->isSubclassOf('mageekguy\atoum\asserter'); } public function test__construct() { $this ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->then ->object($asserter->getLocale())->isIdenticalTo($generator->getLocale()) ->object($asserter->getGenerator())->isIdenticalTo($generator) ->variable($asserter->getMock())->isNull() ->variable($asserter->getCall())->isNull() ->array($asserter->getBeforeMethodCalls())->isEmpty() ->array($asserter->getAfterMethodCalls())->isEmpty() ; } public function testReset() { $this ->if($mockController = new \mock\mageekguy\atoum\mock\controller()) ->and($asserter = new asserters\mock($generator = new asserter\generator())) ->then ->variable($asserter->getMock())->isNull() ->object($asserter->reset())->isIdenticalTo($asserter) ->variable($asserter->getMock())->isNull() ->if($asserter->setWith($mock = new \mock\mageekguy\atoum\score())) ->and($mock->setMockController($mockController)) ->and($this->resetMock($mockController)) ->then ->object($asserter->getMock())->isIdenticalTo($mock) ->object($asserter->reset())->isIdenticalTo($asserter) ->object($asserter->getMock())->isIdenticalTo($mock) ->mock($mockController)->call('resetCalls')->once(); } public function testSetWith() { $this ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->and($adapter = new atoum\test\adapter()) ->and($adapter->class_exists = true) ->then ->exception(function() use ($asserter, & $mock) { $asserter->setWith($mock = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not a mock'), $asserter->getTypeOf($mock))) ->object($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\mock($adapter)))->isIdenticalTo($asserter) ->object($asserter->getMock())->isIdenticalTo($mock) ; } public function testWasCalled() { $this ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->wasCalled(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Mock is undefined') ->if($adapter = new atoum\test\adapter()) ->and($adapter->class_exists = true) ->and($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\mock($adapter))) ->and($mock->getMockController()->resetCalls()) ->then ->exception(function() use ($asserter) { $asserter->wasCalled(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not called'), get_class($mock))) ->exception(function() use ($asserter, & $failMessage) { $asserter->wasCalled($failMessage = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($failMessage) ->if($mock->getMockController()->{$method = __FUNCTION__} = function() {}) ->and($mock->{$method}()) ->then ->object($asserter->wasCalled())->isIdenticalTo($asserter) ; } public function testWasNotCalled() { $this ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->wasNotCalled(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Mock is undefined') ->if($adapter = new atoum\test\adapter()) ->and($adapter->class_exists = true) ->and($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\mock($adapter))) ->and($mock->getMockController()->resetCalls()) ->then ->object($asserter->wasNotCalled())->isIdenticalTo($asserter) ->if($mock->getMockController()->{$method = __FUNCTION__} = function() {}) ->and($mock->{$method}()) ->then ->exception(function() use ($asserter, & $failMessage) { $asserter->wasNotCalled($failMessage = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($failMessage) ; } public function testBeforeMethodCall() { $this ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->beforeMethodCall(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Mock is undefined') ->if($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->then ->object($asserter->beforeMethodCall('foo'))->isEqualTo($beforeMethodCall = new asserters\mock\call\mock($asserter, $mock, 'foo')) ->array($asserter->getBeforeMethodCalls())->isEqualTo(array($beforeMethodCall)) ->object($asserter->beforeMethodCall('bar'))->isEqualTo($otherBeforeMethodCall = new asserters\mock\call\mock($asserter, $mock, 'bar')) ->array($asserter->getBeforeMethodCalls())->isEqualTo(array($beforeMethodCall, $otherBeforeMethodCall)) ; } public function testWithAnyMethodCallsBefore() { $this ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->then ->array($asserter->getBeforeMethodCalls())->isEmpty() ->object($asserter->withAnyMethodCallsBefore())->isIdenticalTo($asserter) ->array($asserter->getBeforeMethodCalls())->isEmpty() ->if($asserter->setWith(new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->and($asserter->beforeMethodCall(uniqid())) ->then ->array($asserter->getBeforeMethodCalls())->isNotEmpty() ->object($asserter->withAnyMethodCallsBefore())->isIdenticalTo($asserter) ->array($asserter->getBeforeMethodCalls())->isEmpty() ->if($asserter ->beforeMethodCall(uniqid()) ->beforeMethodCall(uniqid()) ) ->then ->array($asserter->getBeforeMethodCalls())->isNotEmpty() ->object($asserter->withAnyMethodCallsBefore())->isIdenticalTo($asserter) ->array($asserter->getBeforeMethodCalls())->isEmpty() ; } public function testAfterMethodCall() { $this ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->afterMethodCall(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Mock is undefined') ->if($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->then ->object($asserter->afterMethodCall('foo'))->isEqualTo($afterMethodCall = new asserters\mock\call\mock($asserter, $mock, 'foo')) ->array($asserter->getAfterMethodCalls())->isEqualTo(array($afterMethodCall)) ->object($asserter->afterMethodCall('bar'))->isEqualTo($otherAfterMethodCall = new asserters\mock\call\mock($asserter, $mock, 'bar')) ->array($asserter->getAfterMethodCalls())->isEqualTo(array($afterMethodCall, $otherAfterMethodCall)) ; } public function testWithAnyMethodCallsAfter() { $this ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->then ->array($asserter->getAfterMethodCalls())->isEmpty() ->object($asserter->withAnyMethodCallsAfter())->isIdenticalTo($asserter) ->array($asserter->getAfterMethodCalls())->isEmpty() ->if($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->and($asserter->afterMethodCall($function = uniqid())) ->then ->array($asserter->getAfterMethodCalls())->isNotEmpty() ->object($asserter->withAnyMethodCallsAfter())->isIdenticalTo($asserter) ->array($asserter->getAfterMethodCalls())->isEmpty() ->if($asserter ->afterMethodCall($function1 = uniqid()) ->afterMethodCall($function2 = uniqid()) ) ->then ->array($asserter->getAfterMethodCalls())->isNotEmpty() ->object($asserter->withAnyMethodCallsAfter())->isIdenticalTo($asserter) ->array($asserter->getAfterMethodCalls())->isEmpty() ; } public function testBeforeFunctionCall() { $this ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->beforeFunctionCall(uniqid(), new test\adapter()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Mock is undefined') ->if($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->and($adapter = new test\adapter()) ->then ->object($asserter->beforeFunctionCall('foo', $adapter))->isEqualTo($beforeFunctionCall = new asserters\mock\call\adapter($asserter, $adapter, 'foo')) ->array($asserter->getBeforeFunctionCalls())->isEqualTo(array($beforeFunctionCall)) ->object($asserter->beforeFunctionCall('bar', $adapter))->isEqualTo($otherBeforeFunctionCall = new asserters\mock\call\adapter($asserter, $adapter, 'bar')) ->array($asserter->getBeforeFunctionCalls())->isEqualTo(array($beforeFunctionCall, $otherBeforeFunctionCall)) ; } public function testWithAnyFunctionCallsBefore() { $this ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->then ->array($asserter->getBeforeFunctionCalls())->isEmpty() ->object($asserter->withAnyFunctionCallsBefore())->isIdenticalTo($asserter) ->array($asserter->getBeforeFunctionCalls())->isEmpty() ->if($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->and($adapter = new test\adapter()) ->and($asserter->beforeFunctionCall($function = uniqid(), $adapter)) ->then ->array($asserter->getBeforeFunctionCalls())->isNotEmpty() ->object($asserter->withAnyFunctionCallsBefore())->isIdenticalTo($asserter) ->array($asserter->getBeforeFunctionCalls())->isEmpty() ->if($asserter ->beforeFunctionCall($function1 = uniqid(), $adapter) ->beforeFunctionCall($function2 = uniqid(), $adapter) ) ->then ->array($asserter->getBeforeFunctionCalls())->isNotEmpty() ->object($asserter->withAnyFunctionCallsBefore())->isIdenticalTo($asserter) ->array($asserter->getBeforeFunctionCalls())->isEmpty() ; } public function testAfterFunctionCall() { $this ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->afterFunctionCall(uniqid(), new test\adapter()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Mock is undefined') ->if($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->and($adapter = new test\adapter()) ->then ->object($asserter->afterFunctionCall('foo', $adapter))->isEqualTo($afterFunctionCall = new asserters\mock\call\adapter($asserter, $adapter, 'foo')) ->array($asserter->getAfterFunctionCalls())->isEqualTo(array($afterFunctionCall)) ->object($asserter->afterFunctionCall('bar', $adapter))->isEqualTo($otherAfterFunctionCall = new asserters\mock\call\adapter($asserter, $adapter, 'bar')) ->array($asserter->getAfterFunctionCalls())->isEqualTo(array($afterFunctionCall, $otherAfterFunctionCall)) ; } public function testWithAnyFunctionCallsAfter() { $this ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->then ->array($asserter->getAfterFunctionCalls())->isEmpty() ->object($asserter->withAnyFunctionCallsAfter())->isIdenticalTo($asserter) ->array($asserter->getAfterFunctionCalls())->isEmpty() ->if($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->and($adapter = new test\adapter()) ->and($asserter->afterFunctionCall($function = uniqid(), $adapter)) ->then ->array($asserter->getAfterFunctionCalls())->isNotEmpty() ->object($asserter->withAnyFunctionCallsAfter())->isIdenticalTo($asserter) ->array($asserter->getAfterFunctionCalls())->isEmpty() ->if($asserter ->afterFunctionCall($function1 = uniqid(), $adapter) ->afterFunctionCall($function2 = uniqid(), $adapter) ) ->then ->array($asserter->getAfterFunctionCalls())->isNotEmpty() ->object($asserter->withAnyFunctionCallsAfter())->isIdenticalTo($asserter) ->array($asserter->getAfterFunctionCalls())->isEmpty() ; } public function testCall() { $this ->if($asserter = new \mock\mageekguy\atoum\asserters\mock(new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->call(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Mock is undefined') ->if($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->then ->object($asserter->call($function = uniqid()))->isIdenticalTo($asserter) ->object($asserter->getCall())->isEqualTo(new php\call($function, null, $mock)) ->if($asserter->withArguments()) ->then ->object($asserter->getCall())->isEqualTo(new php\call($function, array(), $mock)) ->object($asserter->call($function = uniqid()))->isIdenticalTo($asserter) ->object($asserter->getCall())->isEqualTo(new php\call($function, null, $mock)) ; } public function testWithArguments() { $this ->if($asserter = new \mock\mageekguy\atoum\asserters\mock(new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->withArguments(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Mock is undefined') ->if($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->then ->exception(function() use ($asserter) { $asserter->withArguments(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Called method is undefined') ->if($asserter->call($function = uniqid())) ->then ->object($asserter->withArguments())->isIdenticalTo($asserter) ->object($asserter->getCall())->isEqualTo(new php\call($function, array(), $mock)) ->object($asserter->withArguments($arg1 = uniqid()))->isIdenticalTo($asserter) ->object($asserter->getCall())->isEqualTo(new php\call($function, array($arg1), $mock)) ->object($asserter->withArguments($arg1 = uniqid(), $arg2 = uniqid()))->isIdenticalTo($asserter) ->object($asserter->getCall())->isEqualTo(new php\call($function, array($arg1, $arg2), $mock)) ; } public function testWithAtLeastArguments() { $this ->if($asserter = new \mock\mageekguy\atoum\asserters\mock(new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->withArguments(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Mock is undefined') ->if($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->then ->exception(function() use ($asserter) { $asserter->withArguments(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Called method is undefined') ->if($asserter->call($function = uniqid())) ->then ->object($asserter->withAtLeastArguments($arguments = array(1 => uniqid())))->isIdenticalTo($asserter) ->object($asserter->getCall())->isEqualTo(new php\call($function, $arguments, $mock)) ->object($asserter->withAtLeastArguments($arguments = array(2 => uniqid(), 5 => uniqid())))->isIdenticalTo($asserter) ->object($asserter->getCall())->isEqualTo(new php\call($function, $arguments, $mock)) ; } public function testWithAnyArguments() { $this ->if($asserter = new \mock\mageekguy\atoum\asserters\mock(new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->withArguments(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Mock is undefined') ->if($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->then ->exception(function() use ($asserter) { $asserter->withArguments(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Called method is undefined') ->if($asserter->call($function = uniqid())) ->then ->object($asserter->getCall())->isEqualTo(new php\call($function, null, $mock)) ->object($asserter->withAnyArguments())->isIdenticalTo($asserter) ->object($asserter->getCall())->isEqualTo(new php\call($function, null, $mock)) ->if($asserter->withArguments($arg = uniqid())) ->then ->object($asserter->getCall())->isEqualTo(new php\call($function, array($arg), $mock)) ->object($asserter->withAnyArguments())->isIdenticalTo($asserter) ->object($asserter->getCall())->isEqualTo(new php\call($function, null, $mock)) ; } public function testWithoutAnyArgument() { $this ->if($asserter = new \mock\mageekguy\atoum\asserters\mock(new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->withoutAnyArgument(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Mock is undefined') ->if($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->then ->exception(function() use ($asserter) { $asserter->withoutAnyArgument(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Called method is undefined') ->if($asserter->call($function = uniqid())) ->then ->object($asserter->withoutAnyArgument())->isIdenticalTo($asserter) ->object($asserter->getCall())->isEqualTo(new php\call($function, array(), $mock)) ; } public function testOnce() { $this ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->once(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Mock is undefined') ->if($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->then ->exception(function() use ($asserter) { $asserter->once(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Called method is undefined') ->if($asserter->call('foo')) ->then ->exception(function() use ($asserter) { $asserter->once(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time instead of 1'), $asserter->getCall())) ->if($call = new php\call('foo', null, $mock)) ->and($mock->foo($usedArg = uniqid())) ->then ->object($asserter->once())->isIdenticalTo($asserter) ->if($mock->foo($otherUsedArg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->once(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 2 times instead of 1'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[2] ' . $call->setArguments(array($otherUsedArg))) ->if($mock->getMockController()->resetCalls()) ->and($asserter->withArguments($usedArg = uniqid())) ->and($mock->foo($usedArg)) ->then ->object($asserter->once())->isIdenticalTo($asserter) ->if($asserter->withArguments($arg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->once(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time instead of 1'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg))) ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->and($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->and($asserter->beforeMethodCall('bar')->call('foo')) ->then ->exception(function() use ($asserter) { $asserter->once(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time instead of 1'), $asserter->getCall())) ->if($mock->foo(uniqid())) ->object($asserter->once())->isIdenticalTo($asserter) /* ->if($mock->getMockController()->resetCalls()) ->and($mock->bar(uniqid())) ->and($mock->foo(uniqid())) ->then ->exception(function() use ($asserter) { $asserter->once(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is not called before method %s'), $asserter->getCall(), current($asserter->getBeforeMethodCalls()))) */ ->if($mock->getMockController()->resetCalls()) ->and($mock->foo(uniqid())) ->and($mock->bar(uniqid())) ->then ->object($asserter->once())->isIdenticalTo($asserter) ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->and($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->and($asserter->afterMethodCall('bar')->call('foo')) ->then ->exception(function() use ($asserter) { $asserter->once(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time instead of 1'), $asserter->getCall())) /* ->if($mock->foo(uniqid())) ->then ->exception(function() use ($asserter) { $asserter->once(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is not called'), current($asserter->getAfterMethodCalls()))) ->if($mock->getMockController()->resetCalls()) ->and($mock->foo(uniqid())) ->and($mock->bar(uniqid())) ->then ->exception(function() use ($asserter) { $asserter->once(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is not called after method %s'), $asserter->getCall(), current($asserter->getAfterMethodCalls()))) */ ->if($mock->getMockController()->resetCalls()) ->and($mock->bar(uniqid())) ->and($mock->foo(uniqid())) ->then ->object($asserter->once())->isIdenticalTo($asserter) ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->and($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->and($asserter->beforeMethodCall('bar')->withArguments($arg = 'toto')->call('foo')) ->and($mock->foo(uniqid())) ->then ->exception(function() use ($asserter) { $asserter->once(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is not called'), current($asserter->getBeforeMethodCalls()))) ; } public function testTwice() { $this ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Mock is undefined') ->if($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->then ->exception(function() use ($asserter) { $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Called method is undefined') ->if($asserter->call('foo')) ->then ->exception(function() use ($asserter) { $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time instead of 2'), $asserter->getCall())) ->if($call = new php\call('foo', null, $mock)) ->and($mock->foo($usedArg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 1 time instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg))) ->if($mock->foo($secondArg = uniqid())) ->then ->object($asserter->twice())->isIdenticalTo($asserter) ->if($mock->foo($thirdArg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 3 times instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[2] ' . $call->setArguments(array($secondArg)) . PHP_EOL . '[3] ' . $call->setArguments(array($thirdArg))) ->if($mock->getMockController()->resetCalls()) ->and($asserter->withArguments($usedArg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time instead of 2'), $asserter->getCall())) ->if($mock->foo($usedArg)) ->then ->exception(function() use ($asserter) { $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 1 time instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg))) ->if($mock->foo($usedArg)) ->then ->object($asserter->twice())->isIdenticalTo($asserter) ->if($mock->foo($usedArg)) ->then ->exception(function() use ($asserter) { $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 3 times instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[2] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[3] ' . $call->setArguments(array($usedArg))) ->if($asserter->withArguments($arg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[2] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[3] ' . $call->setArguments(array($usedArg))) ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->and($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->and($asserter->beforeMethodCall('bar')->call('foo')) ->then ->exception(function() use ($asserter) { $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time instead of 2'), $asserter->getCall())) ->if($mock->foo($usedArg = uniqid())) ->exception(function() use ($asserter) { $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 1 time instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg))) ->if($mock->foo(uniqid())) ->object($asserter->twice())->isIdenticalTo($asserter) ->if($mock->getMockController()->resetCalls()) ->and($mock->foo($usedArg = uniqid())) ->and($mock->bar(uniqid())) ->then ->exception(function() use ($asserter) { $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 1 time instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg))) ->if($mock->foo($usedArg = uniqid())) ->and($mock->bar(uniqid())) ->then ->object($asserter->twice())->isIdenticalTo($asserter) ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->and($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->and($asserter->afterMethodCall('bar')->call('foo')) ->then ->exception(function() use ($asserter) { $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time instead of 2'), $asserter->getCall())) ->if($mock->getMockController()->resetCalls()) ->and($mock->bar(uniqid())) ->and($mock->foo($usedArg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 1 time instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg))) ->if($mock->foo(uniqid())) ->then ->object($asserter->twice())->isIdenticalTo($asserter) ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->and($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->and($asserter->beforeMethodCall('bar')->withArguments($arg = 'toto')->call('foo')) ->and($mock->foo(uniqid())) ->then ->exception(function() use ($asserter) { $asserter->twice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is not called'), current($asserter->getBeforeMethodCalls()))) ->and($mock->foo(uniqid())) ->if($mock->bar($arg)) ->then ->object($asserter->twice())->isIdenticalTo($asserter) ; } public function testThrice() { $this ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Mock is undefined') ->if($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Called method is undefined') ->if($asserter->call('foo')) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time instead of 3'), $asserter->getCall())) ->if($call = new php\call('foo', null, $mock)) ->and($mock->foo($usedArg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 1 time instead of 3'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg))) ->if($mock->foo($secondArg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 2 times instead of 3'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[2] ' . $call->setArguments(array($secondArg))) ->if($mock->foo($thirdArg = uniqid())) ->then ->object($asserter->thrice())->isIdenticalTo($asserter) ->if($mock->foo($fourthArg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 4 times instead of 3'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[2] ' . $call->setArguments(array($secondArg)) . PHP_EOL . '[3] ' . $call->setArguments(array($thirdArg)) . PHP_EOL . '[4] ' . $call->setArguments(array($fourthArg))) ->if($mock->getMockController()->resetCalls()) ->and($asserter->withArguments($usedArg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time instead of 3'), $asserter->getCall())) ->if($mock->foo($usedArg)) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 1 time instead of 3'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg))) ->if($mock->foo($usedArg)) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 2 times instead of 3'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[2] ' . $call->setArguments(array($usedArg))) ->if($mock->foo($usedArg)) ->then ->object($asserter->thrice())->isIdenticalTo($asserter) ->if($mock->foo($usedArg)) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 4 times instead of 3'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[2] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[3] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[4] ' . $call->setArguments(array($usedArg))) ->if($asserter->withArguments($arg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time instead of 3'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[2] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[3] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[4] ' . $call->setArguments(array($usedArg))) ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->and($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->and($asserter->beforeMethodCall('bar')->call('foo')) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time instead of 3'), $asserter->getCall())) ->if($mock->foo($usedArg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 1 time instead of 3'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg))) ->if($mock->foo($usedArg)) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 2 times instead of 3'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[2] ' . $call->setArguments(array($usedArg))) ->if($mock->foo(uniqid())) ->then ->object($asserter->thrice())->isIdenticalTo($asserter) ->if($mock->getMockController()->resetCalls()) ->and($mock->foo($firstArg = uniqid())) ->and($mock->bar(uniqid())) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 1 time instead of 3'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($firstArg))) ->if($mock->foo($secondArg = uniqid())) ->and($mock->bar(uniqid())) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 2 times instead of 3'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($firstArg)) . PHP_EOL . '[2] ' . $call->setArguments(array($secondArg))) ->if($mock->foo(uniqid())) ->and($mock->bar(uniqid())) ->then ->object($asserter->thrice())->isIdenticalTo($asserter) ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->and($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->and($asserter->afterMethodCall('bar')->call('foo')) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time instead of 3'), $asserter->getCall())) ->if($mock->getMockController()->resetCalls()) ->and($mock->bar(uniqid())) ->and($mock->foo($firstArg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 1 time instead of 3'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($firstArg))) ->if($mock->bar(uniqid())) ->and($mock->foo($secondArg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 2 times instead of 3'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($firstArg)) . PHP_EOL . '[2] ' . $call->setArguments(array($secondArg))) ->if($mock->foo(uniqid())) ->then ->object($asserter->thrice())->isIdenticalTo($asserter) ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->and($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->and($asserter->beforeMethodCall('bar')->withArguments($arg = 'toto')->call('foo')) ->and($mock->foo(uniqid())) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is not called'), current($asserter->getBeforeMethodCalls()))) ->if($mock->foo(uniqid())) ->then ->exception(function() use ($asserter) { $asserter->thrice(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is not called'), current($asserter->getBeforeMethodCalls()))) ->and($mock->foo(uniqid())) ->if($mock->bar($arg)) ->then ->object($asserter->thrice())->isIdenticalTo($asserter) ; } public function testAtLeastOnce() { $this ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->atLeastOnce(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Mock is undefined') ->if($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->then ->exception(function() use ($asserter) { $asserter->atLeastOnce(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Called method is undefined') ->if($asserter->call('foo')) ->then ->exception(function() use ($asserter) { $asserter->atLeastOnce(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time'), $asserter->getCall())) ->if($mock->foo(uniqid())) ->then ->object($asserter->atLeastOnce())->isIdenticalTo($asserter) ->if($mock->foo(uniqid())) ->then ->object($asserter->atLeastOnce())->isIdenticalTo($asserter) ->if($mock->getMockController()->resetCalls()) ->and($asserter->withArguments($usedArg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->atLeastOnce(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time'), $asserter->getCall())) ->if($call = new php\call('foo', null, $mock)) ->if( $mock->foo($usedArg)) ->then ->object($asserter->atLeastOnce())->isIdenticalTo($asserter) ->if($asserter->withArguments($otherArg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->atLeastOnce(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg))) ; } public function testExactly() { $this ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->exactly(2); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Mock is undefined') ->if($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->then ->exception(function() use ($asserter) { $asserter->exactly(2); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Called method is undefined') ->if($asserter->call('foo')) ->then ->exception(function() use ($asserter) { $asserter->exactly(2); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time instead of 2'), $asserter->getCall())) ->if($call = new php\call('foo', null, $mock)) ->and($mock->foo($usedArg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->exactly(2); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 1 time instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg))) ->if($mock->foo($otherUsedArg = uniqid())) ->then ->object($asserter->exactly(2))->isIdenticalTo($asserter) ->if($mock->foo($anOtherUsedArg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->exactly(2); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 3 times instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[2] ' . $call->setArguments(array($otherUsedArg)) . PHP_EOL . '[3] ' . $call->setArguments(array($anOtherUsedArg))) ->if($mock->getMockController()->resetCalls()) ->and($asserter->withArguments($arg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->exactly(2); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time instead of 2'), $asserter->getCall())) ->if($mock->foo($usedArg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->exactly(2); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg))) ->if($mock->foo($arg)) ->then ->exception(function() use ($asserter) { $asserter->exactly(2); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 1 time instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[2] ' . $call->setArguments(array($arg))) ->if($mock->foo($arg)) ->then ->object($asserter->exactly(2))->isIdenticalTo($asserter) ->if($mock->foo($arg)) ->then ->exception(function() use ($asserter) { $asserter->exactly(2); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 3 times instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[2] ' . $call->setArguments(array($arg)) . PHP_EOL . '[3] ' . $call->setArguments(array($arg)) . PHP_EOL . '[4] ' . $call->setArguments(array($arg))) ->if($call = new php\call('fooWithSeveralArguments', null, $mock)) ->and($asserter->call('fooWithSeveralArguments')) ->then ->object($asserter->exactly(0))->isIdenticalTo($asserter) ->exception(function() use ($asserter) { $asserter->exactly(1); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time instead of 1'), $asserter->getCall())) ->if($mock->fooWithSeveralArguments(1, 2, 3, 4, 5)) ->exception(function() use ($asserter) { $asserter->exactly(0); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 1 time instead of 0'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array(1, 2, 3, 4, 5))) ->object($asserter->exactly(1))->isIdenticalTo($asserter) ->object($asserter->withArguments(1, 2, 3, 4, 5)->exactly(1))->isIdenticalTo($asserter) ->object($asserter->withAtLeastArguments(array(1 => 2, 3 => 4))->exactly(1))->isIdenticalTo($asserter) ->object($asserter->withAtLeastArguments(array(1 => 2, 3 => rand(6, PHP_INT_MAX)))->exactly(0))->isIdenticalTo($asserter) ->exception(function() use ($asserter) { $asserter->withAtLeastArguments(array(1 => 2, 3 => 4))->exactly(0); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 1 time instead of 0'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array(1, 2, 3, 4, 5))) ->object($asserter->withIdenticalArguments(1, 2, 3, 4, 5)->exactly(1))->isIdenticalTo($asserter) ->exception(function() use ($asserter) { $asserter->withAtLeastIdenticalArguments(array(1 => '2', 3 => 4))->exactly(1); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 0 time instead of 1'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array(1, 2, 3, 4, 5))) ; } public function testNever() { $this ->if($asserter = new asserters\mock($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->never(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Mock is undefined') ->if($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy())) ->then ->exception(function() use ($asserter) { $asserter->never(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Called method is undefined') ->if($asserter->call('foo')) ->then ->object($asserter->never())->isIdenticalTo($asserter) ->if($call = new php\call('foo', null, $mock)) ->and($mock->foo($usedArg = uniqid())) ->then ->exception(function() use ($asserter) { $asserter->never(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 1 time instead of 0'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg))) ->if($mock->getMockController()->resetCalls()) ->and($asserter->withArguments($arg = uniqid())) ->then ->object($asserter->never())->isIdenticalTo($asserter) ->if($mock->foo($arg)) ->then ->exception(function() use ($asserter) { $asserter->never(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 1 time instead of 0'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($arg))) ->if($mock->foo($arg)) ->then ->exception(function() use ($asserter) { $asserter->never(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('method %s is called 2 times instead of 0'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($arg)) . PHP_EOL . '[2] ' . $call->setArguments(array($arg))) ->if($mock->foo($arg)) ->then ->exception(function() use ($asserter, & $message) { $asserter->never($message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->if($asserter->withArguments(uniqid())) ->then ->object($asserter->never())->isIdenticalTo($asserter) ; } } testedClass->isSubclassOf('mageekguy\atoum\asserters\dateTime'); } public function testSetWith() { $this ->if($asserter = new asserters\mysqlDateTime($generator = new asserter\generator())) ->then ->exception(function() use ($asserter, & $value) { $asserter->setWith($value = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not in format Y-m-d H:i:s'), $asserter->getTypeOf($value))) ->string($asserter->getValue())->isEqualTo($value) ->object($asserter->setWith($value = '1976-10-06 14:05:54'))->isIdenticalTo($asserter) ->string($asserter->getValue())->isIdenticalTo($value) ->object($asserter->setWith($value = uniqid(), false))->isIdenticalTo($asserter) ->string($asserter->getValue())->isEqualTo($value) ; } } testedClass->isSubclassOf('mageekguy\atoum\asserters\variable'); } public function test__construct() { $this ->if($asserter = new asserters\object($generator = new asserter\generator())) ->then ->object($asserter->getLocale())->isIdenticalTo($generator->getLocale()) ->object($asserter->getGenerator())->isIdenticalTo($generator) ->variable($asserter->getValue())->isNull() ->boolean($asserter->wasSet())->isFalse() ; } public function test__get() { $this ->if($asserter = new asserters\object($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->toString; }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Object is undefined') ->exception(function() use ($asserter, & $property) { $asserter->{$property = uniqid()}; }) ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument') ->hasMessage('Asserter \'' . $property . '\' does not exist') ->if($asserter->setWith($this)) ->then ->object($asserter->toString)->isInstanceOf('mageekguy\atoum\asserters\castToString') ; } public function testSetWith() { $this ->if($asserter = new asserters\object($generator = new asserter\generator())) ->then ->exception(function() use ($asserter, & $value) { $asserter->setWith($value = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not an object'), $asserter->getTypeOf($value))) ->string($asserter->getValue())->isEqualTo($value) ->object($asserter->setWith($value = $this))->isIdenticalTo($asserter) ->object($asserter->getValue())->isIdenticalTo($value) ->object($asserter->setWith($value = uniqid(), false))->isIdenticalTo($asserter) ->string($asserter->getValue())->isEqualTo($value) ; } public function testHasSize() { $this ->if($asserter = new asserters\object($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasSize(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Object is undefined') ->if($asserter->setWith($this)) ->then ->exception(function() use ($asserter) { $asserter->hasSize(0); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s has size %d, expected size %d'), $asserter, sizeof($this), 0)) ->object($asserter->hasSize(sizeof($this)))->isIdenticalTo($asserter); ; } public function testIsEmpty() { $this ->if($asserter = new asserters\object($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasSize(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Object is undefined') ->if($asserter->setWith($this)) ->then ->exception(function() use ($asserter) { $asserter->isEmpty(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s has size %d'), $asserter, sizeof($this))) ->if($asserter->setWith(new \arrayIterator())) ->then ->object($asserter->isEmpty())->isIdenticalTo($asserter) ; } public function testIsCloneOf() { $this ->if($asserter = new asserters\object($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->isCloneOf($asserter); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Object is undefined') ->if($asserter->setWith($test = $this)) ->then ->exception(function() use ($asserter, $test) { $asserter->isCloneOf($test); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not a clone of %s'), $asserter, $asserter->getTypeOf($test))) ->if($clonedTest = clone $test) ->then ->object($asserter->isCloneOf($clonedTest))->isIdenticalTo($asserter) ; } public function testToString() { $this ->if($asserter = new asserters\object($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->toString(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Object is undefined') ->if($asserter->setWith($this)) ->then ->object($asserter->toString())->isInstanceOf('mageekguy\atoum\asserters\castToString') ; } } testedClass->extends('mageekguy\atoum\asserters\string'); } public function test__construct() { $this ->if($asserter = new asserters\output()) ->then ->object($asserter->getGenerator())->isEqualTo(new asserter\generator()) ->object($asserter->getLocale())->isIdenticalTo($asserter->getGenerator()->getLocale()) ->string($asserter->getValue())->isEmpty() ->boolean($asserter->wasSet())->isTrue() ->if($asserter = new asserters\output($generator = new asserter\generator())) ->then ->object($asserter->getGenerator())->isIdenticalTo($generator) ->object($asserter->getLocale())->isIdenticalTo($generator->getLocale()) ->string($asserter->getValue())->isEmpty() ->boolean($asserter->wasSet())->isTrue() ; } public function testSetWith() { $this ->if($asserter = new asserters\output(new asserter\generator())) ->then ->object($asserter->setWith(function() use (& $output) { echo ($output = uniqid()); }))->isIdenticalTo($asserter) ->string($asserter->getValue())->isEqualTo($output) ->variable($asserter->getCharlist())->isNull() ->object($asserter->setWith(function() use (& $output) { echo ($output = uniqid()); }, null, "\010"))->isIdenticalTo($asserter) ->string($asserter->getValue())->isEqualTo($output) ->string($asserter->getCharlist())->isEqualTo("\010") ; } } testedClass->extends('mageekguy\atoum\asserters\variable'); } public function test__construct() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->object($asserter->getLocale())->isIdenticalTo($generator->getLocale()) ->object($asserter->getGenerator())->isIdenticalTo($generator) ->variable($asserter->getValue())->isNull() ->boolean($asserter->wasSet())->isFalse() ; } public function testSetWith() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter, & $value) { $asserter->setWith($value = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not an array'), $asserter->getTypeOf($value))) ->object($asserter->setWith($value = array()))->isIdenticalTo($asserter) ->array($asserter->getValue())->isEqualTo($value) ; } public function testHasSize() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasSize(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Array is undefined') ->if($asserter->setWith(array())) ->then ->exception(function() use ($asserter, & $size) { $asserter->hasSize($size = rand(1, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s has not size %d'), $asserter, $size)) ->exception(function() use ($asserter, & $size, & $message) { $asserter->hasSize($size = rand(1, PHP_INT_MAX), $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->object($asserter->hasSize(0))->isIdenticalTo($asserter) ; } public function testIsEmpty() { $this->assert ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->isEmpty(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Array is undefined') ->if($asserter->setWith(array(uniqid()))) ->then ->exception(function() use ($asserter) { $asserter->isEmpty(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not empty'), $asserter)) ->exception(function() use ($asserter, & $message) { $asserter->isEmpty($message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->if($asserter->setWith(array())) ->then ->object($asserter->isEmpty())->isIdenticalTo($asserter) ; } public function testIsNotEmpty() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->isNotEmpty(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Array is undefined') ->if($asserter->setWith(array())) ->then ->exception(function() use ($asserter) { $asserter->isNotEmpty(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is empty'), $asserter)) ->exception(function() use ($asserter, & $message) { $asserter->isNotEmpty($message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->if($asserter->setWith(array(uniqid()))) ->then ->object($asserter->isNotEmpty())->isIdenticalTo($asserter) ; } public function testAtKey() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->atKey(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Array is undefined') ->if($asserter->setWith(array(uniqid(), uniqid(), $data = rand(1, PHP_INT_MAX), uniqid(), uniqid()))) ->object($asserter->atKey(0))->isIdenticalTo($asserter) ->object($asserter->atKey('0'))->isIdenticalTo($asserter) ->object($asserter->atKey(1))->isIdenticalTo($asserter) ->object($asserter->atKey(2))->isIdenticalTo($asserter) ->object($asserter->atKey(3))->isIdenticalTo($asserter) ->object($asserter->atKey(4))->isIdenticalTo($asserter) ->exception(function() use ($asserter, & $key) { $asserter->atKey($key = rand(5, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s has no key %s'), $asserter, $asserter->getTypeOf($key))) ->exception(function() use ($asserter, & $key, & $message) { $asserter->atKey($key = rand(5, PHP_INT_MAX), $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ; } public function testContains() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->contains(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Array is undefined') ->if($asserter->setWith(array(uniqid(), uniqid(), $data = rand(1, PHP_INT_MAX), uniqid(), uniqid()))) ->then ->exception(function() use ($asserter, & $notInArray) { $asserter->contains($notInArray = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s does not contain %s'), $asserter, $asserter->getTypeOf($notInArray))) ->object($asserter->contains($data))->isIdenticalTo($asserter) ->object($asserter->contains((string) $data))->isIdenticalTo($asserter) ->exception(function() use ($asserter, $data) { $asserter->atKey(0)->contains($data); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s does not contain %s at key %s'), $asserter, $asserter->getTypeOf($data), $asserter->getTypeOf(0))) ->object($asserter->contains($data))->isIdenticalTo($asserter) ->object($asserter->atKey(2)->contains($data))->isIdenticalTo($asserter) ; } public function testNotContains() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->notContains(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Array is undefined') ->if($asserter->setWith(array(uniqid(), uniqid(), $inArray = uniqid(), uniqid(), uniqid()))) ->then ->object($asserter->notContains(uniqid()))->isIdenticalTo($asserter) ->exception(function() use ($asserter, $inArray) { $asserter->notContains($inArray); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s contains %s'), $asserter, $asserter->getTypeOf($inArray))) ->exception(function() use ($asserter, $inArray, & $message) { $asserter->notContains($inArray, $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->exception(function() use($asserter, $inArray){ $asserter->notContains((string) $inArray); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s contains %s'), $asserter, $asserter->getTypeOf((string) $inArray))) ->exception(function() use($asserter, $inArray, & $message){ $asserter->notContains((string) $inArray, $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->object($asserter->atKey(0)->notContains($inArray))->isIdenticalTo($asserter) ->object($asserter->atKey(1)->notContains($inArray))->isIdenticalTo($asserter) ->object($asserter->atKey(3)->notContains($inArray))->isIdenticalTo($asserter) ->object($asserter->atKey(4)->notContains($inArray))->isIdenticalTo($asserter) ->exception(function() use ($asserter, $inArray) { $asserter->notContains($inArray); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s contains %s'), $asserter, $asserter->getTypeOf($inArray))) ->exception(function() use ($asserter, $inArray) { $asserter->atKey(2)->notContains($inArray); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s contains %s at key %s'), $asserter, $asserter->getTypeOf($inArray), $asserter->getTypeOf(2))) ->exception(function() use ($asserter, $inArray) { $asserter->atKey('2')->notContains($inArray); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s contains %s at key %s'), $asserter, $asserter->getTypeOf($inArray), $asserter->getTypeOf('2'))) ; } public function testStrictlyContains() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->contains(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Array is undefined') ->and($asserter->setWith(array(1, 2, 3, 4, 5, '3'))) ->then ->exception(function() use ($asserter) {$asserter->strictlyContains('1'); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s does not strictly contain %s'), $asserter, $asserter->getTypeOf('1'))) ->exception(function() use ($asserter, & $message) {$asserter->strictlyContains('1', $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->object($asserter->strictlyContains(1))->isIdenticalTo($asserter) ->exception(function() use ($asserter) { $asserter->atKey(0)->strictlyContains(2); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s does not strictly contain %s at key %s'), $asserter, $asserter->getTypeOf(2), $asserter->getTypeOf(0))) ->object($asserter->strictlyContains(2))->isIdenticalTo($asserter) ->object($asserter->atKey(2)->strictlyContains(3))->isIdenticalTo($asserter) ->exception(function() use ($asserter) { $asserter->atKey(2)->strictlyContains('3'); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s does not strictly contain %s at key %s'), $asserter, $asserter->getTypeOf('3'), $asserter->getTypeOf(2))) ; } public function testStrictlyNotContains() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->contains(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Array is undefined') ->if($asserter->setWith(array(1, 2, 3, 4, 5, '6'))) ->then ->exception(function() use ($asserter) {$asserter->strictlyNotContains(1); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s strictly contains %s'), $asserter, $asserter->getTypeOf(1))) ->exception(function() use ($asserter, & $message) {$asserter->strictlyNotContains(1, $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->object($asserter->strictlyNotContains('1'))->isIdenticalTo($asserter) ->object($asserter->atKey(1)->strictlyNotContains(1))->isIdenticalTo($asserter) ->object($asserter->atKey(2)->strictlyNotContains(1))->isIdenticalTo($asserter) ->object($asserter->atKey(3)->strictlyNotContains(1))->isIdenticalTo($asserter) ->object($asserter->atKey(4)->strictlyNotContains(1))->isIdenticalTo($asserter) ->exception(function() use ($asserter) { $asserter->strictlyNotContains(1); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s strictly contains %s'), $asserter, $asserter->getTypeOf(1))) ->exception(function() use ($asserter) { $asserter->atKey(0)->strictlyNotContains(1); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s strictly contains %s at key %s'), $asserter, $asserter->getTypeOf(1), $asserter->getTypeOf(0))) ->exception(function() use ($asserter) { $asserter->atKey('0')->strictlyNotContains(1); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s strictly contains %s at key %s'), $asserter, $asserter->getTypeOf(1), $asserter->getTypeOf('0'))) ; } public function testContainsValues() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->contains(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Array is undefined') ->if($asserter->setWith(array(1, 2, 3, 4, 5))) ->then ->exception(function() use ($asserter) { $asserter->containsValues(array(6)); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s does not contain values %s'), $asserter, $asserter->getTypeOf(array(6)))) ->exception(function() use ($asserter, & $message) { $asserter->containsValues(array(6), $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->exception(function() use ($asserter) { $asserter->containsValues(array('6')); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s does not contain values %s'), $asserter, $asserter->getTypeOf(array('6')))) ->exception(function() use ($asserter, & $message) { $asserter->containsValues(array('6'), $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->object($asserter->containsValues(array(1)))->isIdenticalTo($asserter) ->object($asserter->containsValues(array(1, 2, 4)))->isIdenticalTo($asserter) ->object($asserter->containsValues(array('1', 2, '4')))->isIdenticalTo($asserter) ; } public function testNotContainsValues() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->contains(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Array is undefined') ->if($asserter->setWith(array(1, 2, 3, 4, 5))) ->then ->exception(function() use ($asserter) { $asserter->notContainsValues(array(1, 6)); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s should not contain values %s'), $asserter, $asserter->getTypeOf(array(1)))) ->exception(function() use ($asserter, & $message) { $asserter->notContainsValues(array(1, 6), $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->exception(function() use ($asserter, & $message) { $asserter->notContainsValues(array('1', '6'), $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->object($asserter->containsValues(array(1)))->isIdenticalTo($asserter) ->object($asserter->containsValues(array(1, 2, 4)))->isIdenticalTo($asserter) ->object($asserter->containsValues(array('1', 2, '4')))->isIdenticalTo($asserter) ; } public function testStrictlyContainsValues() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->contains(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Array is undefined') ->if($asserter->setWith(array(1, 2, 3, 4, 5))) ->then ->exception(function() use ($asserter) { $asserter->strictlyContainsValues(array(6)); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s does not contain strictly values %s'), $asserter, $asserter->getTypeOf(array(6)))) ->exception(function() use ($asserter, & $message) { $asserter->strictlyContainsValues(array(6), $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->exception(function() use ($asserter) { $asserter->strictlyContainsValues(array('6')); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s does not contain strictly values %s'), $asserter, $asserter->getTypeOf(array('6')))) ->exception(function() use ($asserter, & $message) { $asserter->strictlyContainsValues(array('6'), $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->exception(function() use ($asserter, & $message) { $asserter->strictlyContainsValues(array('1'), $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->object($asserter->strictlyContainsValues(array(1)))->isIdenticalTo($asserter) ->object($asserter->strictlyContainsValues(array(1, 2, 4)))->isIdenticalTo($asserter) ->exception(function() use ($asserter, & $message) { $asserter->strictlyContainsValues(array('1', 2, '4'), $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ; } public function testStrictlyNotContainsValues() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->contains(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Array is undefined') ->if($asserter->setWith(array(1, 2, 3, 4, 5))) ->then ->exception(function() use ($asserter) { $asserter->strictlyNotContainsValues(array(1)); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s should not contain strictly values %s'), $asserter, $asserter->getTypeOf(array(1)))) ->exception(function() use ($asserter, & $message) { $asserter->strictlyNotContainsValues(array(1), $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->exception(function() use ($asserter, & $message) { $asserter->strictlyNotContainsValues(array(1, '2', 3), $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->object($asserter->strictlyNotContainsValues(array('1')))->isIdenticalTo($asserter) ->object($asserter->strictlyNotContainsValues(array(6, 7, '2', 8)))->isIdenticalTo($asserter) ; } public function testHasKey() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasKey(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Array is undefined') ->if($asserter->setWith(array())) ->then ->exception(function() use ($asserter, & $key) { $asserter->hasKey($key = rand(1, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s has no key %s'), $asserter, $asserter->getTypeOf($key))) ->exception(function() use ($asserter, & $key, & $message) { $asserter->hasKey($key = rand(1, PHP_INT_MAX), $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->if($asserter->setWith(array(uniqid(), uniqid(), uniqid(), uniqid(), uniqid()))) ->then ->object($asserter->hasKey(0))->isIdenticalTo($asserter) ->object($asserter->hasKey(1))->isIdenticalTo($asserter) ->object($asserter->hasKey(2))->isIdenticalTo($asserter) ->object($asserter->hasKey(3))->isIdenticalTo($asserter) ->object($asserter->hasKey(4))->isIdenticalTo($asserter) ->exception(function() use ($asserter) { $asserter->hasKey(5); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s has no key %s'), $asserter, $asserter->getTypeOf(5))) ->exception(function() use ($asserter, & $message) { $asserter->hasKey(5, $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ; } public function testNotHasKey() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasSize(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Array is undefined') ->if($asserter->setWith(array())) ->then ->object($asserter->notHasKey(1))->isIdenticalTo($asserter) ->if($asserter->setWith(array(uniqid(), uniqid(), uniqid(), uniqid(), uniqid()))) ->then ->exception(function() use ($asserter) { $asserter->notHasKey(0); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s has a key %s'), $asserter, $asserter->getTypeOf(0))) ->exception(function() use ($asserter, & $message) { $asserter->notHasKey(0, $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->object($asserter->notHasKey(5))->isIdenticalTo($asserter) ; } public function testNotHasKeys() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasSize(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Array is undefined') ->if($asserter->setWith(array())) ->then ->object($asserter->notHasKeys(array(1)))->isIdenticalTo($asserter) ->object($asserter->notHasKeys(array(0, 1)))->isIdenticalTo($asserter) ->if($asserter->setWith(array(uniqid(), uniqid(), uniqid(), uniqid(), uniqid()))) ->then ->exception(function() use ($asserter) { $asserter->notHasKeys(array(0, 'premier', 2)); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s should not have keys %s'), $asserter, $asserter->getTypeOf(array(0, 2)))) ->exception(function() use ($asserter, & $message) { $asserter->notHasKeys(array(0, 'premier', 2), $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->object($asserter->notHasKeys(array(5, '6')))->isIdenticalTo($asserter) ; } public function testHasKeys() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasSize(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Array is undefined') ->if($asserter->setWith(array())) ->then ->exception(function() use ($asserter) { $asserter->hasKeys(array(0)); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s should have keys %s'), $asserter, $asserter->getTypeOf(array(0)))) ->exception(function() use ($asserter, & $message) { $asserter->hasKeys(array(0), $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->if($asserter->setWith(array(uniqid(), uniqid(), uniqid(), uniqid(), uniqid()))) ->then ->exception(function() use ($asserter) { $asserter->hasKeys(array(0, 'first', 2, 'second')); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s should have keys %s'), $asserter, $asserter->getTypeOf(array('first', 'second')))) ->exception(function() use ($asserter, & $message) { $asserter->hasKeys(array(0, 'first', 2, 'second'), $message = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($message) ->object($asserter->hasKeys(array(0, 2, 4)))->isIdenticalTo($asserter) ; } public function testSize() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->size; }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Array is undefined') ->if($asserter->setWith(array())) ->then ->object($integer = $asserter->size) ->isInstanceOf('mageekguy\atoum\asserters\integer') ->integer($integer->getValue()) ->isEqualTo(0) ->if($asserter->setWith(array(uniqid(), uniqid()))) ->then ->object($integer = $asserter->size) ->isInstanceOf('mageekguy\atoum\asserters\integer') ->integer($integer->getValue()) ->isEqualTo(2) ; } } mockGenerator ->shunt('__construct') ; } public function testClass() { $this->testedClass->isSubclassOf('mageekguy\atoum\asserter'); } public function test__construct() { $this->assert ->if($asserter = new asserters\phpClass($generator = new asserter\generator())) ->then ->object($asserter->getLocale())->isIdenticalTo($generator->getLocale()) ->object($asserter->getGenerator())->isIdenticalTo($generator) ; } public function testGetClass() { $this ->if($asserter = new asserters\phpClass($generator = new asserter\generator())) ->then ->variable($asserter->getClass())->isNull() ->if($asserter->setWith(__CLASS__)) ->then ->string($asserter->getClass())->isEqualTo(__CLASS__) ; } public function testSetReflectionClassInjector() { $this ->if($asserter = new asserters\phpClass($generator = new asserter\generator())) ->then ->object($asserter->setReflectionClassInjector(function($class) use (& $reflectionClass) { return ($reflectionClass = new \mock\reflectionClass($class)); }))->isIdenticalTo($asserter) ->object($asserter->getReflectionClass($class = uniqid()))->isIdenticalTo($reflectionClass) ->exception(function() use ($asserter) { $asserter->setReflectionClassInjector(function() {}); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument') ->hasMessage('Reflection class injector must take one argument') ; } public function testGetReflectionClass() { $this ->if($asserter = new asserters\phpClass($generator = new asserter\generator())) ->then ->object($asserter->getReflectionClass(__CLASS__))->isInstanceOf('reflectionClass') ->string($asserter->getReflectionClass(__CLASS__)->getName())->isEqualTo(__CLASS__) ->if($asserter->setReflectionClassInjector(function($class) use (& $reflectionClass) { return ($reflectionClass = new \mock\reflectionClass($class)); })) ->then ->object($asserter->getReflectionClass($class = uniqid()))->isIdenticalTo($reflectionClass) ->mock($reflectionClass)->call('__construct')->withArguments($class)->once() ->if($asserter->setReflectionClassInjector(function($class) use (& $reflectionClass) { return uniqid(); })) ->then ->exception(function() use ($asserter) { $asserter->getReflectionClass(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\runtime\unexpectedValue') ->hasMessage('Reflection class injector must return a \reflectionClass instance') ; } public function testSetWith() { $this ->if($asserter = new asserters\phpClass($generator = new asserter\generator())) ->and($mockController = new atoum\mock\controller()) ->and($mockController->__construct = function() { throw new \reflectionException();}) ->and($asserter->setReflectionClassInjector(function($class) use ($mockController) { return new \mock\reflectionClass($class, $mockController); })) ->and($class = uniqid()) ->then ->exception(function() use ($asserter, $class) { $asserter->setWith($class); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('Class \'%s\' does not exist'), $class)) ->if($asserter = new asserters\phpClass($generator = new asserter\generator())) ->then ->object($asserter->setWith(__CLASS__))->isIdenticalTo($asserter) ->string($asserter->getClass())->isEqualTo(__CLASS__) ; } public function testHasParent() { $this ->if($asserter = new asserters\phpClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasParent(uniqid()); }) ->isInstanceOf('logicException') ->hasMessage('Class is undefined') ->if($class = uniqid()) ->and($parent = uniqid()) ->and($mockController = new atoum\mock\controller()) ->and($mockController->getName = function() use ($class) { return $class; }) ->and($asserter ->setReflectionClassInjector(function($class) use ($mockController) { return new \mock\reflectionClass($class, $mockController); }) ->setWith($class) ) ->and($parentMockController = new atoum\mock\controller()) ->and($parentMockController->getName = function() { return uniqid(); }) ->and($mockController->getParentClass = function() use ($parent, $parentMockController) { return new \mock\reflectionClass($parent, $parentMockController); }) ->then ->exception(function() use ($asserter, $parent) { $asserter->hasParent($parent); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not the parent of class %s'), $parent, $class)) ->if($parentMockController->getName = function() use ($parent) { return $parent; }) ->then ->object($asserter->hasParent($parent))->isIdenticalTo($asserter) ->object($asserter->hasParent(strtoupper($parent)))->isIdenticalTo($asserter) ; } public function testHasNoParent() { $this ->if($asserter = new asserters\phpClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasNoParent(); }) ->isInstanceOf('logicException') ->hasMessage('Class is undefined') ->if($reflectionClass = new \mock\reflectionClass($className = uniqid())) ->and($asserter ->setReflectionClassInjector(function($class) use ($reflectionClass) { return $reflectionClass; }) ->setWith($class = uniqid()) ) ->and($reflectionClass->getMockController()->getName = function() use ($className) { return $className; }) ->and($reflectionClass->getMockController()->getParentClass = function() { return false; }) ->then ->object($asserter->hasNoParent())->isIdenticalTo($asserter) ->if($parentClass = new \mock\reflectionClass($parentClassName = uniqid())) ->and($parentClass->getMockController()->__toString = function() use ($parentClassName) { return $parentClassName; }) ->and($reflectionClass->getMockController()->getParentClass = function() use ($parentClass) { return $parentClass; }) ->then ->exception(function() use ($asserter) { $asserter->hasNoParent(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('class %s has parent %s'), $className, $parentClass)) ; } public function testIsSubclassOf() { $this ->if($asserter = new asserters\phpClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->isSubclassOf(uniqid()); }) ->isInstanceOf('logicException') ->hasMessage('Class is undefined') ->if($class = uniqid()) ->and($parentClass = uniqid()) ->and($mockController = new atoum\mock\controller()) ->and($mockController->__construct = function() {}) ->and($mockController->getName = function() use ($class) { return $class; }) ->and($asserter ->setReflectionClassInjector(function($class) use ($mockController) { return new \mock\reflectionClass($class, $mockController); }) ->setWith($class) ) ->and($mockController->isSubclassOf = false) ->then ->exception(function() use ($asserter, $parentClass) { $asserter->isSubclassOf($parentClass); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('Class %s is not a sub-class of %s'), $class, $parentClass)) ->if($mockController->isSubclassOf = true) ->then ->object($asserter->isSubclassOf($parentClass))->isIdenticalTo($asserter) ; } public function testExtends() { $this ->if($asserter = new asserters\phpClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->extends(uniqid()); }) ->isInstanceOf('logicException') ->hasMessage('Class is undefined') ->if($class = uniqid()) ->and($parentClass = uniqid()) ->and($mockController = new atoum\mock\controller()) ->and($mockController->__construct = function() {}) ->and($mockController->getName = function() use ($class) { return $class; }) ->and($asserter ->setReflectionClassInjector(function($class) use ($mockController) { return new \mock\reflectionClass($class, $mockController); }) ->setWith($class) ) ->and($mockController->isSubclassOf = false) ->then ->exception(function() use ($asserter, $parentClass) { $asserter->extends($parentClass); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('Class %s is not a sub-class of %s'), $class, $parentClass)) ->if($mockController->isSubclassOf = true) ->then ->object($asserter->extends($parentClass))->isIdenticalTo($asserter) ; } public function testHasInterface() { $this ->if($asserter = new asserters\phpClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasInterface(uniqid()); }) ->isInstanceOf('logicException') ->hasMessage('Class is undefined') ->if($class = uniqid()) ->and($interface = uniqid()) ->and($mockController = new atoum\mock\controller()) ->and($mockController->__construct = function() {}) ->and($mockController->getName = function() use ($class) { return $class; }) ->and($asserter ->setReflectionClassInjector(function($class) use ($mockController) { return new \mock\reflectionClass($class, $mockController); }) ->setWith($class) ) ->and($mockController->implementsInterface = false) ->then ->exception(function() use ($asserter, $interface) { $asserter->hasInterface($interface); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('Class %s does not implement interface %s'), $class, $interface)) ->if($mockController->implementsInterface = true) ->then ->object($asserter->hasInterface($interface))->isIdenticalTo($asserter) ; } public function testImplements() { $this ->if($asserter = new asserters\phpClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->implements(uniqid()); }) ->isInstanceOf('logicException') ->hasMessage('Class is undefined') ->if($class = uniqid()) ->and($interface = uniqid()) ->and($mockController = new atoum\mock\controller()) ->and($mockController->__construct = function() {}) ->and($mockController->getName = function() use ($class) { return $class; }) ->and($asserter ->setReflectionClassInjector(function($class) use ($mockController) { return new \mock\reflectionClass($class, $mockController); }) ->setWith($class) ) ->and($mockController->implementsInterface = false) ->then ->exception(function() use ($asserter, $interface) { $asserter->implements($interface); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('Class %s does not implement interface %s'), $class, $interface)) ->if($mockController->implementsInterface = true) ->then ->object($asserter->implements($interface))->isIdenticalTo($asserter) ; } public function testIsAbstract() { $this ->if($asserter = new asserters\phpClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->isAbstract(); }) ->isInstanceOf('logicException') ->hasMessage('Class is undefined') ->if($class = uniqid()) ->and($mockController = new atoum\mock\controller()) ->and($mockController->__construct = function() {}) ->and($mockController->getName = function() use ($class) { return $class; }) ->and($asserter ->setReflectionClassInjector(function($class) use ($mockController) { return new \mock\reflectionClass($class, $mockController); }) ->setWith($class) ) ->and($mockController->isAbstract = false) ->then ->exception(function() use ($asserter) { $asserter->isAbstract(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('Class %s is not abstract'), $class)) ->if($mockController->isAbstract = true) ->then ->object($asserter->isAbstract())->isIdenticalTo($asserter) ; } public function testHasMethod() { $this ->if($asserter = new asserters\phpClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasMethod(uniqid()); }) ->isInstanceOf('logicException') ->hasMessage('Class is undefined') ->if($class = uniqid()) ->and($method = uniqid()) ->and($reflectionClass = new \mock\reflectionClass($class = uniqid())) ->and($reflectionClassController = $reflectionClass->getMockController()) ->and($reflectionClassController->getName = $class) ->and($reflectionClassController->hasMethod = false) ->and($asserter ->setReflectionClassInjector(function($class) use ($reflectionClass) { return $reflectionClass; }) ->setWith($class) ) ->then ->exception(function() use ($asserter, $method) { $asserter->hasMethod($method); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('Method %s::%s() does not exist'), $class, $method)) ->if($reflectionClassController->hasMethod = true) ->then ->object($asserter->hasMethod(uniqid()))->isIdenticalTo($asserter) ; } } testedClass->isSubclassOf('mageekguy\atoum\asserters\integer'); } public function test__construct() { $this ->if($asserter = new asserters\sizeOf($generator = new asserter\generator())) ->then ->object($asserter->getLocale())->isIdenticalTo($generator->getLocale()) ->object($asserter->getGenerator())->isIdenticalTo($generator) ->variable($asserter->getValue())->isNull() ->boolean($asserter->wasSet())->isFalse() ; } public function testSetWith() { $this ->if($asserter = new asserters\sizeOf($generator = new asserter\generator())) ->then ->object($asserter->setWith(array()))->isIdenticalTo($asserter) ->boolean($asserter->wasSet())->isTrue() ->integer($asserter->getValue())->isZero() ->object($asserter->setWith($countable = range(1, rand(2, 5))))->isIdenticalTo($asserter) ->boolean($asserter->wasSet())->isTrue() ->integer($asserter->getValue())->isEqualTo(sizeof($countable)) ; } } testedClass->extends('mageekguy\atoum\asserter'); } public function test__construct() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->variable($asserter->getStreamController())->isNull() ->object($asserter->getGenerator())->isIdenticalTo($generator) ->object($asserter->getLocale())->isIdenticalTo($generator->getLocale()) ; } public function testSetWith() { $this ->if($asserter = new testedClass(new asserter\generator())) ->then ->object($asserter->setWith($stream = uniqid()))->isIdenticalTo($asserter) ->object($asserter->getStreamController())->isEqualTo(atoum\mock\stream::get($stream)) ->if(atoum\mock\stream::get($stream = uniqid())) ->then ->object($asserter->setWith($stream))->isIdenticalTo($asserter) ->object($asserter->getStreamController())->isIdenticalTo(atoum\mock\stream::get($stream)) ; } public function testIsRead() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->isRead(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Stream is undefined') ->if($streamController = atoum\mock\stream::get($streamName = uniqid())) ->and($streamController->file_get_contents = uniqid()) ->and($asserter->setWith($streamName)) ->then ->exception(function() use ($asserter) { $asserter->isRead(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($failMessage = sprintf($generator->getLocale()->_('stream %s is not read'), $streamController)) ->when(function() use ($streamName) { file_get_contents('atoum://' . $streamName); }) ->object($asserter->isRead())->isIdenticalTo($asserter) ; } public function testIsWrited() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->isWrited(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Stream is undefined') ->if($streamController = atoum\mock\stream::get($streamName = uniqid())) ->and($streamController->file_put_contents = strlen($contents = uniqid())) ->and($asserter->setWith($streamName)) ->then ->exception(function() use ($asserter) { $asserter->isWrited(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($failMessage = sprintf($generator->getLocale()->_('stream %s is not writed'), $streamController)) ->when(function() use ($streamName, $contents) { file_put_contents('atoum://' . $streamName, $contents); }) ->object($asserter->isWrited())->isIdenticalTo($asserter) ->if($streamController = atoum\mock\stream::get(uniqid())) ->and($streamController->file_put_contents = strlen($contents = uniqid())) ->and($asserter->setWith($streamController)) ->then ->exception(function() use ($asserter) { $asserter->isWrited(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($failMessage = sprintf($generator->getLocale()->_('stream %s is not writed'), $streamController)) ->when(function() use ($streamController, $contents) { file_put_contents($streamController, $contents); }) ->object($asserter->isWrited())->isIdenticalTo($asserter) ; } } testedClass->extends('mageekguy\atoum\asserters\variable'); } public function test__construct() { $this ->if($asserter = new testedClass()) ->then ->object($asserter->getGenerator())->isEqualTo(new asserter\generator()) ->object($asserter->getLocale())->isIdenticalTo($asserter->getGenerator()->getLocale()) ->object($asserter->getAdapter())->isEqualTo(new atoum\adapter()) ->variable($asserter->getValue())->isNull() ->boolean($asserter->wasSet())->isFalse() ->if($asserter = new testedClass($generator = new asserter\generator(), $adapter = new atoum\adapter())) ->then ->object($asserter->getLocale())->isIdenticalTo($generator->getLocale()) ->object($asserter->getGenerator())->isIdenticalTo($generator) ->object($asserter->getAdapter())->isIdenticalTo($adapter) ->variable($asserter->getValue())->isNull() ->boolean($asserter->wasSet())->isFalse() ; } public function test__toString() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->and($asserter->setWith($value = uniqid())) ->then ->castToString($asserter)->isEqualTo('string(' . strlen($value) . ') \'' . $value . '\'') ->if($asserter->setWith($value = "\010" . uniqid() . "\010", null, $charlist = "\010")) ->then ->castToString($asserter)->isEqualTo('string(' . strlen($value) . ') \'' . addcslashes($value, "\010") . '\'') ; } public function testSetAdapter() { $this ->if($asserter = new testedClass()) ->then ->object($asserter->setAdapter($adapter = new atoum\adapter()))->isIdenticalTo($asserter) ->object($asserter->getAdapter())->isIdenticalTo($adapter) ->object($asserter->setAdapter())->isIdenticalTo($asserter) ->object($asserter->getAdapter()) ->isNotIdenticalTo($adapter) ->isEqualTo(new atoum\adapter()) ; } public function testSetWith() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use (& $line, $asserter, & $value) { $line = __LINE__; $asserter->setWith($value = rand(- PHP_INT_MAX, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not a string'), $asserter->getTypeOf($value))) ->integer($asserter->getValue())->isEqualTo($value) ->variable($asserter->getCharlist())->isNull() ->object($asserter->setWith($value = uniqid()))->isIdenticalTo($asserter) ->string($asserter->getValue())->isEqualTo($value) ->variable($asserter->getCharlist())->isNull() ->object($asserter->setWith($value = uniqid(), null, $charlist = "\010"))->isIdenticalTo($asserter) ->string($asserter->getValue())->isEqualTo($value) ->string($asserter->getCharlist())->isEqualTo($charlist) ; } public function testIsEqualTo() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->boolean($asserter->wasSet())->isFalse() ->exception(function() use ($asserter) { $asserter->isEqualTo(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Value is undefined') ->if($asserter->setWith($firstString = uniqid())) ->and($diff = new diffs\variable()) ->then ->exception(function() use ($asserter, & $secondString) { $asserter->isEqualTo($secondString = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($generator->getLocale()->_('strings are not equals') . PHP_EOL . $diff->setReference($secondString)->setData($firstString)) ->object($asserter->isEqualTo($firstString))->isIdenticalTo($asserter) ; } public function testIsEqualToFileContents() { $this ->if($asserter = new testedClass($generator = new asserter\generator(), $adapter = new atoum\test\adapter())) ->then ->boolean($asserter->wasSet())->isFalse() ->exception(function() use ($asserter) { $asserter->isEqualToContentsOfFile(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Value is undefined') ->if($asserter->setWith($firstString = uniqid())) ->and($adapter->file_get_contents = false) ->then ->exception(function() use ($asserter, & $path) { $asserter->isEqualToContentsOfFile($path = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('Unable to get contents of file %s'), $path)) ->if($adapter->file_get_contents = $fileContents = uniqid()) ->and($diff = new diffs\variable()) ->then ->exception(function() use ($asserter, & $path) { $asserter->isEqualToContentsOfFile($path); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('string is not equals to contents of file %s'), $path) . PHP_EOL . $diff->setReference($fileContents)->setData($firstString)) ->if($adapter->file_get_contents = $firstString) ->then ->object($asserter->isEqualToContentsOfFile(uniqid()))->isIdenticalTo($asserter) ; } public function testIsEmpty() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->isEmpty(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Value is undefined') ->if($asserter->setWith($string = uniqid())) ->and($diff = new diffs\variable()) ->then ->exception(function() use ($asserter) { $asserter->isEmpty(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($generator->getLocale()->_('strings are not equals') . PHP_EOL . $diff->setReference('')->setData($string)) ->if($asserter->setWith('')) ->then ->object($asserter->isEmpty())->isIdenticalTo($asserter) ; } public function testIsNotEmpty() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->isNotEmpty(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Value is undefined') ->if($asserter->setWith('')) ->and($diff = new diffs\variable()) ->then ->exception(function() use ($asserter) { $asserter->isNotEmpty(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($generator->getLocale()->_('string is empty')) ->if($asserter->setWith($string = uniqid())) ->then ->object($asserter->isNotEmpty())->isIdenticalTo($asserter) ; } public function testHasLength() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasLength(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Value is undefined') ->if($asserter->setWith('')) ->and($diff = new diffs\variable()) ->then ->exception(function() use ($asserter, & $requiredLength) { $asserter->hasLength($requiredLength = rand(1, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('length of %s is not %d'), $asserter->getTypeOf(''), $requiredLength)) ->object($asserter->hasLength(0))->isIdenticalTo($asserter) ->if($asserter->setWith($string = uniqid())) ->then ->object($asserter->hasLength(strlen($string)))->isIdenticalTo($asserter) ; } public function testHasLengthGreaterThan() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasLengthGreaterThan(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Value is undefined') ->if($asserter->setWith('Chuck Norris')) ->and($diff = new diffs\variable()) ->then ->exception(function() use ($asserter, & $requiredLength) { $asserter->hasLengthGreaterThan($requiredLength = rand(1, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('length of %s is not greater than %d'), $asserter->getTypeOf('Chuck Norris'), $requiredLength)) ->object($asserter->hasLengthGreaterThan(0))->isIdenticalTo($asserter) ->if($asserter->setWith($string = uniqid())) ->then ->object($asserter->hasLengthGreaterThan(strlen($string)-1))->isIdenticalTo($asserter) ; } public function testHasLengthLessThan() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasLengthLessThan(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Value is undefined') ->if($asserter->setWith('Chuck Norris')) ->and($diff = new diffs\variable()) ->then ->exception(function() use ($asserter, & $requiredLength) { $asserter->hasLengthLessThan($requiredLength = 10); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('length of %s is not less than %d'), $asserter->getTypeOf('Chuck Norris'), $requiredLength)) ->object($asserter->hasLengthLessThan(20))->isIdenticalTo($asserter) ->if($asserter->setWith($string = uniqid())) ->then ->object($asserter->hasLengthLessThan(strlen($string)+1))->isIdenticalTo($asserter) ; } public function testContains() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->contains(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Value is undefined') ->if($asserter->setWith($string = __METHOD__)) ->and($diff = new diffs\variable()) ->then ->exception(function() use ($asserter, & $fragment) { $asserter->contains($fragment = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($this->getLocale()->_('String does not contain %s'), $fragment)) ->object($asserter->contains($string))->isIdenticalTo($asserter) ->if($asserter->setWith(uniqid() . $string . uniqid())) ->then ->object($asserter->contains($string))->isIdenticalTo($asserter) ->exception(function() use ($asserter, $string, & $fragment) { $asserter->contains($fragment = strtoupper($string)); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($this->getLocale()->_('String does not contain %s'), $fragment)) ; } public function testLength() { $this ->if($asserter = new testedClass($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->length; }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Value is undefined') ->if($asserter->setWith('')) ->then ->object($integer = $asserter->length) ->isInstanceOf('mageekguy\atoum\asserters\integer') ->integer($integer->getValue()) ->isEqualTo(0) ->if($asserter->setWith($str = uniqid())) ->then ->object($integer = $asserter->length) ->isInstanceOf('mageekguy\atoum\asserters\integer') ->integer($integer->getValue()) ->isEqualTo(strlen($str)) ; } } testedClass->isSubclassOf('mageekguy\atoum\asserters\phpClass'); } public function testSetWith() { $this ->if($asserter = new asserters\testedClass(new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->setWith(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic\badMethodCall') ->hasMessage('Unable to call method ' . get_class($asserter) . '::setWith()') ; } } testedClass->extends('mageekguy\atoum\asserters\string'); } public function test__construct() { $this ->if($asserter = new asserters\utf8String()) ->then ->object($asserter->getGenerator())->isEqualTo(new asserter\generator()) ->object($asserter->getLocale())->isIdenticalTo($asserter->getGenerator()->getLocale()) ->object($asserter->getAdapter())->isEqualTo(new atoum\adapter()) ->variable($asserter->getValue())->isNull() ->boolean($asserter->wasSet())->isFalse() ->if($asserter = new asserters\utf8String($generator = new asserter\generator())) ->then ->object($asserter->getGenerator())->isIdenticalTo($generator) ->object($asserter->getLocale())->isIdenticalTo($generator->getLocale()) ->object($asserter->getAdapter())->isEqualTo(new atoum\adapter()) ->variable($asserter->getValue())->isNull() ->boolean($asserter->wasSet())->isFalse() ->if($adapter = new atoum\test\adapter()) ->and($adapter->extension_loaded = true) ->and($asserter = new asserters\utf8String($generator = new asserter\generator(), $adapter)) ->then ->object($asserter->getGenerator())->isIdenticalTo($generator) ->object($asserter->getLocale())->isIdenticalTo($generator->getLocale()) ->object($asserter->getAdapter())->isEqualTo($adapter) ->variable($asserter->getValue())->isNull() ->boolean($asserter->wasSet())->isFalse() ->if($adapter->extension_loaded = false) ->then ->exception(function() use ($adapter) { new asserters\utf8String(new asserter\generator(), $adapter); }) ->isInstanceOf('mageekguy\atoum\exceptions\runtime') ->hasMessage('mbstring PHP extension is mandatory to use utf8String asserter') ; } public function test__toString() { $this ->if($asserter = new asserters\utf8String($generator = new asserter\generator())) ->and($asserter->setWith($value = $this->getRandomUtf8String())) ->then ->castToString($asserter)->isEqualTo('string(' . mb_strlen($value, 'UTF-8') . ') \'' . $value . '\'') ->if($asserter->setWith($value = "\010" . $this->getRandomUtf8String() . "\010", null, $charlist = "\010")) ->then ->castToString($asserter)->isEqualTo('string(' . mb_strlen($value, 'UTF-8') . ') \'' . addcslashes($value, "\010") . '\'') ; } public function testSetWith() { $this ->if($asserter = new asserters\utf8String($generator = new asserter\generator())) ->then ->exception(function() use ($asserter, & $value) { $asserter->setwith($value = rand(- PHP_INT_MAX, PHP_INT_MAX)); }) ->isinstanceof('mageekguy\atoum\asserter\exception') ->hasmessage(sprintf($generator->getlocale()->_('%s is not a string'), $asserter->gettypeof($value))) ->exception(function() use ($asserter, & $value) { $asserter->setwith("\xf0\x28\x8c\xbc"); }) ->isinstanceof('mageekguy\atoum\asserter\exception') ->hasmessage(sprintf($generator->getlocale()->_('\'%s\' is not an UTF-8 string'), "\xf0\x28\x8c\xbc")) ->exception(function() use ($asserter, & $value) { $asserter->setwith("\xf8\xa1\xa1\xa1\xa1"); }) ->isinstanceof('mageekguy\atoum\asserter\exception') ->hasmessage(sprintf($generator->getlocale()->_('\'%s\' is not an UTF-8 string'), "\xf8\xa1\xa1\xa1\xa1")) ->object($asserter->setWith(uniqid()))->isIdenticalTo($asserter) ; } public function testIsEqualTo() { $this ->if($asserter = new asserters\utf8String($generator = new asserter\generator())) ->then ->boolean($asserter->wasSet())->isFalse() ->exception(function() use ($asserter) { $asserter->isEqualTo(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Value is undefined') ->if($asserter->setWith($firstString = $this->getRandomUtf8String())) ->and($diff = new diffs\variable()) ->and($secondString = $this->getRandomUtf8String()) ->then ->exception(function() use ($asserter, $secondString) { $asserter->isEqualTo($secondString); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($generator->getLocale()->_('strings are not equals') . PHP_EOL . $diff->setReference($secondString)->setData($firstString)) ->object($asserter->isEqualTo($firstString))->isIdenticalTo($asserter) ; } public function testIsEqualToFileContents() { $this ->if($asserter = new asserters\utf8String($generator = new asserter\generator(), $adapter = new atoum\test\adapter())) ->then ->boolean($asserter->wasSet())->isFalse() ->exception(function() use ($asserter) { $asserter->isEqualToContentsOfFile(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Value is undefined') ->if($asserter->setWith($firstString = $this->getRandomUtf8String())) ->and($adapter->file_get_contents = false) ->then ->exception(function() use ($asserter, & $path) { $asserter->isEqualToContentsOfFile($path = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('Unable to get contents of file %s'), $path)) ->if($adapter->file_get_contents = $fileContents = $this->getRandomUtf8String()) ->and($diff = new diffs\variable()) ->then ->exception(function() use ($asserter, & $path) { $asserter->isEqualToContentsOfFile($path); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('string is not equals to contents of file %s'), $path) . PHP_EOL . $diff->setReference($fileContents)->setData($firstString)) ->if($adapter->file_get_contents = $firstString) ->then ->object($asserter->isEqualToContentsOfFile($this->getRandomUtf8String()))->isIdenticalTo($asserter) ; } public function testIsEmpty() { $this ->if($asserter = new asserters\utf8String($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->isEmpty(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Value is undefined') ->if($asserter->setWith($string = $this->getRandomUtf8String())) ->and($diff = new diffs\variable()) ->then ->exception(function() use ($asserter) { $asserter->isEmpty(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($generator->getLocale()->_('strings are not equals') . PHP_EOL . $diff->setReference('')->setData($string)) ->if($asserter->setWith('')) ->then ->object($asserter->isEmpty())->isIdenticalTo($asserter) ; } public function testIsNotEmpty() { $this ->if($asserter = new asserters\utf8String($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->isNotEmpty(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Value is undefined') ->if($asserter->setWith('')) ->and($diff = new diffs\variable()) ->then ->exception(function() use ($asserter) { $asserter->isNotEmpty(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($generator->getLocale()->_('string is empty')) ->if($asserter->setWith($string = $this->getRandomUtf8String())) ->then ->object($asserter->isNotEmpty())->isIdenticalTo($asserter) ; } public function testHasLength() { $this ->if($asserter = new asserters\utf8String($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasLength(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Value is undefined') ->if($asserter->setWith('')) ->and($diff = new diffs\variable()) ->then ->exception(function() use ($asserter, & $requiredLength) { $asserter->hasLength($requiredLength = rand(1, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('length of %s is not %d'), $asserter->getTypeOf(''), $requiredLength)) ->object($asserter->hasLength(0))->isIdenticalTo($asserter) ->if($asserter->setWith($string = $this->getRandomUtf8String())) ->then ->object($asserter->hasLength(mb_strlen($string, 'UTF-8')))->isIdenticalTo($asserter) ; } public function testHasLengthGreaterThan() { $this ->if($asserter = new asserters\utf8String($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasLengthGreaterThan(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Value is undefined') ->if($asserter->setWith($string = $this->getRandomUtf8String())) ->and($diff = new diffs\variable()) ->then ->exception(function() use ($asserter, $string) { $asserter->hasLengthGreaterThan(mb_strlen($string, 'UTF-8')); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('length of %s is not greater than %d'), $asserter->getTypeOf($string), mb_strlen($string, 'UTF-8'))) ->object($asserter->hasLengthGreaterThan(0))->isIdenticalTo($asserter) ->if($asserter->setWith($string = $this->getRandomUtf8String())) ->then ->object($asserter->hasLengthGreaterThan(mb_strlen($string, 'UTF-8') - 1))->isIdenticalTo($asserter) ; } public function testHasLengthLessThan() { $this ->if($asserter = new asserters\utf8String($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->hasLengthLessThan(rand(0, PHP_INT_MAX)); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Value is undefined') ->if($asserter->setWith($string = $this->getRandomUtf8String())) ->and($diff = new diffs\variable()) ->then ->exception(function() use ($asserter, $string) { $asserter->hasLengthLessThan(mb_strlen($string, 'UTF-8')); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('length of %s is not less than %d'), $asserter->getTypeOf($string), mb_strlen($string, 'UTF-8'))) ->object($asserter->hasLengthLessThan(20))->isIdenticalTo($asserter) ->if($asserter->setWith($string = $this->getRandomUtf8String())) ->then ->object($asserter->hasLengthLessThan(mb_strlen($string, 'UTF-8') + 1))->isIdenticalTo($asserter) ; } public function testContains() { $this ->if($asserter = new asserters\utf8String($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->contains(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Value is undefined') ->if($asserter->setWith($string = $this->getRandomUtf8String())) ->and($diff = new diffs\variable()) ->and($fragment = $this->getRandomUtf8String()) ->then ->exception(function() use ($asserter, $fragment) { $asserter->contains($fragment); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($this->getLocale()->_('String does not contain %s'), $fragment)) ->object($asserter->contains($string))->isIdenticalTo($asserter) ->if($asserter->setWith($this->getRandomUtf8String() . $string . $this->getRandomUtf8String())) ->then ->object($asserter->contains($string))->isIdenticalTo($asserter) ->exception(function() use ($asserter, $string, & $fragment) { $asserter->contains($fragment = mb_strtoupper($string, 'UTF-8')); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($this->getLocale()->_('String does not contain %s'), $fragment)) ->exception(function() use ($asserter) { $asserter->contains("\xf0\x28\x8c\xbc"); } ) ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument') ->hasMessage('Fragment \'' . "\xf0\x28\x8c\xbc" . '\' is not an UTF-8 string') ; } public function testLength() { $this ->if($asserter = new asserters\utf8String($generator = new asserter\generator())) ->then ->exception(function() use ($asserter) { $asserter->length; }) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Value is undefined') ->if($asserter->setWith('')) ->then ->object($integer = $asserter->length) ->isInstanceOf('mageekguy\atoum\asserters\integer') ->integer($integer->getValue()) ->isEqualTo(0) ->if($asserter->setWith($str = uniqid())) ->then ->object($integer = $asserter->length) ->isInstanceOf('mageekguy\atoum\asserters\integer') ->integer($integer->getValue()) ->isEqualTo(strlen($str)) ->if($asserter->setWith($str = $this->getRandomUtf8String())) ->then ->object($integer = $asserter->length) ->isInstanceOf('mageekguy\atoum\asserters\integer') ->integer($integer->getValue()) ->isEqualTo(mb_strlen($str, 'UTF-8')) ; } /********* * HELPER * *********/ private function getRandomUtf8String() { $characters = 'àâäéèêëîïôöùüŷÿ'; $characters = mb_convert_encoding($characters, 'UTF-8', mb_detect_encoding($characters)); $charactersLength = mb_strlen($characters, 'UTF-8'); $utf8String = ''; for($i = 0; $i < 16; $i++) { $utf8String .= mb_substr($characters, rand(0, $charactersLength - 1), 1, 'UTF-8'); } return $utf8String; } } testedClass->isSubclassOf('mageekguy\atoum\asserter'); } public function test__construct() { $this ->if($asserter = new asserters\variable($generator = new asserter\generator())) ->then ->object($asserter->getLocale())->isIdenticalTo($generator->getLocale()) ->object($asserter->getGenerator())->isIdenticalTo($generator) ->variable($asserter->getValue())->isNull() ->boolean($asserter->wasSet())->isFalse() ; } public function test__get() { $this ->if($asserter = new asserters\variable($generator = new asserter\generator())) ->then ->exception(function() use ($asserter, & $property) { $asserter->{$property = uniqid()}; }) ->isInstanceOf('logicException') ->hasMessage('Asserter \'' . $property . '\' does not exist') ->variable($asserter->getValue())->isNull() ->if($asserter->setWith($value = uniqid())) ->then ->string($asserter->getValue())->isEqualTo($value) ; } public function testReset() { $this ->if($asserter = new asserters\variable($generator = new asserter\generator())) ->and($asserter->setWith(uniqid())) ->then ->variable($asserter->getValue())->isNotNull() ->boolean($asserter->wasSet())->isTrue() ->object($asserter->reset())->isIdenticalTo($asserter) ->variable($asserter->getValue())->isNull() ->boolean($asserter->wasSet())->isFalse() ; } public function testSetWith() { $this ->if($asserter = new asserters\variable($generator = new asserter\generator())) ->and($value = uniqid()) ->then ->boolean($asserter->isSetByReference())->isFalse() ->object($asserter->setWith($value))->isIdenticalTo($asserter) ->variable($asserter->getValue())->isIdenticalTo($value) ->boolean($asserter->isSetByReference())->isFalse() ; } public function testSetByReferenceWith() { $this ->if($asserter = new asserters\variable($generator = new asserter\generator())) ->and($value = uniqid()) ->then ->boolean($asserter->isSetByReference())->isFalse() ->object($asserter->setByReferenceWith($value))->isIdenticalTo($asserter) ->variable($asserter->getValue())->isIdenticalTo($value) ->boolean($asserter->isSetByReference())->isTrue() ; } public function testIsSetByReference() { $this ->if($asserter = new asserters\variable($generator = new asserter\generator())) ->then ->boolean($asserter->isSetByReference())->isFalse() ->if($asserter->setWith(uniqid())) ->then ->boolean($asserter->isSetByReference())->isFalse() ->if($asserter->setWith(uniqid())) ->then ->boolean($asserter->isSetByReference())->isFalse() ->if($value = uniqid()) ->and($asserter->setByReferenceWith($value)) ->then ->boolean($asserter->isSetByReference())->isTrue() ; } public function testIsEqualTo() { $this ->if($asserter = new asserters\variable($generator = new asserter\generator())) ->then ->boolean($asserter->wasSet())->isFalse() ->exception(function() use ($asserter) { $asserter->isEqualTo(rand(- PHP_INT_MAX, PHP_INT_MAX)); }) ->isInstanceOf('logicException') ->hasMessage('Value is undefined') ->if($asserter->setWith($value = uniqid())) ->then ->object($asserter->isEqualTo($value))->isIdenticalTo($asserter) ->if($diff = new diffs\variable()) ->then ->exception(function() use (& $line, $asserter, & $notEqualValue) { $line = __LINE__; $asserter->isEqualTo($notEqualValue = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not equal to %s'), $asserter, $asserter->getTypeOf($notEqualValue)) . PHP_EOL . $diff->setReference($notEqualValue)->setData($asserter->getValue())) ->if($asserter->setWith(1)) ->and($otherDiff = new diffs\variable()) ->then ->object($asserter->isEqualTo('1'))->isIdenticalTo($asserter) ->exception(function() use (& $otherLine, $asserter, & $otherNotEqualValue, & $otherFailMessage) { $otherLine = __LINE__; $asserter->isEqualTo($otherNotEqualValue = uniqid(), $otherFailMessage = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($otherFailMessage . PHP_EOL . $otherDiff->setReference($otherNotEqualValue)->setData($asserter->getValue())) ; } public function testIsNotEqualTo() { $this ->if($asserter = new asserters\variable($generator = new asserter\generator())) ->then ->boolean($asserter->wasSet())->isFalse() ->exception(function() use ($asserter) { $asserter->isNotEqualTo(rand(- PHP_INT_MAX, PHP_INT_MAX)); }) ->isInstanceOf('logicException') ->hasMessage('Value is undefined') ->if($asserter->setWith($value = uniqid())) ->then ->object($asserter->isNotEqualTo(uniqid()))->isIdenticalTo($asserter) ->exception(function() use ($asserter, $value) { $asserter->isNotEqualTo($value); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is equal to %s'), $asserter, $asserter->getTypeOf($value))) ->exception(function() use ($asserter, $value, & $failMessage) { $asserter->isNotEqualTo($value, $failMessage = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($failMessage) ; } public function testIsIdenticalTo() { $this ->if($asserter = new asserters\variable($generator = new asserter\generator())) ->then ->boolean($asserter->wasSet())->isFalse() ->exception(function() use ($asserter) { $asserter->isIdenticalTo(rand(- PHP_INT_MAX, PHP_INT_MAX)); }) ->isInstanceOf('logicException') ->hasMessage('Value is undefined') ->if($asserter->setWith($value = rand(- PHP_INT_MAX, PHP_INT_MAX))) ->then ->object($asserter->isIdenticalTo($value))->isIdenticalTo($asserter) ->if($diff = new diffs\variable()) ->then ->exception(function() use ($asserter, & $notIdenticalValue, $value) { $asserter->isIdenticalTo($notIdenticalValue = (string) $value); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not identical to %s'), $asserter, $asserter->getTypeOf($notIdenticalValue)) . PHP_EOL . $diff->setReference($notIdenticalValue)->setData($asserter->getValue())) ->exception(function() use ($asserter, $notIdenticalValue, & $failMessage) { $asserter->isIdenticalTo($notIdenticalValue, $failMessage = uniqid()); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage($failMessage . PHP_EOL . $diff->setReference($notIdenticalValue)->setData($asserter->getValue())) ; } public function testIsNotIdenticalTo() { $this ->if($asserter = new asserters\variable($generator = new asserter\generator())) ->then ->boolean($asserter->wasSet())->isFalse() ->exception(function() use ($asserter) { $asserter->isNotIdenticalTo(rand(- PHP_INT_MAX, PHP_INT_MAX)); }) ->isInstanceOf('logicException') ->hasMessage('Value is undefined') ->if($asserter->setWith($value = rand(- PHP_INT_MAX, PHP_INT_MAX))) ->then ->object($asserter->isNotIdenticalTo(uniqid()))->isIdenticalTo($asserter) ->exception(function() use ($asserter, & $notIdenticalValue, $value) { $asserter->isNotIdenticalTo($value); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is identical to %s'), $asserter, $asserter->getTypeOf($value))) ; } public function testIsNull() { $this ->if($asserter = new asserters\variable($generator = new asserter\generator())) ->then ->boolean($asserter->wasSet())->isFalse() ->exception(function() use ($asserter) { $asserter->isNull(rand(- PHP_INT_MAX, PHP_INT_MAX)); }) ->isInstanceOf('logicException') ->hasMessage('Value is undefined') ->if($asserter->setWith(null)) ->then ->object($asserter->isNull())->isIdenticalTo($asserter) ->if($asserter->setWith('')) ->then ->exception(function() use ($asserter) { $asserter->isNull(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not null'), $asserter)) ->if($asserter->setWith(uniqid())) ->then ->exception(function() use ($asserter) { $asserter->isNull(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not null'), $asserter)) ->if($asserter->setWith(0)) ->then ->exception(function() use ($asserter) { $asserter->isNull(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not null'), $asserter)) ->if($asserter->setWith(false)) ->then ->exception(function() use ($asserter) { $asserter->isNull(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not null'), $asserter)) ; } public function testIsNotNull() { $this ->if($asserter = new asserters\variable($generator = new asserter\generator())) ->then ->boolean($asserter->wasSet())->isFalse() ->exception(function() use ($asserter) { $asserter->isNotNull(rand(- PHP_INT_MAX, PHP_INT_MAX)); }) ->isInstanceOf('logicException') ->hasMessage('Value is undefined') ->if($asserter->setWith(uniqid())) ->then ->object($asserter->isNotNull())->isIdenticalTo($asserter) ->if($asserter->setWith(null)) ->then ->exception(function() use ($asserter) { $asserter->isNotNull(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is null'), $asserter)) ; } public function testIsReferenceTo() { $this ->if($asserter = new asserters\variable($generator = new asserter\generator())) ->and($value = uniqid()) ->then ->boolean($asserter->wasSet())->isFalse() ->exception(function() use ($asserter, $value) { $asserter->isReferenceTo($value); }) ->isInstanceOf('logicException') ->hasMessage('Value is undefined') ->if($asserter->setWith($value)) ->then ->boolean($asserter->isSetByReference())->isFalse() ->exception(function() use ($asserter, $value) { $asserter->isReferenceTo($value); }) ->isInstanceOf('logicException') ->hasMessage('Value is not set by reference') ->if($asserter->setByReferenceWith($value)) ->and($reference = & $value) ->then ->boolean($asserter->wasSet())->isTrue() ->boolean($asserter->isSetByReference())->isTrue() ->object($asserter->isReferenceTo($reference))->isIdenticalTo($asserter) ->if($notReference = uniqid()) ->then ->exception(function() use ($asserter, $notReference) { $asserter->isReferenceTo($notReference); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not a reference to %s'), $asserter, $asserter->getTypeOf($notReference))) ->if($value = new \exception()) ->and($reference = $value) ->and($asserter->setByReferenceWith($value)) ->then ->boolean($asserter->wasSet())->isTrue() ->boolean($asserter->isSetByReference())->isTrue() ->object($asserter->isReferenceTo($reference))->isIdenticalTo($asserter) ->if($notReference = new \exception()) ->then ->exception(function() use ($asserter, $notReference) { $asserter->isReferenceTo($notReference); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is not a reference to %s'), $asserter, $asserter->getTypeOf($notReference))) ; } public function testIsNotFalse() { $this ->if($asserter = new asserters\variable($generator = new asserter\generator())) ->then ->boolean($asserter->wasSet())->isFalse() ->exception(function() use ($asserter) { $asserter->isNotNull(rand(- PHP_INT_MAX, PHP_INT_MAX)); }) ->isInstanceOf('logicException') ->hasMessage('Value is undefined') ->if($asserter->setWith(uniqid())) ->then ->object($asserter->isNotFalse())->isIdenticalTo($asserter) ->if($asserter->setWith(false)) ->then ->exception(function() use ($asserter) { $asserter->isNotFalse(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is false'), $asserter)) ; } public function testIsNotTrue() { $this ->if($asserter = new asserters\variable($generator = new asserter\generator())) ->then ->boolean($asserter->wasSet())->isFalse() ->exception(function() use ($asserter) { $asserter->isNotNull(rand(- PHP_INT_MAX, PHP_INT_MAX)); }) ->isInstanceOf('logicException') ->hasMessage('Value is undefined') ->if($asserter->setWith(uniqid())) ->then ->object($asserter->isNotTrue())->isIdenticalTo($asserter) ->if($asserter->setWith(true)) ->then ->exception(function() use ($asserter) { $asserter->isNotTrue(); }) ->isInstanceOf('mageekguy\atoum\asserter\exception') ->hasMessage(sprintf($generator->getLocale()->_('%s is true'), $asserter)) ; } } assert ->variable($colorizer->getForeground())->isNull() ->variable($colorizer->getBackground())->isNull() ->object($colorizer->getCli())->isEqualTo(new atoum\cli()) ; $colorizer = new cli\colorizer($foreground = uniqid()); $this->assert ->string($colorizer->getForeground())->isEqualTo($foreground) ->variable($colorizer->getBackground())->isNull() ->object($colorizer->getCli())->isEqualTo(new atoum\cli()) ; $colorizer = new cli\colorizer($foreground = rand(1, PHP_INT_MAX)); $this->assert ->string($colorizer->getForeground())->isEqualTo($foreground) ->variable($colorizer->getBackground())->isNull() ->object($colorizer->getCli())->isEqualTo(new atoum\cli()) ; $colorizer = new cli\colorizer($foreground = uniqid(), $background = uniqid()); $this->assert ->string($colorizer->getForeground())->isEqualTo($foreground) ->string($colorizer->getBackground())->isEqualTo($background) ->object($colorizer->getCli())->isEqualTo(new atoum\cli()) ; $colorizer = new cli\colorizer($foreground = uniqid(), $background = rand(1, PHP_INT_MAX)); $this->assert ->string($colorizer->getForeground())->isEqualTo($foreground) ->string($colorizer->getBackground())->isEqualTo($background) ->object($colorizer->getCli())->isEqualTo(new atoum\cli()) ; $colorizer = new cli\colorizer($foreground = uniqid(), $background = rand(1, PHP_INT_MAX), $cli = new atoum\cli()); $this->assert ->string($colorizer->getForeground())->isEqualTo($foreground) ->string($colorizer->getBackground())->isEqualTo($background) ->object($colorizer->getCli())->isIdenticalTo($cli) ; } public function testSetCli() { $colorizer = new cli\colorizer(uniqid()); $this->assert ->object($colorizer->setCli($cli = new atoum\cli()))->isIdenticalTo($colorizer) ->object($colorizer->getCli())->isIdenticalTo($cli) ; } public function testSetForeground() { $colorizer = new cli\colorizer(uniqid()); $this->assert ->object($colorizer->setForeground($foreground = uniqid()))->isIdenticalTo($colorizer) ->string($colorizer->getForeground())->isEqualTo($foreground) ->object($colorizer->setForeground($foreground = rand(1, PHP_INT_MAX)))->isIdenticalTo($colorizer) ->string($colorizer->getForeground())->isEqualTo($foreground) ; } public function testSetBackground() { $colorizer = new cli\colorizer(uniqid()); $this->assert ->object($colorizer->setBackground($foreground = uniqid()))->isIdenticalTo($colorizer) ->string($colorizer->getBackground())->isEqualTo($foreground) ->object($colorizer->setBackground($foreground = rand(1, PHP_INT_MAX)))->isIdenticalTo($colorizer) ->string($colorizer->getBackground())->isEqualTo($foreground) ; } public function testColorize() { $colorizer = new cli\colorizer(null, null, $cli = new \mock\mageekguy\atoum\cli()); $cli->getMockController()->isTerminal = true; $this->assert ->string($colorizer->colorize($string = uniqid()))->isEqualTo($string) ; $colorizer = new cli\colorizer($foreground = uniqid(), null, $cli); $this->assert ->string($colorizer->colorize($string = uniqid()))->isEqualTo("\033[" . $foreground . 'm' . $string . "\033[0m") ; $colorizer = new cli\colorizer($foreground = uniqid(), $background = uniqid(), $cli); $this->assert ->string($colorizer->colorize($string = uniqid()))->isEqualTo("\033[" . $foreground . 'm' . "\033[" . $background . 'm' . $string . "\033[0m") ; $colorizer = new cli\colorizer(null, $background = uniqid(), $cli); $this->assert ->string($colorizer->colorize($string = uniqid()))->isEqualTo("\033[" . $background . 'm' . $string . "\033[0m") ; $colorizer = new cli\colorizer($foreground = uniqid(), $background = uniqid(), $cli); $cli->getMockController()->isTerminal = false; $this->assert ->string($colorizer->colorize($string = uniqid()))->isEqualTo($string) ; } } string(cli\progressBar::defaultProgressBarFormat)->isEqualTo('[%s]') ->string(cli\progressBar::defaultCounterFormat)->isEqualTo('[%s/%s]') ; } public function test__construct() { $this ->if($progressBar = new cli\progressBar(0)) ->then ->object($progressBar->getCli())->isEqualTo(new atoum\cli()) ->castToString($progressBar)->isEqualTo('[' . str_repeat('_', 60) . '][0/0]') ->castToString($progressBar)->isEmpty() ->if($progressBar = new cli\progressBar(1)) ->then ->castToString($progressBar)->isEqualTo('[.' . str_repeat('_', 59) . '][0/1]') ->castToString($progressBar)->isEmpty() ->if($progressBar = new cli\progressBar($count = rand(2, 9))) ->then ->castToString($progressBar)->isEqualTo('[' . str_repeat('.', $count) . str_repeat('_', 60 - $count) . '][0/' . $count . ']') ->castToString($progressBar)->isEmpty() ->if($progressBar = new cli\progressBar($count = rand(10, 60))) ->then ->castToString($progressBar)->isEqualTo('[' . str_repeat('.', $count) . str_repeat('_', 60 - $count) . '][ 0/' . $count . ']') ->castToString($progressBar)->isEmpty() ->if($progressBar = new cli\progressBar(61)) ->then ->castToString($progressBar)->isEqualTo('[' . str_repeat('.', 59) . '>][ 0/61]') ->castToString($progressBar)->isEmpty() ->if($progressBar = new cli\progressBar($count = rand(100, PHP_INT_MAX))) ->then ->castToString($progressBar)->isEqualTo('[' . str_repeat('.', 59) . '>][' . sprintf('%' . strlen((string) $count) . 'd', 0) . '/' . $count . ']') ->castToString($progressBar)->isEmpty() ; } public function testRefresh() { $this ->if($cli = new \mock\mageekguy\atoum\cli()) ->and($cli->getMockController()->isTerminal = true) ->and($progressBar = new cli\progressBar(0, $cli)) ->then ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar)->isEqualTo('[' . str_repeat('_', 60) . '][0/0]') ->castToString($progressBar)->isEmpty() ->if($progressBar = new cli\progressBar(1, $cli)) ->and($progressBarString = (string) $progressBar) ->and($progressBarLength = strlen($progressBarString)) ->then ->string($progressBarString)->isEqualTo('[.' . str_repeat('_', 59) . '][0/1]') ->castToString($progressBar)->isEmpty() ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo(str_repeat("\010", $progressBarLength - 1) . 'F' . str_repeat('_', 59) . '][1/1]') ->castToString($progressBar)->isEmpty() ->if($progressBar = new cli\progressBar(1, $cli)) ->then ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo('[.' . str_repeat('_', 59) . '][0/1]' . str_repeat("\010", $progressBarLength - 1) . 'F' . str_repeat('_', 59) . '][1/1]') ->castToString($progressBar)->isEmpty() ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar)->isEmpty() ->if($progressBar = new cli\progressBar(60, $cli)) ->and($progressBarString = (string) $progressBar) ->then ->string($progressBarString)->isEqualTo('[' . str_repeat('.', 60) . '][ 0/60]') ->castToString($progressBar)->isEmpty() ->if($nextProgressBarString = 'F' . str_repeat('.', 59) . '][ 1/60]') ->then ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo(str_repeat("\010", strlen($progressBarString) - 1) . $nextProgressBarString) ->castToString($progressBar)->isEmpty() ; for ($i = 2; $i <= 60; $i++) { $currentProgressBarString = $nextProgressBarString; $nextProgressBarString = 'F' . str_repeat('.', 60 - $i) . '][' . sprintf('%2d', $i) . '/60]'; $this ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo(str_repeat("\010", strlen($currentProgressBarString) - 1) . $nextProgressBarString) ->castToString($progressBar)->isEmpty() ; } $this ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar)->isEmpty() ; $this ->if($progressBar = new cli\progressBar(61, $cli)) ->and($progressBarString = (string) $progressBar) ->then ->string($progressBarString)->isEqualTo('[' . str_repeat('.', 59) . '>][ 0/61]') ->castToString($progressBar)->isEmpty() ->if($nextProgressBarString = 'F' . str_repeat('.', 58) . '>][ 1/61]') ->then ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo(str_repeat("\010", strlen($progressBarString) - 1) . $nextProgressBarString) ->castToString($progressBar)->isEmpty() ; for ($i = 2; $i <= 58; $i++) { $currentProgressBarString = $nextProgressBarString; $nextProgressBarString = 'F' . str_repeat('.', 59 - $i) . '>][' . sprintf('%2d', $i) . '/61]'; $this ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo(str_repeat("\010", strlen($currentProgressBarString) - 1) . $nextProgressBarString) ->castToString($progressBar)->isEmpty() ; } $this ->if($currentProgressBarString = $nextProgressBarString) ->and($nextProgressBarString = '[..' . str_repeat('_', 58) . ']') ->then ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo(str_repeat("\010", strlen($currentProgressBarString) - 1) . 'F>][59/61]' . PHP_EOL . $nextProgressBarString) ->castToString($progressBar)->isEmpty() ->if($currentProgressBarString = $nextProgressBarString) ->and($nextProgressBarString = 'F.' . str_repeat('_', 58) . '][60/61]') ->then ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo(str_repeat("\010", strlen($currentProgressBarString) - 1) . $nextProgressBarString) ->castToString($progressBar)->isEmpty() ->if($currentProgressBarString = $nextProgressBarString) ->and($nextProgressBarString = 'F' . str_repeat('_', 58) . '][61/61]') ->then ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo(str_repeat("\010", strlen($currentProgressBarString) - 1) . $nextProgressBarString) ->castToString($progressBar)->isEmpty() ->if($progressBar = new cli\progressBar(121, $cli)) ->and($progressBarString = (string) $progressBar) ->then ->string($progressBarString)->isEqualTo('[' . str_repeat('.', 59) . '>][ 0/121]') ->castToString($progressBar)->isEmpty() ->if($nextProgressBarString = 'F' . str_repeat('.', 58) . '>][ 1/121]') ->then ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo(str_repeat("\010", strlen($progressBarString) - 1) . $nextProgressBarString) ->castToString($progressBar)->isEmpty() ; for ($i = 2; $i <= 58; $i++) { $currentProgressBarString = $nextProgressBarString; $nextProgressBarString = 'F' . str_repeat('.', 59 - $i) . '>][' . sprintf('%3d', $i) . '/121]'; $this ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo(str_repeat("\010", strlen($currentProgressBarString) - 1) . $nextProgressBarString) ->castToString($progressBar)->isEmpty() ; } $this ->if($currentProgressBarString = $nextProgressBarString) ->and($nextProgressBarString = '[' . str_repeat('.', 59) . '>]') ->then ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo(str_repeat("\010", strlen($currentProgressBarString) - 1) . 'F>][ 59/121]' . PHP_EOL . $nextProgressBarString) ->castToString($progressBar)->isEmpty() ; for ($i = 60; $i <= 117; $i++) { $currentProgressBarString = $nextProgressBarString; $nextProgressBarString = 'F' . str_repeat('.', 118 - $i) . '>][' . sprintf('%3d', $i) . '/121]'; $this ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo(str_repeat("\010", strlen($currentProgressBarString) - 1) . $nextProgressBarString) ->castToString($progressBar)->isEmpty() ; } $this ->if($currentProgressBarString = $nextProgressBarString) ->and($nextProgressBarString = '[...' . str_repeat('_', 57) . ']') ->then ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo(str_repeat("\010", strlen($currentProgressBarString) - 1) . 'F>][118/121]' . PHP_EOL . $nextProgressBarString) ->castToString($progressBar)->isEmpty() ; for ($i = 119; $i <= 121; $i++) { $currentProgressBarString = $nextProgressBarString; $nextProgressBarString = 'F' . str_repeat('.', 121 - $i) . str_repeat('_', 57) . '][' . sprintf('%3d', $i) . '/121]'; $this ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo(str_repeat("\010", strlen($currentProgressBarString) - 1) . $nextProgressBarString) ->castToString($progressBar)->isEmpty() ; } $this ->if($cli->getMockController()->isTerminal = false) ->and($progressBar = new cli\progressBar(0, $cli)) ->then ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar)->isEqualTo('[' . str_repeat('_', 60) . '][0/0]') ->castToString($progressBar)->isEmpty() ->if($progressBar = new cli\progressBar(3, $cli)) ->and($progressBarString = (string) $progressBar) ->and($progressBarLength = strlen($progressBarString)) ->then ->string($progressBarString)->isEqualTo('[...' . str_repeat('_', 57) . '][0/3]') ->castToString($progressBar)->isEmpty() ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar)->isEqualTo(PHP_EOL . '[' . 'F..' . str_repeat('_', 57) . '][1/3]') ->castToString($progressBar)->isEmpty() ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar)->isEqualTo(PHP_EOL . '[' . 'FF.' . str_repeat('_', 57) . '][2/3]') ->castToString($progressBar)->isEmpty() ->object($progressBar->refresh('S'))->isIdenticalTo($progressBar) ->castToString($progressBar)->isEqualTo(PHP_EOL . '[' . 'FFS' . str_repeat('_', 57) . '][3/3]') ->castToString($progressBar)->isEmpty() ->if($cli->getMockController()->isTerminal = true) ->and($progressBar = new cli\progressBar(177, $cli)) ->and($progressBarString = (string) $progressBar) ->then ->string($progressBarString)->isEqualTo('[' . str_repeat('.', 59) . '>][ 0/177]') ->castToString($progressBar)->isEmpty() ->if($nextProgressBarString = 'F' . str_repeat('.', 58) . '>][ 1/177]') ->then ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo(str_repeat("\010", strlen($progressBarString) - 1) . $nextProgressBarString) ->castToString($progressBar)->isEmpty() ; for ($i = 2; $i <= 58; $i++) { $currentProgressBarString = $nextProgressBarString; $nextProgressBarString = 'F' . str_repeat('.', 59 - $i) . '>][' . sprintf('%3d', $i) . '/177]'; $this ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo(str_repeat("\010", strlen($currentProgressBarString) - 1) . $nextProgressBarString) ->castToString($progressBar)->isEmpty() ; } $this ->if($currentProgressBarString = $nextProgressBarString) ->and($nextProgressBarString = '[' . str_repeat('.', 59) . '>]') ->then ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo(str_repeat("\010", strlen($currentProgressBarString) - 1) . 'F>][ 59/177]' . PHP_EOL . $nextProgressBarString) ->castToString($progressBar)->isEmpty() ; for ($i = 60; $i <= 117; $i++) { $currentProgressBarString = $nextProgressBarString; $nextProgressBarString = 'F' . str_repeat('.', 118 - $i) . '>][' . sprintf('%3d', $i) . '/177]'; $this ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo(str_repeat("\010", strlen($currentProgressBarString) - 1) . $nextProgressBarString) ->castToString($progressBar)->isEmpty() ; } $this ->if($currentProgressBarString = $nextProgressBarString) ->and($nextProgressBarString = '[' . str_repeat('.', 59) . '_]') ->then ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo(str_repeat("\010", strlen($currentProgressBarString) - 1) . 'F>][118/177]' . PHP_EOL . $nextProgressBarString) ->castToString($progressBar)->isEmpty() ; for ($i = 119; $i <= 176; $i++) { $currentProgressBarString = $nextProgressBarString; $nextProgressBarString = 'F' . str_repeat('.', 177 - $i) . '_][' . sprintf('%3d', $i) . '/177]'; $this ->object($progressBar->refresh('F'))->isIdenticalTo($progressBar) ->castToString($progressBar, null, "\010")->isEqualTo(str_repeat("\010", strlen($currentProgressBarString) - 1) . $nextProgressBarString) ->castToString($progressBar)->isEmpty() ; } } } assert ->string($prompt->getValue())->isEmpty() ->object($prompt->getColorizer())->isInstanceOf('mageekguy\atoum\cli\colorizer') ->variable($prompt->getColorizer()->getForeground())->isNull() ->variable($prompt->getColorizer()->getBackground())->isNull() ; $prompt = new cli\prompt($value = uniqid()); $this->assert ->string($prompt->getValue())->isEqualTo($value) ->object($prompt->getColorizer())->isInstanceOf('mageekguy\atoum\cli\colorizer') ->variable($prompt->getColorizer()->getForeground())->isNull() ->variable($prompt->getColorizer()->getBackground())->isNull() ; $prompt = new cli\prompt($value = uniqid(), $colorizer = new cli\colorizer()); $this->assert ->string($prompt->getValue())->isEqualTo($value) ->object($prompt->getColorizer())->isIdenticalTo($colorizer) ; } public function testSetValue() { $prompt = new cli\prompt(); $this->assert ->object($prompt->setValue($value = uniqid()))->isIdenticalTo($prompt) ->string($prompt->getValue())->isEqualTo($value) ->object($prompt->setValue($value = rand(1, PHP_INT_MAX)))->isIdenticalTo($prompt) ->string($prompt->getValue())->isEqualTo($value) ; } public function testSetColorizer() { $prompt = new cli\prompt(); $this->assert ->object($prompt->setColorizer($colorizer = new cli\colorizer()))->isIdenticalTo($prompt) ->object($prompt->getColorizer())->isIdenticalTo($colorizer) ; } public function test__toString() { $prompt = new cli\prompt(); $colorizer = new cli\colorizer(uniqid(), uniqid()); $this->assert ->castToString($prompt)->isEmpty() ->castToString($prompt->setValue($value = uniqid()))->isEqualTo($value) ->castToString($prompt->setColorizer($colorizer))->isEqualTo($colorizer->colorize($value)) ; } } assert ->testedClass ->isSubclassOf('logicException') ->isSubclassOf('badMethodCallException') ->isSubclassOf('mageekguy\atoum\exception') ; } } assert ->testedClass ->isSubclassOf('logicException') ->isSubclassOf('invalidArgumentException') ->isSubclassOf('mageekguy\atoum\exception') ; } } assert ->object($unexpectedValueException) ->isInstanceOf('runtimeException') ->isInstanceOf('unexpectedValueException') ->isInstanceOf('mageekguy\atoum\exception') ; } } assert ->object($logicExcepion) ->isInstanceOf('logicException') ->isInstanceOf('mageekguy\atoum\exception') ; } } assert ->object($runtimeExcepion) ->isInstanceOf('runtimeException') ->isInstanceOf('mageekguy\atoum\exception') ; } } testedClass->extends('mageekguy\atoum\iterators\filters\recursives\dot'); } public function test__accept() { $this ->mockGenerator->shunt('__construct') ->if($iteratorController = new mock\controller()) ->and($iteratorController->__construct = function() {}) ->and($filter = new recursives\atoum\source(new \mock\recursiveDirectoryIterator(uniqid()))) ->and($iteratorController->current = new \splFileInfo(uniqid())) ->then ->boolean($filter->accept())->isTrue() ->if($iteratorController->current = new \splFileInfo('.' . uniqid())) ->then ->boolean($filter->accept())->isFalse() ->if($iteratorController->current = new \splFileInfo(uniqid() . DIRECTORY_SEPARATOR . '.' . uniqid())) ->then ->boolean($filter->accept())->isFalse() ->if($iteratorController->current = new \splFileInfo(uniqid() . DIRECTORY_SEPARATOR . 'GPATH')) ->then ->boolean($filter->accept())->isFalse() ->if($iteratorController->current = new \splFileInfo(uniqid() . DIRECTORY_SEPARATOR . 'GRTAGS')) ->then ->boolean($filter->accept())->isFalse() ->if($iteratorController->current = new \splFileInfo(uniqid() . DIRECTORY_SEPARATOR . 'GTAGS')) ->then ->boolean($filter->accept())->isFalse() ; } } if($filter = new testedClass(new \recursiveArrayIterator(array()))) ->then ->object($filter->addClosure($closure = function() {}))->isIdenticalTo($filter) ->array($filter->getClosures())->isEqualTo(array($closure)) ->object($filter->addClosure($otherClosure = function() {}))->isIdenticalTo($filter) ->array($filter->getClosures())->isEqualTo(array($closure, $otherClosure)) ; } public function testAccept() { $this ->if($array = array( 0, 1, 2, array( 3, array( 4, 5 ), 6 ), 7, 8, 9 ) ) ->and($iterator = new \recursiveIteratorIterator( new testedClass( new \recursiveArrayIterator($array), function($current, $key, \recursiveArrayIterator $innerIterator) { if (true === $innerIterator->hasChildren()) { return true; } return (0 === $current % 2); } ) ) ) ->then ->array(iterator_to_array($iterator, false)) ->hasSize(5) ->strictlyContainsValues(array(0, 2, 4, 6, 8)) ->strictlyNotContainsValues(array(1, 3, 5, 7, 9)); } } testedClass->extends('\recursiveFilterIterator'); } public function test__construct() { $this ->mockGenerator->shunt('__construct') ->if($filter = new recursives\dot($recursiveIterator = new \mock\recursiveDirectoryIterator(uniqid()))) ->then ->object($filter->getInnerIterator())->isIdenticalTo($recursiveIterator) ->and($filter = new recursives\dot(__DIR__)) ->then ->object($filter->getInnerIterator())->isEqualTo(new \recursiveDirectoryIterator(__DIR__ )) ->string($filter->getInnerIterator()->getPath())->isEqualTo(__DIR__) ->if($filter = new recursives\dot($path = uniqid(), function($path) use (& $innerIterator) { return ($innerIterator = new \mock\recursiveDirectoryIterator($path)); })) ->then ->object($filter->getInnerIterator())->isIdenticalTo($innerIterator) ->mock($filter->getInnerIterator())->call('__construct')->withArguments($path, null)->once() ; } public function test__accept() { $this ->mockGenerator->shunt('__construct') ->if($iteratorController = new mock\controller()) ->and($iteratorController->__construct = function() {}) ->and($filter = new recursives\dot(new \mock\recursiveDirectoryIterator(uniqid()))) ->and($iteratorController->current = new \splFileInfo(uniqid())) ->then ->boolean($filter->accept())->isTrue() ->if($iteratorController->current = new \splFileInfo('.' . uniqid())) ->then ->boolean($filter->accept())->isFalse() ->if($iteratorController->current = new \splFileInfo(uniqid() . DIRECTORY_SEPARATOR . '.' . uniqid())) ->then ->boolean($filter->accept())->isFalse() ; } } testedClass->extends('\recursiveFilterIterator'); } public function test__construct() { $this ->mockGenerator->shunt('__construct') ->if($filter = new recursives\extension($recursiveIterator = new \mock\recursiveDirectoryIterator(uniqid()), $acceptedExtensions = array('php'))) ->then ->object($filter->getInnerIterator())->isIdenticalTo($recursiveIterator) ->array($filter->getAcceptedExtensions())->isEqualTo($acceptedExtensions) ->if($filter = new recursives\extension(__DIR__, $acceptedExtensions)) ->then ->object($filter->getInnerIterator())->isEqualTo(new \recursiveDirectoryIterator(__DIR__ )) ->string($filter->getInnerIterator()->getPath())->isEqualTo(__DIR__) ->if($filter = new recursives\extension($path = uniqid(), $acceptedExtensions, function($path) use (& $innerIterator) { return ($innerIterator = new \mock\recursiveDirectoryIterator($path)); })) ->then ->object($filter->getInnerIterator())->isIdenticalTo($innerIterator) ->mock($filter->getInnerIterator())->call('__construct')->withArguments($path)->once() ->array($filter->getAcceptedExtensions())->isEqualTo($acceptedExtensions) ; } public function testAccept() { $this ->if($filter = new recursives\extension($innerIterator = new \mock\recursiveIterator(), array('php'))) ->and($innerIterator->getMockController()->current = uniqid() . '.php') ->then ->boolean($filter->accept())->isTrue() ->if($innerIterator->getMockController()->current = uniqid() . DIRECTORY_SEPARATOR . uniqid() . '.php') ->boolean($filter->accept())->isTrue() ->if($innerIterator->getMockController()->current = uniqid()) ->boolean($filter->accept())->isTrue() ->if($innerIterator->getMockController()->current = uniqid() . '.' . uniqid()) ->boolean($filter->accept())->isFalse() ; } } testedClass->hasInterface('outerIterator'); } public function test__construct() { $this ->if($sourceDirectory = stream::get()) ->and($sourceDirectory->dir_opendir = true) ->and($sourceDirectory->dir_closedir = true) ->and($sourceDirectory->dir_rewinddir = true) ->and($sourceDirectory->dir_readdir = false) ->and($iterator = new iterators\recursives\atoum\source($sourceDirectory)) ->then ->string($iterator->getSourceDirectory())->isEqualTo($sourceDirectory) ->variable($iterator->getPharDirectory())->isNull() ->object($iterator->getInnerIterator())->isInstanceOf('recursiveIteratorIterator') ->if($iterator = new iterators\recursives\atoum\source($sourceDirectory, $pharDirectory = uniqid())) ->then ->string($iterator->getSourceDirectory())->isEqualTo($sourceDirectory) ->string($iterator->getPharDirectory())->isEqualTo($pharDirectory) ->object($iterator->getInnerIterator())->isInstanceOf('recursiveIteratorIterator') ; } public function testCurrent() { $this ->if($sourceDirectory = stream::get()) ->and($sourceDirectory->opendir = true) ->and($sourceDirectory->rewinddir = true) ->and($sourceDirectory->readdir = false) ->and($sourceDirectory->closedir = true) ->and($file = stream::getSubStream($sourceDirectory)) ->and($iterator = new iterators\recursives\atoum\source($sourceDirectory)) ->then ->variable($iterator->current())->isNull() ->if($sourceDirectory->readdir[1] = $file->getBasename()) ->and($sourceDirectory->readdir[2] = false) ->and($iterator = new iterators\recursives\atoum\source($sourceDirectory)) ->then ->string($iterator->current())->isEqualTo($file) ->if($sourceDirectory->readdir[1] = '.file') ->and($iterator = new iterators\recursives\atoum\source($sourceDirectory)) ->then ->variable($iterator->current())->isNull() ; } public function testKey() { $this ->if($sourceDirectory = stream::get()) ->and($sourceDirectory->opendir = true) ->and($sourceDirectory->rewinddir = true) ->and($sourceDirectory->readdir = false) ->and($sourceDirectory->closedir = true) ->and($iterator = new iterators\recursives\atoum\source($sourceDirectory)) ->then ->integer($iterator->key())->isZero() ->if($file = stream::getSubStream($sourceDirectory)) ->and($sourceDirectory->readdir[1] = $file->getBasename()) ->and($sourceDirectory->readdir[2] = false) ->and($iterator = new iterators\recursives\atoum\source($sourceDirectory)) ->then ->string($iterator->key())->isEqualTo($file) ->if($sourceDirectory->readdir[1] = '.file') ->and($iterator = new iterators\recursives\atoum\source($sourceDirectory)) ->then ->integer($iterator->key())->isZero() ->if($iterator = new iterators\recursives\atoum\source($sourceDirectory, $pharDirectory = uniqid())) ->then ->string($iterator->key())->isEmpty() ->if($sourceDirectory->readdir[1] = $file->getBasename()) ->and($iterator = new iterators\recursives\atoum\source($sourceDirectory, $pharDirectory = uniqid())) ->then ->string($iterator->key())->isEqualTo($pharDirectory . DIRECTORY_SEPARATOR . $file->getBasename()) ->if($sourceDirectory->readdir[1] = '.file') ->and($iterator = new iterators\recursives\atoum\source($sourceDirectory, $pharDirectory = uniqid())) ->then ->string($iterator->key())->isEmpty() ; } } testedClass->implements('iteratorAggregate'); } public function test__construct() { $this ->if($iterator = new testedClass()) ->boolean($iterator->dotsAreAccepted())->isFalse() ->array($iterator->getAcceptedExtensions())->isEqualTo(array('php')) ->object($iteratorFactory = $iterator->getIteratorFactory())->isInstanceOf('closure') ->object($defaultIterator = $iteratorFactory(__DIR__))->isEqualTo(new \recursiveDirectoryIterator(__DIR__)) ->object($dotFilterFactory = $iterator->getDotFilterFactory())->isInstanceOf('closure') ->object($dotFilterFactory($defaultIterator))->isEqualTo(new filters\recursives\dot($defaultIterator)) ->object($extensionFilterIterator = $iterator->getExtensionFilterFactory())->isInstanceOf('closure') ->object($extensionFilterIterator($defaultIterator, $extensions = array('foo')))->isEqualTo(new filters\recursives\extension($defaultIterator, $extensions)) ->if($iterator = new testedClass($iteratorFactory = function() {}, $dotFilterFactory = function() {}, $extensionFilterFactory = function() {})) ->then ->boolean($iterator->dotsAreAccepted())->isFalse() ->array($iterator->getAcceptedExtensions())->isEqualTo(array('php')) ->object($iterator->getIteratorFactory())->isIdenticalTo($iteratorFactory) ->object($iterator->getDotFilterFactory())->isIdenticalTo($dotFilterFactory) ->object($iterator->getExtensionFilterFactory())->isIdenticalTo($extensionFilterFactory) ; } public function testSetIteratorFactory() { $this ->if($iterator = new testedClass()) ->then ->object($iterator->setIteratorFactory($factory = function() {}))->isIdenticalTo($iterator) ->object($iterator->getIteratorFactory())->isIdenticalTo($factory) ->object($iterator->setIteratorFactory())->isIdenticalTo($iterator) ->object($defaultFactory = $iterator->getIteratorFactory()) ->isInstanceOf('closure') ->isNotIdenticalTo($factory) ->object($defaultFactory(__DIR__))->isEqualTo(new \recursiveDirectoryIterator(__DIR__)) ; } public function testSetDotFilterFactory() { $this ->if($iterator = new testedClass()) ->then ->object($iterator->setDotFilterFactory($factory = function() {}))->isIdenticalTo($iterator) ->object($iterator->getDotFilterFactory())->isIdenticalTo($factory) ->object($iterator->setDotFilterFactory())->isIdenticalTo($iterator) ->object($defaultFactory = $iterator->getDotFilterFactory()) ->isInstanceOf('closure') ->isNotIdenticalTo($factory) ->object($defaultFactory($iterator = new \recursiveDirectoryIterator(__DIR__)))->isEqualTo(new filters\recursives\dot($iterator)) ; } public function testSetExtensionFilterFactory() { $this ->if($iterator = new testedClass()) ->then ->object($iterator->setExtensionFilterFactory($factory = function() {}))->isIdenticalTo($iterator) ->object($iterator->getExtensionFilterFactory())->isIdenticalTo($factory) ->object($iterator->setExtensionFilterFactory())->isIdenticalTo($iterator) ->object($defaultFactory = $iterator->getExtensionFilterFactory()) ->isInstanceOf('closure') ->isNotIdenticalTo($factory) ->object($defaultFactory($iterator = new \recursiveDirectoryIterator(__DIR__), $extensions = array('foo')))->isEqualTo(new filters\recursives\extension($iterator, $extensions)) ; } public function testAcceptExtensions() { $this ->if($iterator = new testedClass()) ->then ->object($iterator->acceptExtensions($extensions = array(uniqid())))->isIdenticalTo($iterator) ->array($iterator->getAcceptedExtensions())->isEqualTo($extensions) ->object($iterator->acceptExtensions($extensions = array('.' . ($extension = uniqid()))))->isIdenticalTo($iterator) ->array($iterator->getAcceptedExtensions())->isEqualTo(array($extension)) ; } public function testAcceptAllExtensions() { $this ->if($iterator = new testedClass()) ->then ->object($iterator->acceptAllExtensions())->isIdenticalTo($iterator) ->array($iterator->getAcceptedExtensions())->isEmpty() ; } public function testRefuseExtension() { $this ->if($iterator = new testedClass()) ->then ->object($iterator->refuseExtension('php'))->isIdenticalTo($iterator) ->array($iterator->getAcceptedExtensions())->isEmpty() ->if($iterator->acceptExtensions(array('php', 'txt', 'xml'))) ->then ->object($iterator->refuseExtension('txt'))->isIdenticalTo($iterator) ->array($iterator->getAcceptedExtensions())->isEqualTo(array('php', 'xml')) ; } public function testAcceptDots() { $this ->if($iterator = new testedClass()) ->then ->object($iterator->acceptDots())->isIdenticalTo($iterator) ->boolean($iterator->dotsAreAccepted())->isTrue() ; } public function testRefuseDots() { $this ->if($iterator = new testedClass()) ->then ->object($iterator->refuseDots())->isIdenticalTo($iterator) ->boolean($iterator->dotsAreAccepted())->isFalse() ; } public function testGetIterator() { $this ->mockGenerator ->shunt('__construct') ->generate('recursiveDirectoryIterator') ->if($iterator = new testedClass()) ->and($iterator->setIteratorFactory(function($path) use (& $recursiveDirectoryIterator) { return ($recursiveDirectoryIterator = new \mock\recursiveDirectoryIterator($path)); })) ->and($iterator->setDotFilterFactory(function($iterator) use (& $dotFilterIterator) { return ($dotFilterIterator = new filters\recursives\dot($iterator)); })) ->and($iterator->setExtensionFilterFactory(function($iterator, $extensions) use (& $extensionFilterIterator) { return ($extensionFilterIterator = new filters\recursives\extension($iterator, $extensions)); })) ->then ->object($filterIterator = $iterator->getIterator($path = uniqid()))->isIdenticalTo($extensionFilterIterator) ->object($filterIterator->getInnerIterator())->isIdenticalTo($dotFilterIterator) ->object($filterIterator->getInnerIterator()->getInnerIterator())->isIdenticalTo($recursiveDirectoryIterator) ->mock($filterIterator->getInnerIterator()->getInnerIterator()) ->call('__construct')->withArguments($path)->once() ->if($iterator->acceptDots()) ->then ->object($filterIterator = $iterator->getIterator($path = uniqid()))->isIdenticalTo($extensionFilterIterator) ->object($filterIterator->getInnerIterator())->isIdenticalTo($recursiveDirectoryIterator) ->mock($filterIterator->getInnerIterator()) ->call('__construct')->withArguments($path)->once() ->if($iterator->refuseDots()) ->and($iterator->acceptExtensions(array())) ->then ->object($filterIterator = $iterator->getIterator($path = uniqid()))->isIdenticalTo($dotFilterIterator) ->object($filterIterator->getInnerIterator())->isIdenticalTo($recursiveDirectoryIterator) ->mock($filterIterator->getInnerIterator()) ->call('__construct')->withArguments($path)->once() ->if($iterator->acceptDots()) ->and($iterator->acceptExtensions(array())) ->then ->object($filterIterator = $iterator->getIterator($path = uniqid()))->isIdenticalTo($recursiveDirectoryIterator) ->mock($filterIterator) ->call('__construct')->withArguments($path)->once() ; } } assert ->class($this->getTestedClassName()) ->isSubClassOf('mageekguy\atoum\mailer') ->string(mailers\mail::eol)->isEqualTo("\r\n") ; } public function test__construct() { $mail = new mailers\mail(); $this->assert ->variable($mail->getTo())->isNull() ->variable($mail->getFrom())->isNull() ->variable($mail->getSubject())->isNull() ->variable($mail->getReplyTo())->isNull() ->variable($mail->getXMailer())->isNull() ; $adapter = new atoum\test\adapter(); $mail = new mailers\mail($adapter); $this->assert ->object($mail->getAdapter())->isIdenticalTo($adapter) ; } public function testAddTo() { $mail = new mailers\mail(); $this->assert ->object($mail->addTo($to1 = uniqid()))->isIdenticalTo($mail) ->string($mail->getTo())->isEqualTo($to1) ->object($mail->addTo($to2 = uniqid()))->isIdenticalTo($mail) ->string($mail->getTo())->isEqualTo($to1 . ',' . $to2) ->object($mail->addTo($to3 = uniqid(), $realName3 = uniqid()))->isIdenticalTo($mail) ->string($mail->getTo())->isEqualTo($to1 . ',' . $to2 . ',' . $realName3 . ' <' . $to3 . '>') ; } public function testSetSubject() { $mail = new mailers\mail(); $this->assert ->object($mail->setSubject($subject = uniqid()))->isIdenticalTo($mail) ->string($mail->getSubject())->isEqualTo($subject) ; $this->assert ->object($mail->setSubject($subject = rand(1, PHP_INT_MAX)))->isIdenticalTo($mail) ->string($mail->getSubject())->isEqualTo((string) $subject) ; } public function testSetFrom() { $mail = new mailers\mail(); $this->assert ->object($mail->setFrom($from = uniqid()))->isIdenticalTo($mail) ->string($mail->getFrom())->isEqualTo($from) ; $this->assert ->object($mail->setFrom($from = rand(1, PHP_INT_MAX)))->isIdenticalTo($mail) ->string($mail->getFrom())->isEqualTo((string) $from) ; $this->assert ->object($mail->setFrom($from = uniqid(), $realName = uniqid()))->isIdenticalTo($mail) ->string($mail->getFrom())->isEqualTo($realName . ' <' . $from . '>') ; } public function testSetReplyTo() { $mail = new mailers\mail(); $this->assert ->object($mail->setReplyTo($replyTo = uniqid()))->isIdenticalTo($mail) ->string($mail->getReplyTo())->isEqualTo($replyTo) ; $this->assert ->object($mail->setReplyTo($replyTo = rand(1, PHP_INT_MAX)))->isIdenticalTo($mail) ->string($mail->getReplyTo())->isEqualTo((string) $replyTo) ; $this->assert ->object($mail->setReplyTo($replyTo = uniqid(), $realName = uniqid()))->isIdenticalTo($mail) ->string($mail->getReplyTo())->isEqualTo($realName . ' <' . $replyTo . '>') ; } public function testSetXMailer() { $mail = new mailers\mail(); $this->assert ->object($mail->setXMailer($mailer = uniqid()))->isIdenticalTo($mail) ->string($mail->getXMailer())->isEqualTo($mailer) ; $this->assert ->object($mail->setXMailer($mailer = rand(1, PHP_INT_MAX)))->isIdenticalTo($mail) ->string($mail->getXMailer())->isEqualTo((string) $mailer) ; } public function testSetContentType() { $mail = new mailers\mail(); $this->assert ->object($mail->setContentType($type = 'text/plain', $charset = 'utf-8'))->isIdenticalTo($mail) ->array($mail->getContentType())->isEqualTo(array($type, $charset)) ; } public function testSend() { $adapter = new atoum\test\adapter(); $adapter->mail = function() {}; $mail = new mailers\mail($adapter); $this->assert ->exception(function() use ($mail) { $mail->send(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\runtime') ->hasMessage('To is undefined') ; $mail->addTo($to = uniqid()); $this->assert ->exception(function() use ($mail) { $mail->send(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\runtime') ->hasMessage('Subject is undefined') ; $mail->setSubject($subject = uniqid()); $this->assert ->exception(function() use ($mail) { $mail->send(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\runtime') ->hasMessage('From is undefined') ; $mail->setFrom($from = uniqid()); $this->assert ->exception(function() use ($mail) { $mail->send(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\runtime') ->hasMessage('Reply to is undefined') ; $mail->setReplyTo($replyTo = uniqid()); $this->assert ->exception(function() use ($mail) { $mail->send(uniqid()); }) ->isInstanceOf('mageekguy\atoum\exceptions\runtime') ->hasMessage('X-mailer is undefined') ; $mail->setXMailer($mailer = uniqid()); $this->assert ->object($mail->send($message = uniqid()))->isIdenticalTo($mail) ->adapter($adapter)->call('mail')->withArguments($mail->getTo(), $mail->getSubject(), $message, 'From: ' . $from . "\r\n" . 'Reply-To: ' . $replyTo . "\r\n" . 'X-Mailer: ' . $mailer)->once(); ; $mail->setContentType($type = uniqid(), $charset = uniqid()); $this->assert ->object($mail->send($message = uniqid()))->isIdenticalTo($mail) ->adapter($adapter)->call('mail')->withArguments($mail->getTo(), $mail->getSubject(), $message, 'From: ' . $from . "\r\n" . 'Reply-To: ' . $replyTo . "\r\n" . 'X-Mailer: ' . $mailer . "\r\n" . 'Content-Type: ' . $type . '; charset="' . $charset . '"')->once(); ; } } object(testedClass::add($mock = new \mock\foo(), $controller = new \mock\mageekguy\atoum\mock\controller()))->isIdenticalTo($controller) ->object(testedClass::get($mock)) ->isIdenticalTo($controller) ->isIdenticalTo($mock->getMockController()) ->mock($controller)->call('control')->withArguments($mock)->once() ; } public function testGet() { $this ->if($mock = new \mock\foo()) ->then ->object(testedClass::get($mock))->isIdenticalTo($mock->getMockController()) ->if($otherMock = new \mock\foo()) ->then ->object(testedClass::get($mock))->isIdenticalTo($mock->getMockController()) ->object(testedClass::get($otherMock))->isIdenticalTo($otherMock->getMockController()) ; } public function testRemove() { $this ->if(testedClass::add($mock = new \mock\foo(), $controller = new \mock\mageekguy\atoum\mock\controller())) ->and(testedClass::remove($mock)) ->then ->variable(testedClass::get($mock))->isNull() ->mock($controller)->call('reset')->once() ->if(testedClass::add($mock, $controller = new \mock\mageekguy\atoum\mock\controller())) ->and(testedClass::add($otherMock = new \mock\foo(), $otherController = new controller())) ->and(testedClass::remove($mock)) ->then ->variable(testedClass::get($mock))->isNull() ->mock($controller)->call('reset')->once() ->object(testedClass::get($otherMock))->isIdenticalTo($otherController) ; } public function testClean() { $this ->if($mock = new \mock\foo()) ->and(testedClass::clean()) ->then ->variable(testedClass::get($mock))->isNull() ->if(testedClass::add($mock = new \mock\foo(), new controller())) ->and(testedClass::add($otherMock = new \mock\foo(), new controller())) ->and(testedClass::clean()) ->then ->variable(testedClass::get($mock))->isNull() ->variable(testedClass::get($otherMock))->isNull() ; } } testedClass->implements('iteratorAggregate'); } public function test__construct() { $this ->if($iterator = new testedClass()) ->then ->variable($iterator->getMockController())->isNull() ->array($iterator->getMethods())->isEmpty() ->array($iterator->getFilters())->isEmpty() ->if($iterator = new testedClass($controller = new mock\controller())) ->then ->object($iterator->getMockController())->isIdenticalTo($controller) ->array($iterator->getMethods())->isEmpty() ->array($iterator->getFilters())->isEmpty() ; } public function test__set() { $this ->if($iterator = new testedClass($controller = new mock\controller())) ->and($controller->control($mock = new \mock\mageekguy\atoum\tests\units\mock\controller\foo())) ->and($iterator->return = $return = uniqid()) ->then ->boolean(isset($controller->__construct))->isFalse() ->string($controller->doSomething->invoke())->isEqualTo($return) ->string($controller->doSomethingElse->invoke())->isEqualTo($return) ->if($iterator->addFilter(function($name) { return (strtolower($name) == 'dosomething'); })) ->and($iterator->return = $otherReturn = uniqid()) ->then ->boolean(isset($controller->__construct))->isFalse() ->string($controller->doSomething->invoke())->isEqualTo($otherReturn) ->string($controller->doSomethingElse->invoke())->isEqualTo($return) ->if($iterator->resetFilters()) ->and($iterator->return = $otherReturn) ->then ->boolean(isset($controller->__construct))->isFalse() ->string($controller->doSomething->invoke())->isEqualTo($otherReturn) ->string($controller->doSomethingElse->invoke())->isEqualTo($otherReturn) ->if($iterator->return = $mock) ->then ->boolean(isset($controller->__construct))->isFalse() ->object($controller->doSomething->invoke())->isIdenticalTo($mock) ->object($controller->doSomethingElse->invoke())->isIdenticalTo($mock) ->if($iterator->throw = $exception = new \exception()) ->then ->exception(function() use ($controller) { $controller->doSomething->invoke(); })->isIdenticalTo($exception) ->exception(function() use ($controller) { $controller->doSomethingElse->invoke(); })->isIdenticalTo($exception) ->exception(function() use ($iterator) { $iterator->{uniqid()} = uniqid(); }) ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument') ; } public function testSetMockController() { $this ->if($iterator = new testedClass()) ->then ->object($iterator->setMockController($controller = new mock\controller()))->isIdenticalTo($iterator) ->object($iterator->getMockController())->isIdenticalTo($controller) ->object($iterator->setMockController($otherController = new mock\controller()))->isIdenticalTo($iterator) ->object($iterator->getMockController())->isIdenticalTo($otherController) ; } public function testResetFilters() { $this ->if($iterator = new testedClass($controller = new mock\controller())) ->then ->object($iterator->resetFilters())->isIdenticalTo($iterator) ->array($iterator->getFilters())->isEmpty() ->if($iterator->addFilter(function() {})) ->then ->object($iterator->resetFilters())->isIdenticalTo($iterator) ->array($iterator->getFilters())->isEmpty() ; } public function testAddFilter() { $this ->if($iterator = new testedClass($controller = new mock\controller())) ->then ->object($iterator->addFilter($filter = function() {}))->isIdenticalTo($iterator) ->array($iterator->getFilters())->isIdenticalTo(array($filter)) ->object($iterator->addFilter($otherFilter = function() {}))->isIdenticalTo($iterator) ->array($iterator->getFilters())->isIdenticalTo(array($filter, $otherFilter)) ; } public function testGetMethods() { $this ->if($iterator = new testedClass($controller = new mock\controller())) ->then ->array($iterator->getMethods())->isEmpty() ->if($controller->control($mock = new \mock\mageekguy\atoum\tests\units\mock\controller\foo())) ->then ->array($iterator->getMethods())->isEqualTo(array('dosomething', 'dosomethingelse')) ->if($iterator->addFilter(function($method) { return true; })) ->then ->array($iterator->getMethods())->isEqualTo(array('dosomething', 'dosomethingelse')) ->if($iterator->addFilter(function($method) { return false; })) ->then ->array($iterator->getMethods())->isEmpty() ->if($iterator->resetFilters()->addFilter(function($name) { return (strtolower($name) == 'dosomething'); })) ->then ->array($iterator->getMethods())->isEqualTo(array('dosomething')) ; } public function testGetIterator() { $this ->if($iterator = new testedClass($controller = new mock\controller())) ->then ->object($iterator->getIterator())->isEqualTo(new \arrayIterator($iterator->getMethods())) ->if($controller->control(new \mock\mageekguy\atoum\tests\units\mock\controller\foo())) ->then ->object($iterator->getIterator())->isEqualTo(new \arrayIterator($iterator->getMethods())) ; } } assert ->string($argument->getName())->isEqualTo($name) ; } public function testSetDefaultValue() { $argument = new php\method\argument(uniqid()); $this->assert ->object($argument->setDefaultValue($default = uniqid()))->isIdenticalTo($argument) ; } public function testIsReference() { $argument = new php\method\argument(uniqid()); $this->assert ->object($argument->isReference())->isIdenticalTo($argument) ; } public function test__toString() { $argument = new php\method\argument($name = uniqid()); $this->assert ->castToString($argument)->isEqualTo('$' . $name) ->castToString($argument->isArray())->isEqualTo('array $' . $name) ->castToString($argument->isObject($type = uniqid()))->isEqualTo($type . ' $' . $name) ->castToString($argument->isUntyped()->setDefaultValue(__FUNCTION__))->isEqualTo('$' . $name . '=' . var_export(__FUNCTION__, true)) ->castToString($argument->setDefaultValue($defaultValue = uniqid()))->isEqualTo('$' . $name . '=' . var_export($defaultValue, true)) ->castToString($argument->setDefaultValue(array()))->isEqualTo('$' . $name . '=' . var_export(array(), true)) ->castToString($argument->setDefaultValue(null))->isEqualTo('$' . $name . '=' . var_export(null, true)) ; $argument = new php\method\argument($name = uniqid()); $argument->isReference(); $this->assert ->castToString($argument)->isEqualTo('& $' . $name) ->castToString($argument->setDefaultValue(__FUNCTION__))->isEqualTo('& $' . $name . '=' . var_export(__FUNCTION__, true)) ->castToString($argument->setDefaultValue($defaultValue = uniqid()))->isEqualTo('& $' . $name . '=' . var_export($defaultValue, true)) ->castToString($argument->setDefaultValue(array()))->isEqualTo('& $' . $name . '=' . var_export(array(), true)) ->castToString($argument->setDefaultValue(null))->isEqualTo('& $' . $name . '=' . var_export(null, true)) ; } } assert ->string($method->getName())->isEqualTo($name) ; } public function testReturnReference() { $method = new php\method(uniqid()); $this->assert ->object($method->returnReference())->isIdenticalTo($method) ; $method = new php\method('__construct'); $this->assert ->exception(function() use ($method) { $method->returnReference(); } ) ->isInstanceOf('mageekguy\atoum\exceptions\logic') ->hasMessage('Constructor can not return a reference') ; } public function testIsConstructor() { $method = new php\method(uniqid()); $this->assert ->boolean($method->isConstructor())->isFalse() ; $method = new php\method('__construct'); $this->assert ->boolean($method->isConstructor())->isTrue() ; } public function testAddArgument() { $method = new php\method(uniqid()); $this->assert ->object($method->addArgument(new php\method\argument(uniqid())))->isIdenticalTo($method) ; } public function test__toString() { $method = new php\method($name = uniqid()); $this->assert ->castToString($method)->isEqualTo('public function ' . $name . '()') ->castToString($method->returnReference())->isEqualTo('public function & ' . $name . '()') ->castToString($method->addArgument($argument1 = new php\method\argument(uniqid())))->isEqualTo('public function & ' . $name . '(' . $argument1 . ')') ->castToString($method->addArgument($argument2 = new php\method\argument(uniqid())))->isEqualTo('public function & ' . $name . '(' . $argument1 . ', ' . $argument2 . ')') ; } public function testGetArgumentsAsString() { $method = new php\method($name = uniqid()); $this->assert ->string($method->getArgumentsAsString())->isEmpty() ->string($method->addArgument($argument1 = new php\method\argument(uniqid()))->getArgumentsAsString())->isEqualTo((string) $argument1) ->string($method->addArgument($argument2 = new php\method\argument(uniqid()))->getArgumentsAsString())->isEqualTo($argument1 . ', ' . $argument2) ->string($method->addArgument($argument3 = new php\method\argument(uniqid()))->getArgumentsAsString())->isEqualTo($argument1 . ', ' . $argument2 . ', ' . $argument3) ; } } assert ->testedClass->isSubclassOf('mageekguy\atoum\test\adapter') ; } public function test__construct() { $this ->if($streamController = new testedClass($stream = uniqid())) ->then ->string($streamController->getPath())->isEqualTo($stream) ->variable($streamController->invoke('__construct'))->isNull() ->variable($streamController->invoke('dir_closedir'))->isNull() ->variable($streamController->invoke('dir_opendir'))->isNull() ->variable($streamController->invoke('dir_readdir'))->isNull() ->variable($streamController->invoke('dir_rewinddir'))->isNull() ->variable($streamController->invoke('mkdir'))->isNull() ->variable($streamController->invoke('rename'))->isNull() ->variable($streamController->invoke('rmdir'))->isNull() ->variable($streamController->invoke('stream_cast'))->isNull() ->variable($streamController->invoke('stream_close'))->isNull() ->variable($streamController->invoke('stream_eof'))->isNull() ->variable($streamController->invoke('stream_flush'))->isNull() ->variable($streamController->invoke('stream_lock'))->isNull() ->variable($streamController->invoke('stream_metadata'))->isNull() ->variable($streamController->invoke('stream_open'))->isNull() ->variable($streamController->invoke('stream_read'))->isNull() ->variable($streamController->invoke('stream_seek'))->isNull() ->variable($streamController->invoke('stream_set_option'))->isNull() ->variable($streamController->invoke('stream_stat'))->isNull() ->variable($streamController->invoke('stream_tell'))->isNull() ->variable($streamController->invoke('stream_write'))->isNull() ->variable($streamController->invoke('unlink'))->isNull() ->variable($streamController->invoke('url_stat'))->isNull() ; } public function test__toString() { $this ->if($streamController = new testedClass($stream = uniqid())) ->then ->castToString($streamController)->isEqualTo($stream) ; } public function test__get() { $this ->if($streamController = new testedClass(uniqid())) ->then ->object($streamController->__construct)->isEqualTo(new stream\invoker('__construct')) ->object($streamController->dir_closedir)->isEqualTo(new stream\invoker('dir_closedir')) ->object($streamController->closedir)->isEqualTo(new stream\invoker('dir_closedir')) ->object($streamController->dir_opendir)->isEqualTo(new stream\invoker('dir_opendir')) ->object($streamController->opendir)->isEqualTo(new stream\invoker('dir_opendir')) ->object($streamController->dir_readdir)->isEqualTo(new stream\invoker('dir_readdir')) ->object($streamController->readdir)->isEqualTo(new stream\invoker('dir_readdir')) ->object($streamController->dir_rewinddir)->isEqualTo(new stream\invoker('dir_rewinddir')) ->object($streamController->rewinddir)->isEqualTo(new stream\invoker('dir_rewinddir')) ->object($streamController->mkdir)->isEqualTo(new stream\invoker('mkdir')) ->object($streamController->rename)->isEqualTo(new stream\invoker('rename')) ->object($streamController->rmdir)->isEqualTo(new stream\invoker('rmdir')) ->object($streamController->stream_cast)->isEqualTo(new stream\invoker('stream_cast')) ->object($streamController->select)->isEqualTo(new stream\invoker('stream_cast')) ->object($streamController->stream_close)->isEqualTo(new stream\invoker('stream_close')) ->object($streamController->fclose)->isEqualTo(new stream\invoker('stream_close')) ->object($streamController->stream_eof)->isEqualTo(new stream\invoker('stream_eof')) ->object($streamController->feof)->isEqualTo(new stream\invoker('stream_eof')) ->object($streamController->stream_flush)->isEqualTo(new stream\invoker('stream_flush')) ->object($streamController->fflush)->isEqualTo(new stream\invoker('stream_flush')) ->object($streamController->stream_lock)->isEqualTo(new stream\invoker('stream_lock')) ->object($streamController->flock)->isEqualTo(new stream\invoker('stream_lock')) ->object($streamController->stream_metadata)->isEqualTo(new stream\invoker('stream_metadata')) ->object($streamController->touch)->isEqualTo(new stream\invoker('stream_metadata')) ->object($streamController->chmod)->isEqualTo(new stream\invoker('stream_metadata')) ->object($streamController->chown)->isEqualTo(new stream\invoker('stream_metadata')) ->object($streamController->chgrp)->isEqualTo(new stream\invoker('stream_metadata')) ->object($streamController->stream_open)->isEqualTo(new stream\invoker('stream_open')) ->object($streamController->fopen)->isEqualTo(new stream\invoker('stream_open')) ->object($streamController->stream_read)->isEqualTo(new stream\invoker('stream_read')) ->object($streamController->fread)->isEqualTo(new stream\invoker('stream_read')) ->object($streamController->stream_seek)->isEqualTo(new stream\invoker('stream_seek')) ->object($streamController->fseek)->isEqualTo(new stream\invoker('stream_seek')) ->object($streamController->stream_set_option)->isEqualTo(new stream\invoker('stream_set_option')) ->object($streamController->stream_stat)->isEqualTo(new stream\invoker('stream_stat')) ->object($streamController->fstat)->isEqualTo(new stream\invoker('stream_stat')) ->object($streamController->stream_tell)->isEqualTo(new stream\invoker('stream_tell')) ->object($streamController->ftell)->isEqualTo(new stream\invoker('stream_tell')) ->object($streamController->stream_write)->isEqualTo(new stream\invoker('stream_write')) ->object($streamController->fwrite)->isEqualTo(new stream\invoker('stream_write')) ->object($streamController->unlink)->isEqualTo(new stream\invoker('unlink')) ->object($streamController->url_stat)->isEqualTo(new stream\invoker('url_stat')) ->object($streamController->stat)->isEqualTo(new stream\invoker('url_stat')) ->if($method = uniqid()) ->then ->exception(function() use ($streamController, $method) { $streamController->{$method}; } ) ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument') ->hasMessage('Method streamWrapper::' . $method . '() does not exist') ; } public function test__set() { $this ->if($streamController = new testedClass(uniqid())) ->and($streamController->__construct = $__construct = uniqid()) ->then ->string($streamController->invoke('__construct'))->isEqualTo($__construct) ->if($streamController->dir_closedir = $dir_closedir = uniqid()) ->then ->string($streamController->invoke('dir_closedir'))->isEqualTo($dir_closedir) ->if($streamController->closedir = $closedir = uniqid()) ->then ->string($streamController->invoke('closedir'))->isEqualTo($closedir) ->if($streamController->dir_opendir = $dir_opendir = uniqid()) ->then ->string($streamController->invoke('dir_opendir'))->isEqualTo($dir_opendir) ->if($streamController->opendir = $opendir = uniqid()) ->then ->string($streamController->invoke('opendir'))->isEqualTo($opendir) ->if($streamController->dir_readdir = $dir_readdir = uniqid()) ->then ->string($streamController->invoke('dir_readdir'))->isEqualTo($dir_readdir) ->if($streamController->readdir = $readdir = uniqid()) ->then ->string($streamController->invoke('readdir'))->isEqualTo($readdir) ->if($streamController->dir_rewinddir = $dir_rewinddir = uniqid()) ->then ->string($streamController->invoke('dir_rewinddir'))->isEqualTo($dir_rewinddir) ->if($streamController->rewinddir = $rewinddir = uniqid()) ->then ->string($streamController->invoke('rewinddir'))->isEqualTo($rewinddir) ->if($streamController->mkdir = $mkdir = uniqid()) ->then ->string($streamController->invoke('mkdir'))->isEqualTo($mkdir) ->if($streamController->rename = $rename = uniqid()) ->then ->string($streamController->invoke('rename'))->isEqualTo($rename) ->if($streamController->rmdir = $rmdir = uniqid()) ->then ->string($streamController->invoke('rmdir'))->isEqualTo($rmdir) ->if($streamController->stream_cast = $stream_cast = uniqid()) ->then ->string($streamController->invoke('stream_cast'))->isEqualTo($stream_cast) ->if($streamController->select = $select = uniqid()) ->then ->string($streamController->invoke('select'))->isEqualTo($select) ->if($streamController->stream_close = $stream_close = uniqid()) ->then ->string($streamController->invoke('stream_close'))->isEqualTo($stream_close) ->if($streamController->fclose = $fclose = uniqid()) ->then ->string($streamController->invoke('fclose'))->isEqualTo($fclose) ->if($streamController->stream_eof = $stream_eof = uniqid()) ->then ->string($streamController->invoke('stream_eof'))->isEqualTo($stream_eof) ->if($streamController->feof = $feof = uniqid()) ->then ->string($streamController->invoke('feof'))->isEqualTo($feof) ->if($streamController->stream_flush = $stream_flush = uniqid()) ->then ->string($streamController->invoke('stream_flush'))->isEqualTo($stream_flush) ->if($streamController->fflush = $fflush = uniqid()) ->then ->string($streamController->invoke('fflush'))->isEqualTo($fflush) ->if($streamController->stream_lock = $stream_lock = uniqid()) ->then ->string($streamController->invoke('stream_lock'))->isEqualTo($stream_lock) ->if($streamController->flock = $flock = uniqid()) ->then ->string($streamController->invoke('flock'))->isEqualTo($flock) ->if($streamController->stream_metadata = $stream_metadata = uniqid()) ->then ->string($streamController->invoke('stream_metadata'))->isEqualTo($stream_metadata) ->if($streamController->touch = $touch = uniqid()) ->then ->string($streamController->invoke('touch'))->isEqualTo($touch) ->if($streamController->chmod = $chmod = uniqid()) ->then ->string($streamController->invoke('chmod'))->isEqualTo($chmod) ->if($streamController->chown = $chown = uniqid()) ->then ->string($streamController->invoke('chown'))->isEqualTo($chown) ->if($streamController->chgrp = $chgrp = uniqid()) ->then ->string($streamController->invoke('chgrp'))->isEqualTo($chgrp) ->if($streamController->stream_open = $stream_open = uniqid()) ->then ->string($streamController->invoke('stream_open'))->isEqualTo($stream_open) ->if($streamController->fopen = $fopen = uniqid()) ->then ->string($streamController->invoke('fopen'))->isEqualTo($fopen) ->if($streamController->stream_read = $stream_read = uniqid()) ->then ->string($streamController->invoke('stream_read'))->isEqualTo($stream_read) ->if($streamController->fread = $fread = uniqid()) ->then ->string($streamController->invoke('fread'))->isEqualTo($fread) ->if($streamController->stream_seek = $stream_seek = uniqid()) ->then ->string($streamController->invoke('stream_seek'))->isEqualTo($stream_seek) ->if($streamController->fseek = $fseek = uniqid()) ->then ->string($streamController->invoke('fseek'))->isEqualTo($fseek) ->if($streamController->stream_set_option = $stream_set_option = uniqid()) ->then ->string($streamController->invoke('stream_set_option'))->isEqualTo($stream_set_option) ->if($streamController->stream_stat = $stream_stat = uniqid()) ->then ->string($streamController->invoke('stream_stat'))->isEqualTo($stream_stat) ->if($streamController->fstat = $fstat = uniqid()) ->then ->string($streamController->invoke('fstat'))->isEqualTo($fstat) ->if($streamController->stream_tell = $stream_tell = uniqid()) ->then ->string($streamController->invoke('stream_tell'))->isEqualTo($stream_tell) ->if($streamController->ftell = $ftell = uniqid()) ->then ->string($streamController->invoke('ftell'))->isEqualTo($ftell) ->if($streamController->stream_write = $stream_write = uniqid()) ->then ->string($streamController->invoke('stream_write'))->isEqualTo($stream_write) ->if($streamController->fwrite = $fwrite = uniqid()) ->then ->string($streamController->invoke('fwrite'))->isEqualTo($fwrite) ->if($streamController->unlink = $unlink = uniqid()) ->then ->string($streamController->invoke('unlink'))->isEqualTo($unlink) ->if($streamController->url_stat = $url_stat = uniqid()) ->then ->string($streamController->invoke('url_stat'))->isEqualTo($url_stat) ->if($streamController->stat = $stat = uniqid()) ->then ->string($streamController->invoke('stat'))->isEqualTo($stat) ->if($streamController->resetCalls()->file_get_contents = $contents = uniqid()) ->then ->boolean($streamController->invoke('fopen'))->isTrue() ->string($streamController->invoke('fread'))->isEqualTo($contents) ->boolean($streamController->invoke('fread'))->isFalse() ->boolean($streamController->invoke('fclose'))->isTrue() ->if($streamController->resetCalls()->file_put_contents = true) ->then ->boolean($streamController->invoke('fopen'))->isTrue() ->boolean($streamController->invoke('fwrite'))->isTrue() ->boolean($streamController->invoke('fclose'))->isTrue() ->if($streamController->resetCalls()->file_put_contents = false) ->then ->boolean($streamController->invoke('fopen'))->isTrue() ->boolean($streamController->invoke('fwrite'))->isFalse() ->boolean($streamController->invoke('fclose'))->isTrue() ->if($method = uniqid()) ->then ->exception(function() use ($streamController, $method) { $streamController->{$method} = uniqid(); } ) ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument') ->hasMessage('Method streamWrapper::' . $method . '() does not exist') ; } public function test__isset() { $this ->if($streamController = new testedClass(uniqid())) ->then ->boolean(isset($streamController->__construct))->isFalse() ->boolean(isset($streamController->dir_closedir))->isFalse() ->boolean(isset($streamController->closedir))->isFalse() ->boolean(isset($streamController->dir_opendir))->isFalse() ->boolean(isset($streamController->opendir))->isFalse() ->boolean(isset($streamController->dir_readdir))->isFalse() ->boolean(isset($streamController->readdir))->isFalse() ->boolean(isset($streamController->dir_rewinddir))->isFalse() ->boolean(isset($streamController->rewinddir))->isFalse() ->boolean(isset($streamController->mkdir))->isFalse() ->boolean(isset($streamController->rename))->isFalse() ->boolean(isset($streamController->rmdir))->isFalse() ->boolean(isset($streamController->stream_cast))->isFalse() ->boolean(isset($streamController->select))->isFalse() ->boolean(isset($streamController->stream_close))->isFalse() ->boolean(isset($streamController->fclose))->isFalse() ->boolean(isset($streamController->stream_eof))->isFalse() ->boolean(isset($streamController->feof))->isFalse() ->boolean(isset($streamController->stream_flush))->isFalse() ->boolean(isset($streamController->fflush))->isFalse() ->boolean(isset($streamController->stream_lock))->isFalse() ->boolean(isset($streamController->flock))->isFalse() ->boolean(isset($streamController->stream_metadata))->isFalse() ->boolean(isset($streamController->touch))->isFalse() ->boolean(isset($streamController->chmod))->isFalse() ->boolean(isset($streamController->chown))->isFalse() ->boolean(isset($streamController->chgrp))->isFalse() ->boolean(isset($streamController->stream_open))->isFalse() ->boolean(isset($streamController->fopen))->isFalse() ->boolean(isset($streamController->stream_read))->isFalse() ->boolean(isset($streamController->fread))->isFalse() ->boolean(isset($streamController->stream_seek))->isFalse() ->boolean(isset($streamController->fseek))->isFalse() ->boolean(isset($streamController->stream_set_option))->isFalse() ->boolean(isset($streamController->stream_stat))->isFalse() ->boolean(isset($streamController->fstat))->isFalse() ->boolean(isset($streamController->stream_tell))->isFalse() ->boolean(isset($streamController->ftell))->isFalse() ->boolean(isset($streamController->stream_write))->isFalse() ->boolean(isset($streamController->fwrite))->isFalse() ->boolean(isset($streamController->unlink))->isFalse() ->boolean(isset($streamController->url_stat))->isFalse() ->boolean(isset($streamController->stat))->isFalse() ->if($streamController->__construct = uniqid()) ->and($streamController->dir_closedir = uniqid()) ->and($streamController->closedir = uniqid()) ->and($streamController->dir_opendir = uniqid()) ->and($streamController->opendir = uniqid()) ->and($streamController->dir_readdir = uniqid()) ->and($streamController->readdir = uniqid()) ->and($streamController->dir_rewinddir = uniqid()) ->and($streamController->rewinddir = uniqid()) ->and($streamController->mkdir = uniqid()) ->and($streamController->rename = uniqid()) ->and($streamController->rmdir = uniqid()) ->and($streamController->stream_cast = uniqid()) ->and($streamController->select = uniqid()) ->and($streamController->stream_close = uniqid()) ->and($streamController->fclose = uniqid()) ->and($streamController->stream_eof = uniqid()) ->and($streamController->feof = uniqid()) ->and($streamController->stream_flush = uniqid()) ->and($streamController->fflush = uniqid()) ->and($streamController->stream_lock = uniqid()) ->and($streamController->flock = uniqid()) ->and($streamController->stream_metadata = uniqid()) ->and($streamController->touch = uniqid()) ->and($streamController->chown = uniqid()) ->and($streamController->chmod = uniqid()) ->and($streamController->chgrp = uniqid()) ->and($streamController->stream_open = uniqid()) ->and($streamController->fopen = uniqid()) ->and($streamController->stream_read = uniqid()) ->and($streamController->fread = uniqid()) ->and($streamController->stream_seek = uniqid()) ->and($streamController->fseek = uniqid()) ->and($streamController->stream_set_option = uniqid()) ->and($streamController->stream_stat = uniqid()) ->and($streamController->fstat = uniqid()) ->and($streamController->stream_tell = uniqid()) ->and($streamController->ftell = uniqid()) ->and($streamController->stream_write = uniqid()) ->and($streamController->fwrite = uniqid()) ->and($streamController->unlink = uniqid()) ->and($streamController->url_stat = uniqid()) ->and($streamController->stat = uniqid()) ->then ->boolean(isset($streamController->__construct))->isTrue() ->boolean(isset($streamController->dir_closedir))->isTrue() ->boolean(isset($streamController->closedir))->isTrue() ->boolean(isset($streamController->dir_opendir))->isTrue() ->boolean(isset($streamController->opendir))->isTrue() ->boolean(isset($streamController->dir_readdir))->isTrue() ->boolean(isset($streamController->readdir))->isTrue() ->boolean(isset($streamController->dir_rewinddir))->isTrue() ->boolean(isset($streamController->rewinddir))->isTrue() ->boolean(isset($streamController->mkdir))->isTrue() ->boolean(isset($streamController->rename))->isTrue() ->boolean(isset($streamController->rmdir))->isTrue() ->boolean(isset($streamController->stream_cast))->isTrue() ->boolean(isset($streamController->select))->isTrue() ->boolean(isset($streamController->stream_close))->isTrue() ->boolean(isset($streamController->fclose))->isTrue() ->boolean(isset($streamController->stream_eof))->isTrue() ->boolean(isset($streamController->feof))->isTrue() ->boolean(isset($streamController->stream_flush))->isTrue() ->boolean(isset($streamController->fflush))->isTrue() ->boolean(isset($streamController->stream_lock))->isTrue() ->boolean(isset($streamController->flock))->isTrue() ->boolean(isset($streamController->stream_metadata))->isTrue() ->boolean(isset($streamController->touch))->isTrue() ->boolean(isset($streamController->chmod))->isTrue() ->boolean(isset($streamController->chown))->isTrue() ->boolean(isset($streamController->chgrp))->isTrue() ->boolean(isset($streamController->stream_open))->isTrue() ->boolean(isset($streamController->fopen))->isTrue() ->boolean(isset($streamController->stream_read))->isTrue() ->boolean(isset($streamController->fread))->isTrue() ->boolean(isset($streamController->stream_seek))->isTrue() ->boolean(isset($streamController->fseek))->isTrue() ->boolean(isset($streamController->stream_set_option))->isTrue() ->boolean(isset($streamController->stream_stat))->isTrue() ->boolean(isset($streamController->fstat))->isTrue() ->boolean(isset($streamController->stream_tell))->isTrue() ->boolean(isset($streamController->ftell))->isTrue() ->boolean(isset($streamController->stream_write))->isTrue() ->boolean(isset($streamController->fwrite))->isTrue() ->boolean(isset($streamController->unlink))->isTrue() ->boolean(isset($streamController->url_stat))->isTrue() ->boolean(isset($streamController->stat))->isTrue() ->if($method = uniqid()) ->then ->exception(function() use ($streamController, $method) { isset($streamController->{$method}); } ) ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument') ->hasMessage('Method streamWrapper::' . $method . '() does not exist') ; } public function test__unset() { $this ->if($streamController = new testedClass(uniqid())) ->then ->boolean(isset($streamController->__construct))->isFalse() ->when(function() use ($streamController) { unset($streamController->__construct); }) ->boolean(isset($streamController->__construct))->isFalse() ->boolean(isset($streamController->dir_closedir))->isFalse() ->when(function() use ($streamController) { unset($streamController->dir_closedir); }) ->boolean(isset($streamController->dir_closedir))->isFalse() ->boolean(isset($streamController->closedir))->isFalse() ->when(function() use ($streamController) { unset($streamController->closedir); }) ->boolean(isset($streamController->closedir))->isFalse() ->boolean(isset($streamController->dir_opendir))->isFalse() ->when(function() use ($streamController) { unset($streamController->dir_opendir); }) ->boolean(isset($streamController->dir_opendir))->isFalse() ->boolean(isset($streamController->opendir))->isFalse() ->when(function() use ($streamController) { unset($streamController->opendir); }) ->boolean(isset($streamController->opendir))->isFalse() ->boolean(isset($streamController->dir_readdir))->isFalse() ->when(function() use ($streamController) { unset($streamController->dir_readdir); }) ->boolean(isset($streamController->dir_readdir))->isFalse() ->boolean(isset($streamController->readdir))->isFalse() ->when(function() use ($streamController) { unset($streamController->readdir); }) ->boolean(isset($streamController->readdir))->isFalse() ->boolean(isset($streamController->dir_rewinddir))->isFalse() ->when(function() use ($streamController) { unset($streamController->dir_rewinddir); }) ->boolean(isset($streamController->dir_rewinddir))->isFalse() ->boolean(isset($streamController->rewinddir))->isFalse() ->when(function() use ($streamController) { unset($streamController->rewinddir); }) ->boolean(isset($streamController->rewinddir))->isFalse() ->boolean(isset($streamController->mkdir))->isFalse() ->when(function() use ($streamController) { unset($streamController->mkdir); }) ->boolean(isset($streamController->mkdir))->isFalse() ->boolean(isset($streamController->rename))->isFalse() ->when(function() use ($streamController) { unset($streamController->rename); }) ->boolean(isset($streamController->rename))->isFalse() ->boolean(isset($streamController->rmdir))->isFalse() ->when(function() use ($streamController) { unset($streamController->rmdir); }) ->boolean(isset($streamController->rmdir))->isFalse() ->boolean(isset($streamController->stream_cast))->isFalse() ->when(function() use ($streamController) { unset($streamController->stream_cast); }) ->boolean(isset($streamController->stream_cast))->isFalse() ->boolean(isset($streamController->select))->isFalse() ->when(function() use ($streamController) { unset($streamController->select); }) ->boolean(isset($streamController->select))->isFalse() ->boolean(isset($streamController->stream_close))->isFalse() ->when(function() use ($streamController) { unset($streamController->stream_close); }) ->boolean(isset($streamController->stream_close))->isFalse() ->boolean(isset($streamController->fclose))->isFalse() ->when(function() use ($streamController) { unset($streamController->fclose); }) ->boolean(isset($streamController->fclose))->isFalse() ->boolean(isset($streamController->stream_eof))->isFalse() ->when(function() use ($streamController) { unset($streamController->stream_eof); }) ->boolean(isset($streamController->stream_eof))->isFalse() ->boolean(isset($streamController->feof))->isFalse() ->when(function() use ($streamController) { unset($streamController->feof); }) ->boolean(isset($streamController->feof))->isFalse() ->boolean(isset($streamController->stream_flush))->isFalse() ->when(function() use ($streamController) { unset($streamController->stream_flush); }) ->boolean(isset($streamController->stream_flush))->isFalse() ->boolean(isset($streamController->fflush))->isFalse() ->when(function() use ($streamController) { unset($streamController->fflush); }) ->boolean(isset($streamController->fflush))->isFalse() ->boolean(isset($streamController->stream_lock))->isFalse() ->when(function() use ($streamController) { unset($streamController->stream_lock); }) ->boolean(isset($streamController->stream_lock))->isFalse() ->boolean(isset($streamController->flock))->isFalse() ->when(function() use ($streamController) { unset($streamController->flock); }) ->boolean(isset($streamController->flock))->isFalse() ->boolean(isset($streamController->stream_metadata))->isFalse() ->when(function() use ($streamController) { unset($streamController->stream_metadata); }) ->boolean(isset($streamController->stream_metadata))->isFalse() ->boolean(isset($streamController->touch))->isFalse() ->when(function() use ($streamController) { unset($streamController->touch); }) ->boolean(isset($streamController->touch))->isFalse() ->boolean(isset($streamController->chmod))->isFalse() ->when(function() use ($streamController) { unset($streamController->chmod); }) ->boolean(isset($streamController->chmod))->isFalse() ->boolean(isset($streamController->chown))->isFalse() ->when(function() use ($streamController) { unset($streamController->chown); }) ->boolean(isset($streamController->chown))->isFalse() ->boolean(isset($streamController->chgrp))->isFalse() ->when(function() use ($streamController) { unset($streamController->chgrp); }) ->boolean(isset($streamController->chgrp))->isFalse() ->boolean(isset($streamController->stream_open))->isFalse() ->when(function() use ($streamController) { unset($streamController->stream_open); }) ->boolean(isset($streamController->stream_open))->isFalse() ->boolean(isset($streamController->fopen))->isFalse() ->when(function() use ($streamController) { unset($streamController->fopen); }) ->boolean(isset($streamController->fopen))->isFalse() ->boolean(isset($streamController->stream_read))->isFalse() ->when(function() use ($streamController) { unset($streamController->stream_read); }) ->boolean(isset($streamController->stream_read))->isFalse() ->boolean(isset($streamController->fread))->isFalse() ->when(function() use ($streamController) { unset($streamController->fread); }) ->boolean(isset($streamController->fread))->isFalse() ->boolean(isset($streamController->stream_seek))->isFalse() ->when(function() use ($streamController) { unset($streamController->stream_seek); }) ->boolean(isset($streamController->stream_seek))->isFalse() ->boolean(isset($streamController->fseek))->isFalse() ->when(function() use ($streamController) { unset($streamController->fseek); }) ->boolean(isset($streamController->fseek))->isFalse() ->boolean(isset($streamController->stream_set_option))->isFalse() ->when(function() use ($streamController) { unset($streamController->stream_set_option); }) ->boolean(isset($streamController->stream_set_option))->isFalse() ->boolean(isset($streamController->stream_stat))->isFalse() ->when(function() use ($streamController) { unset($streamController->stream_stat); }) ->boolean(isset($streamController->stream_stat))->isFalse() ->boolean(isset($streamController->fstat))->isFalse() ->when(function() use ($streamController) { unset($streamController->fstat); }) ->boolean(isset($streamController->fstat))->isFalse() ->boolean(isset($streamController->stream_tell))->isFalse() ->when(function() use ($streamController) { unset($streamController->stream_tell); }) ->boolean(isset($streamController->stream_tell))->isFalse() ->boolean(isset($streamController->ftell))->isFalse() ->when(function() use ($streamController) { unset($streamController->ftell); }) ->boolean(isset($streamController->ftell))->isFalse() ->boolean(isset($streamController->stream_write))->isFalse() ->when(function() use ($streamController) { unset($streamController->stream_write); }) ->boolean(isset($streamController->stream_write))->isFalse() ->boolean(isset($streamController->fwrite))->isFalse() ->when(function() use ($streamController) { unset($streamController->fwrite); }) ->boolean(isset($streamController->fwrite))->isFalse() ->boolean(isset($streamController->unlink))->isFalse() ->when(function() use ($streamController) { unset($streamController->unlink); }) ->boolean(isset($streamController->unlink))->isFalse() ->boolean(isset($streamController->url_stat))->isFalse() ->when(function() use ($streamController) { unset($streamController->url_stat); }) ->boolean(isset($streamController->url_stat))->isFalse() ->boolean(isset($streamController->stat))->isFalse() ->when(function() use ($streamController) { unset($streamController->stat); }) ->boolean(isset($streamController->stat))->isFalse() ->if($streamController->__construct = uniqid()) ->and($streamController->dir_closedir = uniqid()) ->and($streamController->clo