PHP Advent Calendar 2013 in Adventar ã®ï¼æ¥ç®ã§ãã
åæ¥ã¯ @matsubo ããã® ã³ããã§åºæ¥ãComposerå°å ¥ ã§ãããComposerãç§ã使ã£ã¦ã¾ãã
Grunt ã¨ã¯ Node.js ã§ä½ãããè²ã ãªä½æ¥ãèªååããããã®ãã¼ã«ã§ãã æ®é㯠Node.js ã§ã®éçºã js ã¨ãã®ããã³ãã¨ã³ãéçºã«ä½¿ããã¾ãããPHP ã§ã®éçºã§ãããã¨ä¾¿å©ã§ãã
PHP ã®ããã® Grunt ãã©ã°ã¤ã³ãè²ã ããã®ã§ãã¨ããããæ¬¡ã®ï¼ã¤ã ã使ã£ã¦ã¿ã¾ãã
åæ
php ã node ã npm ã¯ãããããã¤ã³ã¹ãã¼ã«ãã¦ããã¦ãã ããã
ã½ã¼ã¹ã¨ãã¹ãã®æºå
ã¨ãããã phpunit ãå®è¡ã§ããã½ã¼ã¹ããªã¼ãç¨æãã¾ããphpunit ã¯ä»é¢¨ã« composer ã§ã¤ã³ã¹ãã¼ã«ãã¾ãã
$ find . -type f ./src/Sample.php ./tests/phpunit.xml.dist ./tests/bootstrap.php ./tests/SampleTest.php ./composer.json
composer.json
{ "autoload": { "psr-0": { "": "src/" } }, "require-dev": { "phpunit/phpunit": "3.7.*" } }
Sample.php
<?php class Sample { public function add($a, $b) { // @todo æªå®è£ } }
bootstrap.php
<?php require __DIR__ . '/../vendor/autoload.php'; require_once 'PHPUnit/Framework/Assert/Functions.php';
<?xml version="1.0" encoding="utf-8" ?> <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.github.com/sebastianbergmann/phpunit/master/phpunit.xsd" bootstrap="./bootstrap.php" > <testsuites> <testsuite name="tests"> <directory>./</directory> </testsuite> </testsuites> </phpunit>
SampleTest.php
<?php class SampleTest extends PHPUnit_Framework_TestCase { function test() { $sample = new Sample(); assertEquals(3, $sample->add(1, 2)); } }
composer ã§ phpunit ãã¤ã³ã¹ãã¼ã«ãã¾ãã
$ composer install --dev Loading composer repositories with package information Installing dependencies (including require-dev) : Writing lock file Generating autoload files
phpunit ãå®è¡ãã¾ããSample::add() ã®ä¸èº«ãæªå®è£ ãªã®ã§ãã¹ãã¯ã³ã±ã¾ãã
$ vendor/bin/phpunit -c tests/ --colors PHPUnit 3.7.28 by Sebastian Bergmann. Configuration read from /home/ore/work/example/php-grunt/tests/phpunit.xml.dist F Time: 29 ms, Memory: 3.25Mb There was 1 failure: 1) SampleTest::test Failed asserting that null matches expected 3. /home/ore/work/example/php-grunt/tests/SampleTest.php:7 FAILURES! Tests: 1, Assertions: 1, Failures: 1.
grunt ã®æºå
PHP ã®ã½ã¼ã¹ã¨ãã¹ãã®æºåã¯ã§ããã®ã§ grunt ãæºåãã¦ããã¾ãã
grunt-cli
ã¾ã㯠npm ã§ grunt-cli ãã°ãã¼ãã«ã«ã¤ã³ã¹ãã¼ã«ãã¾ãã
çç±ã¯ç¥ãã¾ããã grunt-cli ã¯ã°ãã¼ãã«ã«ã¤ã³ã¹ãã¼ã«ããå¿
è¦ãããã¾ãã
ï¼æå
ã§è©¦ããæã -g ããªããã¦ããã¸ã§ã¯ããã¼ã«ã«ã«ã¤ã³ã¹ãã¼ã«ãã¦ã大ä¸å¤«ã£ã½ãã£ãã§ããã»ã»ã»ããå¤ãã¾ããï¼
$ npm install -g grunt-cli
package.json
ç¶ã㦠package.json ã使ãã¾ãã
$ echo '{}' > package.json
package.json 㯠PHP ã§è¨ãã¨ããã® composer.json ã§ãã
ããã«ããã±ã¼ã¸ãæ¸ãã¦ããã° npm install ã ãã§å¿
è¦ãªããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«ãããã¨ãã§ãã¾ãã
æ¬æ¥ãªã npm init ã§ä½æããã®ã§ãããPHP ã®éçºã®ããã«ã¡ãã£ã¨ä½¿ãã ããªãããã§ãååã§ãããã¶ãã
grunt/grunt-phpunit
次㫠grunt 㨠grunt-phpunit ãã¤ã³ã¹ãã¼ã«ãã¾ãã
å
ã»ã©ã® grunt-cli ã¨ç°ãªã -g ãä»ãã¦ããªãã®ã§ãã«ã¬ã³ããã£ã¬ã¯ããªã® node_modules ã«ã¤ã³ã¹ãã¼ã«ããã¾ãã
$ npm install --save-dev grunt $ npm install --save-dev grunt-phpunit
ãã㯠PHP ã§è¨ãã¨ããã® composer require --dev ore/are ã§ãã
ããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«ãã¤ã¤ package.json ã«ããã±ã¼ã¸åã追è¨ãã¾ãã
ãã ãpackage.json ãèªåã§ä½æããããã¯ããªãã®ã§ãåã®æé ã§ç©ºã®ãã¡ã¤ã«ãä½ã£ã¦ãã¾ãã
Gruntfile.js
Gruntfile.js ã使ãã¾ãããã®ãã¡ã¤ã«ã«ã¯å®è¡ããã¿ã¹ã¯ã®å 容ãè¨è¿°ãã¾ãã
Gruntfile.js
module.exports = function (grunt) { grunt.initConfig({ phpunit: { options: { bin: 'vendor/bin/phpunit', // phpunit ã® bin ã®ãã¹ configuration: 'tests/', // --configuration=tests/ colors: true, // --colors followOutput: true // phpunit ã®åºåã®é½åº¦ã³ã³ã½ã¼ã«ã«è¡¨ç¤ºãã }, test: {} // ãã¹ã対象ã®ãã£ã¬ã¯ã㪠} }); grunt.loadNpmTasks('grunt-phpunit'); };
ãã®ä¾ã§ã¯æ¬¡ã®éãã«è¨å®ãã¦ãã¾ãã
- phpunit ã®ãã¹ã¯ vendor/bin/phpunit
- ãªãã·ã§ã³ã¯
--configuration=tests/ --colors - phpunit ããåºåã®é½åº¦ã³ã³ã½ã¼ã«ã«è¡¨ç¤ºããï¼
followOutput: trueï¼- followOutput ã false ã ã¨ãã¹ã¦ã®ãã¹ããçµäºãã¦ããçµæã表示ããã¾ã
- ãã¹ãã®é²æãããããªããªãã®ã§ followOutput 㯠true ã«ãã¦ãããæ¹ãè¯ãã§ããã
grunt ã§ phpunit ãå®è¡
次ã®ããã« grunt ã§ phpunit ãå®è¡ã§ãã¾ãã
$ grunt phpunit Running "phpunit:test" (phpunit) task Starting phpunit (target: test) in PHPUnit 3.7.28 by Sebastian Bergmann. Configuration read from /home/ore/work/example/php-grunt/tests/phpunit.xml.dist F Time: 26 ms, Memory: 3.25Mb There was 1 failure: 1) SampleTest::test Failed asserting that null matches expected 3. /home/ore/work/example/php-grunt/tests/SampleTest.php:7 FAILURES! Tests: 1, Assertions: 1, Failures: 1. Fatal error: Command failed:
ã§ããããã ããªãæ®éã« phpunit ãããã°ããã§ããã»ã»ã»
ãªããtest: {} ã®é¨åã¯æ®éã¯æ¬¡ã®ããã«ãã¹ã対象ã®ãã£ã¬ã¯ããªãæå®ãã¾ãã
test: { dir: "tests/" }
ãããã®ä¾ã§ã¯ phpunit.xml.dist ã§ãã¹ã対象ãæå®ãã¦ããã®ã§ç©ºã§æ§ãã¾ããã
ã¾ããtest ã®é¨åã¯ã¿ã¹ã¯ã®ã¿ã¼ã²ããåã«ãªã£ã¦ãã¦ãgrunt phpunit:test ã®ããã«æå®ãããã¨ãåºæ¥ã¾ãã
ãªã®ã§ã次ã®ããã«ãã¹ããè¤æ°ã«åå²ãã¦å®ç¾©ãããã¨ãåºæ¥ã¾ãã
Gruntfile.js
module.exports = function (grunt) { grunt.initConfig({ phpunit: { options: { bin: 'vendor/bin/phpunit', configuration: 'tests/', colors: true, followOutput: true }, unit: { dir: "tests/unit" }, functional: { dir: "tests/functional" } } }); grunt.loadNpmTasks('grunt-phpunit'); };
$ grunt phpunit:unit # ã¦ããããã¹ã $ grunt phpunit:functional # ãã¡ã³ã¯ã·ã§ãã«ãã¹ã $ grunt phpunit # 両æ¹
grunt phpunit ã®ããã« : ã®å¾ãçç¥ããã¨ãã¹ã¦ã®ã¿ã¹ã¯ãå®è¡ããã¾ãã
æåã®ä¾ã§ã¯ phpunit ã®ã¿ã¹ã¯ã 1 ã¤ããè¨ãã¦ããªãã®ã§ : ã®å¾ã¯çç¥ãã¦ãã¾ãã
grunt ã§ãã£ã¬ã¯ããªç£è¦ã㦠phpunit ãå®è¡
次ã«ãgrunt ã§ãã£ã¬ã¯ããªãç£è¦ãã¦ãã¡ã¤ã«ãæ´æ°ããããèªåçã« phpunit ãå®è¡ãããããã«ãã¾ãã
ã¾ãã¯ãã£ã¬ã¯ããªç£è¦ã®ããã® grunt ã®ãã©ã°ã¤ã³ãã¤ã³ã¹ãã¼ã«ãã¾ãã
$ npm install --save-dev grunt-contrib-watch
Gruntfile.js ãæ¬¡ã®ããã«ä¿®æ£ãã¾ãã
Gruntfile.js
module.exports = function (grunt) { grunt.initConfig({ phpunit: { options: { bin: 'vendor/bin/phpunit', configuration: 'tests/', colors: true, followOutput: true }, test: {} }, watch: { php: { tasks: ['phpunit'], // ãã¡ã¤ã«ã®å¤æ´æã«å®è¡ããã¿ã¹ã¯ files: [ 'src/**/*.php', // ç£è¦ãããã¹ 'tests/**/*.php' // åä¸ ] } } }); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-phpunit'); grunt.registerTask('default', ['watch']); // ããã©ã«ãã®ã¿ã¹ã¯ã watch ã«ãã };
grunt watch ã§ãã£ã¬ã¯ããªç£è¦ãéå§ãã¾ãã
$ grunt watch Running "watch" task Waiting...
ã³ã³ã½ã¼ã«ã®å¿çãããã§æ¢ã¾ãã¾ããã³ã³ã½ã¼ã«ã¯ãã®ã¾ã¾ã§ src/Sample.php ãä¿®æ£ãã¾ãã
<?php class Sample { public function func($a, $b) { return $a + $b; } }
èªåçã« phpunit ãå®è¡ããã¦ãã¹ãã OK ã«ãªãã¾ããã
Waiting...OK >> File "src/Sample.php" changed. Running "phpunit:test" (phpunit) task Starting phpunit (target: test) in PHPUnit 3.7.28 by Sebastian Bergmann. Configuration read from /home/ore/work/example/php-grunt/tests/phpunit.xml.dist . Time: 26 ms, Memory: 3.25Mb OK (1 test, 1 assertion) Done, without errors. Completed in 0.461s at Tue Dec 03 2013 22:43:53 GMT+0900 (JST) - Waiting...
ãã®å¾ã Sample.php ã SampleTest.php ãç·¨éãããã³ã«èªåçã«ãã¹ããå®è¡ããã¾ãã
ãªããgrunt ã弿°ãªãã§å®è¡ãã㨠default ã¨ããã¿ã¹ã¯ãå®è¡ããã¾ãã
âã® Gruntfile.js ã§ã¯ grunt.registerTask() ã§ default ã«è¨å®ãã¦ããã®ã§ãgrunt ã¨æã¤ã ãã§ watch ã¿ã¹ã¯ãå®è¡ããã¾ãã
$ grunt Running "watch" task Waiting...
grunt ã§ PHP ãã«ãã¤ã³ã¦ã§ããµã¼ãã使ã
grunt-php 㯠grunt ãã PHP ã®ãã«ãã¤ã³ã¦ã§ããµã¼ããå®è¡ããããã®ãã©ã°ã¤ã³ã§ãã ãã«ãã¤ã³ã¦ã§ããµã¼ããå®è¡ããã«ã¯ããã¥ã¡ã³ãã«ã¼ããå¿ è¦ãªã®ã§é©å½ã«ä½ã£ã¦ããã¾ãã
public/index.php
<?php require __DIR__ . '/../vendor/autoload.php'; var_dump(date('Y/m/d H:i:s')); $sample = new Sample(); var_dump($sample->add(3, 4));
grunt-php ãã¤ã³ã¹ãã¼ã«ãã¾ãã
$ npm install --save-dev grunt-php
Gruntfile.js ãæ¬¡ã®ããã«æ¸ãæãã¾ãã
Gruntfile.js
module.exports = function (grunt) { grunt.initConfig({ php: { options: { port: 5000, // ãªãã¹ã³ãããã¼ãçªå· base: 'public' // ããã¥ã¡ã³ãã«ã¼ã }, dist: {} } }); grunt.loadNpmTasks('grunt-php'); grunt.registerTask('default', ['php:dist']); };
æ©éå®è¡ãã¦ã¿ã¾ãã
$ grunt Running "php:dist" (php) task PHP 5.5.6 Development Server started at Tue Dec 3 22:44:24 2013 Listening on http://127.0.0.1:5000 Document root is /home/ore/work/example/php-grunt/public Press Ctrl-C to quit. [Tue Dec 3 22:44:24 2013] 127.0.0.1:35661 [200]: / Done, without errors.
ä¸ç¬ã ããã«ãã¤ã³ã¦ã§ããµã¼ããç«ã¡ä¸ãã£ã¦ grunt ã®çµäºã¨ã¨ãã«çµäºãã¾ããã
ããã ãã ã¨ãªãã®å½¹ã«ãç«ã¡ã¾ããããe2e ãã¹ãã¨ãã§ Web ãµã¼ããå¿ è¦ãªã¨ãã«ãã¹ãã®å®è¡ã«ãããã¦ãã«ãã¤ã³ã¦ã§ããµã¼ããç«ã¡ä¸ãããã¨ãåºæ¥ã¾ãã
ä¾ãã°ãSampleTest.php ãæ¬¡ã®ããã«æ¸ãæãã¦ã¿ã¾ãã
SampleTest.php
<?php class SampleTest extends PHPUnit_Framework_TestCase { function test() { $body = file_get_contents('http://localhost:5000'); assertNotEmpty($body); } }
ãã®ã¾ã¾ phpunit ãå®è¡ãã¦ã 5000 ãã¼ãã§å¾ ã¡åãã¦ãã Web ãµã¼ããç¡ãã®ã§ãã¹ãã¯ã³ã±ã¾ãã
$ vendor/bin/phpunit -c tests/ --colors PHPUnit 3.7.28 by Sebastian Bergmann. Configuration read from /home/ore/work/example/php-grunt/tests/phpunit.xml.dist E Time: 22 ms, Memory: 3.00Mb There was 1 error: 1) SampleTest::test file_get_contents(http://localhost:5000): failed to open stream: Connection refused /home/ore/work/example/php-grunt/tests/SampleTest.php:6 FAILURES! Tests: 1, Assertions: 0, Errors: 1.
ããã§ Gruntfile.js ãæ¬¡ã®ããã«æ¸ãæãã¾ãã
Gruntfile.js
module.exports = function (grunt) { grunt.initConfig({ phpunit: { options: { bin: 'vendor/bin/phpunit', configuration: 'tests/', colors: true, followOutput: true }, test: {} }, php: { options: { port: 5000, base: 'public' }, dist: {} } }); grunt.loadNpmTasks('grunt-php'); grunt.loadNpmTasks('grunt-phpunit'); // ã¿ã¹ã¯ã php:dist -> phpunit ã¨ç¶ãã¦å®è¡ãã grunt.registerTask('default', ['php:dist', 'phpunit']); };
grunt ãå®è¡ãã¾ãã
$ grunt Running "php:dist" (php) task PHP 5.5.6 Development Server started at Tue Dec 3 22:46:02 2013 Listening on http://127.0.0.1:5000 Document root is /home/ore/work/example/php-grunt/public Press Ctrl-C to quit. [Tue Dec 3 22:46:02 2013] 127.0.0.1:35667 [200]: / Running "phpunit:test" (phpunit) task Starting phpunit (target: test) in PHPUnit 3.7.28 by Sebastian Bergmann. Configuration read from /home/ore/work/example/php-grunt/tests/phpunit.xml.dist [Tue Dec 3 22:46:02 2013] 127.0.0.1:35669 [200]: / . Time: 30 ms, Memory: 3.25Mb OK (1 test, 1 assertion) Done, without errors.
ä»åº¦ã¯ãã¹ãã®å®è¡ä¸ã« grunt ããã«ãã¤ã³ã¦ã§ããµã¼ããç«ã¡ä¸ããã®ã§ããã¹ãã OK ã«ãªãã¾ããã
grunt-php ã§åã«ãã«ãã¤ã³ã¦ã§ããµã¼ããèµ·åãã
grunt-php ã®æåã®ä¾ã§ã¯ããã«ãã¤ã³ã¦ã§ããµã¼ããèµ·åããå¾ãããã«çµäºãã¦ãã¾ãã¾ãããã Gruntfile.js ã§æ¬¡ã®ããã«æå®ããã°ãã«ãã¤ã³ã¦ã§ããµã¼ããèµ·åããã¾ã¾ã«ãããã¨ãã§ãã¾ãã
Gruntfile.js
module.exports = function (grunt) { grunt.initConfig({ php: { options: { port: 5000, base: 'public' }, web: { options: { keepalive: true, // ãã«ãã¤ã³ã¦ã§ããµã¼ããèµ·åããã¾ã¾ã«ãã open: true // ã¿ã¹ã¯ã®å®è¡æã«ãã©ã¦ã¶ãéã } } } }); grunt.loadNpmTasks('grunt-php'); grunt.registerTask('default', ['php:web']); };
grunt ãå®è¡ããã¨ã»ã»ã»ãã«ãã¤ã³ã¦ã§ããµã¼ããèµ·åãã¤ã¤ããã©ã¦ã¶ãèµ·åã㦠http://localhost:5000/ ãéããã¾ãã
$ grunt Running "php:web" (php) task PHP 5.5.6 Development Server started at Tue Dec 3 22:51:42 2013 Listening on http://127.0.0.1:5000 Document root is D:\ore\work\example\php-grunt\public Press Ctrl-C to quit. [Tue Dec 3 22:51:43 2013] 127.0.0.1:63381 [200]: / [Tue Dec 3 22:51:43 2013] 127.0.0.1:63382 [200]: /
çµäºããã¨ã㯠Ctrl-C ã§çµäºãã¦ãã ããï¼ãã©ã¦ã¶ã¯æã§éãã¦ãã ããï¼ã
ã§ãããã ãã ã¨æ®éã«ãã«ãã¤ã³ã¦ã§ããµã¼ããå®è¡ããã°ããã§ããã»ã»ã»
grunt-php ã§ãã«ãã¤ã³ã¦ã§ããµã¼ããèµ·åã㦠LiveReload ãã
次㫠grunt ã§ãã«ãã¤ã³ã¦ã§ããµã¼ããç«ã¡ä¸ãã¤ã¤ LiveReload ã§ãã¡ã¤ã«æ´æ°æã«ãã©ã¦ã¶ãèªåçã«ãªãã¼ãããããã«ãã¾ãã
LiveReload ã«é¢ãã¦ã¯ ãã®ã¸ã ã§èª¿ã¹ãã°ããã¨æãã¾ãã
ç§ã¯ FireFox ã®ã¢ããªã³ã使ã£ã¦ã¾ãã
ããã§ã¯æ©é Gruntfile.js ãç·¨éãã¾ãã
Gruntfile.js
module.exports = function (grunt) { grunt.initConfig({ php: { options: { port: 5000, base: 'public/' }, web: { options: { open: true } } }, watch: { php: { options: { livereload: true // ãã¡ã¤ã«ã®æ´æ°æã« LiveReload ãã }, tasks: [], files: [ 'public/*.php', 'src/**/*.php' ] } } }); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-php'); // ã¿ã¹ã¯ã php:web -> watch ã¨ç¶ãã¦å®è¡ãã grunt.registerTask('default', ['php:web', 'watch']); };
grunt ãå®è¡ãã¾ãã
$ grunt Running "php:web" (php) task PHP 5.5.6 Development Server started at Tue Dec 3 22:59:14 2013 Listening on http://127.0.0.1:5000 Document root is D:\ore\work\example\php-grunt\public Press Ctrl-C to quit. [Tue Dec 3 22:59:14 2013] 127.0.0.1:63404 [200]: / Running "watch" task Waiting...[Tue Dec 3 22:59:14 2013] 127.0.0.1:63405 [200]: /
ãã©ã¦ã¶ãèµ·åããã®ã§ã¢ããªã³ã® LiveReload ãæå¹ã«ãã¾ãã
FireFox ãªã
ãªæãã®ã¢ã¤ã³ã³ãã¯ãªãã¯ãã¦
ãªæãã«ãªãã° OK ã§ãã
ããã¦ããããã« Sample.php ãç·¨éãã¾ãã
Sample.php
<?php class Sample { public function func($a, $b) { return $a * $b; } }
èªåçã«ãã©ã¦ã¶ããªãã¼ãããã¾ãããã
$ grunt Waiting...[Tue Dec 3 22:59:14 2013] 127.0.0.1:63405 [200]: / OK >> File "public\index.php" changed. ... Reload public\index.php ... ... Reload public\index.php ... Completed in 0.000s at Tue Dec 3 2013 22:59:19 GMT+0900 (æ±äº¬ (æ¨æºæ)) - Waiting... [Tue Dec 3 22:59:19 2013] 127.0.0.1:63411 [200]: /
Gruntfile.js ãã¾ã¨ãã
ããã¾ã§ã®ä¾ã§ã¯ç°¡ååã®ããã« phpunit ã® Gruntfile.js 㨠livereload ã® Gruntfile.js ãå¥ã ã«ä½ãã¾ãããã1 ã¤ã®ãã¡ã¤ã«ã«ã¾ã¨ãããã¨ãåºæ¥ã¾ãã
Gruntfile.js
module.exports = function (grunt) { grunt.initConfig({ php: { options: { port: 5000, base: 'public/' }, dist: {}, web: { options: { open: true } } }, phpunit: { options: { bin: 'vendor/bin/phpunit', configuration: 'tests/', colors: true, followOutput: true }, test: {} }, watch: { web: { options: { livereload: true }, tasks: [], files: [ 'public/*.php', 'src/**/*.php' ] }, test: { options: { livereload: false }, tasks: ['phpunit'], files: [ 'src/**/*.php', 'tests/**/*.php' ] } } }); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-php'); grunt.loadNpmTasks('grunt-phpunit'); grunt.registerTask('web', ['php:web', 'watch:web']); grunt.registerTask('test', ['php:dist', 'watch:test']); };
ãã® Gruntfile.js ã§ã¯æ¬¡ã®éãã«ã¿ã¹ã¯ãå®ç¾©ãã¦ãã¾ãã
grunt web- ãã«ãã¤ã³ã¦ã§ããµã¼ããèµ·å
- ãã©ã¦ã¶ãéã
- ãã£ã¬ã¯ããªãç£è¦ã㦠livereload ã§ãã©ã¦ã¶ããªãã¼ããã
grunt test- ãã«ãã¤ã³ã¦ã§ããµã¼ããèµ·å
- ãã£ã¬ã¯ããªãç£è¦ã㦠phpunit ãå®è¡ãã
grunt-contrib-watch ã grunt-este-watch ã«å¤æ´ãã
grunt-contrib-watch ã¨åããããªãã©ã°ã¤ã³ã« grunt-este-watch ã¨ãããã®ãããã¾ãã
- steida/grunt-este-watch
- grunt-contrib-watch ãéãã®ã§ grunt-este-watch ã試ããã幸ãã«ãªã£ã - ã¦ã£ãç ®ããã°
- grunt-este-watch ãã£ã¡ã便å©ããã - é³ã®é³´ãããã°
grunt-este-watch ã®æ¹ã CPU 使ç¨çãä½ãã¦ãªã¹ã¹ã¡ãããã®ã§ãâã§è©¦ãã phpunit ãèªåå®è¡ãã Gruntfile.js ã grunt-este-watch ã使ãããã«å¤æ´ãã¦ã¿ã¾ãã
ã¾ã㯠grunt-este-watch ãã¤ã³ã¹ãã¼ã«ãã¾ãã
$ npm install -save-dev grunt-este-watch
Gruntfile.js ãæ¸ãæãã¾ãã説æã¯çãã®ã§âã®è¨äºã¨ããåèã«ãã¦ãã ããã
Gruntfile.js
module.exports = function (grunt) { grunt.initConfig({ php: { options: { port: 5000, base: 'public/' }, dist: {} }, phpunit: { options: { bin: 'vendor/bin/phpunit', configuration: 'tests/', colors: true, followOutput: true }, test: {} }, esteWatch: { options: { dirs: [ // ç£è¦å¯¾è±¡ã®ãã£ã¬ã¯ã㪠// ãã¡ã¤ã«ã§ã¯ãªããã£ã¬ã¯ããªãæå®ãã¾ã 'src/**/', 'tests/**/' ], livereload: { // LiveReload ãç¡å¹ã«ãã // ããããã®ã³ã¡ã³ãã¨å ¥ãæ¿ããã°æå¹ã«ãªãã¾ã enabled: false //enabled: true, //port: 35729, //extensions: ['php', 'js', 'css'] } }, // `php:` ã®é¨åã§å¤æ´ããããã¡ã¤ã«ã®æ¡å¼µåãæå®ãã¾ã // æ»ãå¤ã§å®è¡ããã¿ã¹ã¯ãè¿ãã¾ã // filepath ã«ã¯å¤æ´ããããã¡ã¤ã«ã®ãã¹ãå ¥ã£ã¦ãã¾ã php: function (filepath) { return ['phpunit']; } } }); grunt.loadNpmTasks('grunt-este-watch'); grunt.loadNpmTasks('grunt-phpunit'); grunt.loadNpmTasks('grunt-php'); grunt.registerTask('default', ['php:dist', 'esteWatch']); };
grunt ãå®è¡ãã¦ã½ã¼ã¹ãã¡ã¤ã«ãä¿®æ£ããã¨èªåçã«ãã¹ããå®è¡ããã¾ãã
$ grunt Running "php:dist" (php) task PHP 5.5.6 Development Server started at Tue Dec 3 22:48:47 2013 Listening on http://127.0.0.1:5000 Document root is /home/ore/work/example/php-grunt/public Press Ctrl-C to quit. [Tue Dec 3 22:48:47 2013] 127.0.0.1:35682 [200]: / Running "esteWatch" task >> Waiting... 4 dirs watched within 4 ms. >> User action. >> File changed: src/Sample.php Running "phpunit:test" (phpunit) task Starting phpunit (target: test) in PHPUnit 3.7.28 by Sebastian Bergmann. Configuration read from /home/ore/work/example/php-grunt/tests/phpunit.xml.dist [Tue Dec 3 22:48:49 2013] 127.0.0.1:35684 [200]: / . Time: 27 ms, Memory: 3.00Mb OK (1 test, 1 assertion) Running "esteWatch" task >> Waiting...
ãªããgrunt-este-watch ã¯ãã£ã¬ã¯ããªç£è¦ã Linux ãªã inotifyãWindows ãªã ReadDirectoryChangesW ã§å®è£ ããã¦ããããï¼æ£ãã㯠grunt-este-watch ã使ã£ã¦ãã fs.watch ãï¼ã ãããã¯ã¼ã¯ãã¡ã¤ã«ã·ã¹ãã ãªã©ã§åä½ããªãå ´åãããã¾ãï¼Linux ã® cifs ã§ã¯åä½ãã¾ããã§ããï¼ã
ãããã«
ä»ã«ãå®çªãã®ã 㨠grunt-phpcpd ã grunt-phpmd ãªã©ãããã®ã§ã CPD ã PMD ããã£ã¦ã人ã¯ä½¿ã£ã¦ã¿ãã¨ããã®ã§ã¯ãªãã§ããããã