Php/phpunit/インストール
提供: 初心者エンジニアの簡易メモ
目次
pearからphpunitをインストール
# pearアップデート sudo pear upgrade PEAR # チャンネル追加 sudo pear channel-discover pear.phpunit.de sudo pear channel-discover pear.symfony.com # 依存パッケージごとPHPUnitインストール sudo pear install phpunit/PHPUnit Did not download optional dependencies: phpunit/PHP_Invoker, use --alldeps to download automatically phpunit/PHPUnit can optionally use package "phpunit/PHP_Invoker" (version >= 1.1.0, version <= 1.1.99) phpunit/PHP_CodeCoverage can optionally use PHP extension "xdebug" (version >= 2.0.5) phpunit/PHPUnit_MockObject can optionally use PHP extension "soap" downloading PHPUnit-3.7.15.tgz ... Starting to download PHPUnit-3.7.15.tgz (117,692 bytes) .........................done: 117,692 bytes downloading File_Iterator-1.3.3.tgz ... Starting to download File_Iterator-1.3.3.tgz (5,152 bytes) ...done: 5,152 bytes downloading Text_Template-1.1.4.tgz ... Starting to download Text_Template-1.1.4.tgz (3,701 bytes) ...done: 3,701 bytes downloading PHP_CodeCoverage-1.2.9.tgz ... Starting to download PHP_CodeCoverage-1.2.9.tgz (159,582 bytes) ...done: 159,582 bytes downloading PHP_Timer-1.0.4.tgz ... Starting to download PHP_Timer-1.0.4.tgz (3,694 bytes) ...done: 3,694 bytes downloading PHPUnit_MockObject-1.2.3.tgz ... Starting to download PHPUnit_MockObject-1.2.3.tgz (20,390 bytes) ...done: 20,390 bytes downloading PHP_TokenStream-1.1.5.tgz ... Starting to download PHP_TokenStream-1.1.5.tgz (9,859 bytes) ...done: 9,859 bytes install ok: channel://pear.phpunit.de/File_Iterator-1.3.3 install ok: channel://pear.phpunit.de/Text_Template-1.1.4 install ok: channel://pear.phpunit.de/PHP_Timer-1.0.4 install ok: channel://pear.phpunit.de/PHP_TokenStream-1.1.5 install ok: channel://pear.phpunit.de/PHP_CodeCoverage-1.2.9 install ok: channel://pear.phpunit.de/PHPUnit_MockObject-1.2.3 install ok: channel://pear.phpunit.de/PHPUnit-3.7.15 phpunit --version
以下エラーが出る場合
PHP Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /usr/lib/php/pear/PHPUnit/Autoload.php on line 45
/etc/php.iniの[PHP]項目に以下を追加
include_path = ".:/usr/lib/php/pear"
Xdebug拡張モジュールのインストール
コードカバレッジ機能を使うため
cd /usr/local/src wget http://xdebug.org/files/xdebug-2.2.3.tgz tar xvzf xdebug-2.2.3.tgz cd xdebug-2.2.3 phpize ./configure --enable-xdebug make sudo make install php -r "phpinfo();"|grep xdebug
- php.ini
[xdebug] zend_extension="/usr/local/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so"
phpunit拡張ライブラリインストール
Failed opening required 'PHPUnit/Extensions/Database/TestCase.php
sudo yum install php-pdo sudo pear install phpunit/DbUnit
Failed opening required 'PHPUnit/Extensions/SeleniumTestCase.php'
sudo pear install phpunit/PHPUnit_Selenium
Failed opening required 'PHPUnit/Extensions/Story/TestCase.php'
pear install phpunit/PHPUnit_Story
Fatal error: Uncaught exception 'PHPUnit_Framework_Error_Warning' with message 'include_once(PHP/Invoker.php)
pear install phpunit/PHP_Invoker
composerでインストール
composer.json
{ "require-dev": { "phpunit/phpunit": "3.7.*" } },
インストールコマンド
$ composer install --dev
phpunit実行
$ vendor/symfony/symfony/phpunit