3åã§ã§ãã俺PHPãã¹ãç°å¢
â»ãã®è¨äºã¯VOYAGE GROUP エンジニアブログ : Advent Calendar 2012ã®15æ¥ç®ã®è¨äºã¨ãã¦æ¸ãã¦ã¾ãã
3種ã®ç¥å¨ PHPUnit, Stagehand_TestRunner, Phake
åãã¦ã®æ¹ã¯ããã¾ãã¦ããã¤ãã®æ¹ããã«ã¡ã¯ã
VOYAGE GROUP ã® adingo ã¨ããä¼ç¤¾ã§ åºåé
ä¿¡ã«é¢ãã Webã¢ããªã±ã¼ã·ã§ã³éçºã¨ã³ã¸ãã¢ããã¦ãã @brtriver ã§ãã
ä»æ¥ã¯å®éã®ç¾å ´ã§ã使ã£ã¦ããPHPã®éçºç°å¢æ§ç¯Tipsã¨ãããã¨ã§ ã¿ããªå¤§å¥½ã PHPUnit ã èªåã¯å¤§å¥½ã Phake ãæ¯åãã¹ããæåã§å®è¡ããã®ã許ãããã®ã¯å°å¦çã¾ã§ã ããã¼ Stagehand_TestRunner ã® 3ã¤ã3åã§ããã¸ã§ã¯ããã¨ã«ã¤ã³ã¹ãã¼ã«ããæ¹æ³ãæ¸ãã¦ã¿ã¾ãã
ä½ãèãã composer.jsonãã³ããã§ç¨æ
ããã¸ã§ã¯ãã®ã«ã¼ããã£ã¬ã¯ããªã prj ã¨ãã¾ãããã
ãã㫠以ä¸ã®å
容㮠composer.json ãã¡ã¤ã«ãç¨æãã¾ãã
{ "require": { "phake/phake": "v1.0.3", "piece/stagehand-testrunner": "v3.5.0" }, "require-dev": { "phpunit/phpunit": "3.7.*" } }
ããã§ããcomposerã使ã£ã¦ã©ã¤ãã©ãªãããã¸ã§ã¯ãå ã«ã¤ã³ã¹ãã¼ã«ãã¾ãã
composer.phar ãç¨æãã
ãã¨ã¯ã以ä¸ã®ã³ãã³ããé»ã£ã¦å©ãã¦ææ°ã®composer.pharããã¦ã³ãã¼ããã¦ãã
$ curl -s https://getcomposer.org/installer | php
ãããcurlããªããã°ä»¥ä¸ã§ãOk
$ php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"
ãã£ã¤ ã¤ã³ã¹ãã¼ã«
ãã composerã使ã£ã¦ã¤ã³ã¹ãã¼ã«ãã¾ããã
$ php composer.phar install --dev
composerã®ã¤ã³ã¹ãã¼ã«ã¯ããã±ã¼ã¸ã®ç¢ºèªãªã©ã«æéãçµæ§ãããã¾ãã
ãè¶ã§ãããã£ã¦ãå¾
ã¡ãã ããã
ããã§ãvendorãã£ã¬ã¯ããªãä½æããã³ã¼ããé ç½®ããã¾ãã
PHPUnit ãå®è¡ãã¦ã¿ã
testsãã£ã¬ã¯ããªãä½æãã¦ãã¹ãã³ã¼ããæ¸ãã¦ã¿ã¾ãããã
- tests/SampleTest.php
<?php Class SampleTest extends PHPUnit_Framework_TestCase { /** * @test */ public function ãã¹ããå®è¡ã§ãããã¨() { $this->assertTrue(true); } }
ããã phpunitã§åããã¦ã¿ã¾ã
$ ./vendor/bin/phpunit --tap tests TAP version 13 ok 1 - SampleTest::ãã¹ããå®è¡ã§ããã㨠1..1
ç°¡åã§ãããã¡ãªã¿ã«èª¬æã¯ç«¯æã£ã¦ã¾ããphakeã使ãã¾ãã
Stagehand_TestRunner ã使ã£ã¦ã¿ã
æå¾ã«Stagehand_TestRunner ã®ç¨æã§ãã
ä½ãèããã«ä»¥ä¸ã®ãã¾ããªãã³ãã³ããå©ãã°æºåOk
$ ./vendor/bin/testrunner compile -p vendor/autoload.php
ãã¨ã¯ãtestrunnerãèµ·åãã¦ããã¾ãã
$ ./vendor/bin/testrunner phpunit -p vendor/autoload.php -a tests PHPUnit 3.7.10 by Sebastian Bergmann. . Sample [x] ãã¹ããå®è¡ã§ããã㨠Time: 0 seconds, Memory: 5.25Mb OK (1 test, 1 assertion)
ãã®ç¶æ
ã§SampleTest.phpã®ãã¹ãã assetTrue(false) ã«æ¸ãæãã¦ã¿ã¾ãããã
ããã¨æ¬¡ã®ããã«ãã¡ã¤ã«ã®æ´æ°ããã£ãããèªåçã«ãã¹ããå®è¡ããã¾ãã
PHPUnit 3.7.10 by Sebastian Bergmann. F Sample [ ] ãã¹ããå®è¡ã§ããã㨠Time: 0 seconds, Memory: 5.50Mb There was 1 failure: 1) SampleTest::ãã¹ããå®è¡ã§ããã㨠Failed asserting that false is true. /tmp/prj/tests/SampleTest.php:9 /tmp/prj/vendor/piece/stagehand-testrunner/src/Stagehand/TestRunner/Runner/PHPUnitRunner.php:81 /tmp/prj/vendor/piece/stagehand-testrunner/src/Stagehand/TestRunner/Process/TestRun.php:103 /tmp/prj/vendor/piece/stagehand-testrunner/src/Stagehand/TestRunner/CLI/TestRunner.php:69 /tmp/prj/vendor/piece/stagehand-testrunner/src/Stagehand/TestRunner/CLI/TestRunnerApplication/Command/PluginCommand.php:145 /tmp/prj/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:238 /tmp/prj/vendor/symfony/console/Symfony/Component/Console/Application.php:192 /tmp/prj/vendor/symfony/console/Symfony/Component/Console/Application.php:105 FAILURES! Tests: 1, Assertions: 1, Failures: 1.
ãªãã¨ç´ æµãªãã¨ã§ãããï¼
ã¾ã¨ã
ãã£ã3åã§ãPHPã§ç¶ç¶çã«ãã¹ããæ¸ãã¦éçºãã俺ç°å¢ãã§ãã¦ãã¾ãã¾ããã
ç°¡åã¨ããã¨ããããã½ã§ãå®ããã¸ã§ã¯ãã§ã ä»åã®ç°å¢+α ã make install ã§èªåæ§ç¯ã§ããããã«ãã¦ãã¾ãã
ææ¥ã® Advent Calendar 㯠ãã¤ãç¬é¡ãç´ æµãª @bash0C7 ã§ããã楽ãã¿ã«ï¼