Symfony Standard Edition(2.0.1)を利用している前提 また、以下ではPHPUnitをプロジェクトディレクトリ配下に配置している
Standard Edition のルートディレクトリにある deps
ファイルに以下の行を追加する
[behat]
git=http://github.com/Behat/Behat.git
target=/Behat/Behat
[mink]
git=http://github.com/Behat/Mink.git
target=/Behat/Mink
[gherkin]
git=http://github.com/Behat/Gherkin.git
target=/Behat/Gherkin
[BehatBundle]
git=http://github.com/Behat/BehatBundle.git
target=/Behat/BehatBundle
[MinkBundle]
git=http://github.com/Behat/MinkBundle.git
target=/Behat/MinkBundle
[phpunit]
git=http://github.com/knplabs/phpunit-easyinstall.git
vendorインストールスクリプトを実行する
$ php bin/vendors install
PHPUnitの依存モジュールを取得する
$ cd vendor/phpunit
$ git submodule update --init
app/autoload.phpを編集する
$loader->registerNamespaces(array(
// ・・・
'Behat\BehatBundle' => __DIR__.'/../vendor',
'Behat\MinkBundle' => __DIR__.'/../vendor',
'Behat\Behat' => __DIR__.'/../vendor/Behat/Behat/src',
'Behat\Gherkin' => __DIR__.'/../vendor/Behat/Gherkin/src',
'Behat\Mink' => __DIR__.'/../vendor/Behat/Mink/src',
));
$loader->registerPrefixFallback(array(
// ・・・
'/opt/local/lib/php', // システムのPEARのディレクトリ
));
// autoload.phpの末尾にてinclude_path追加設定
set_include_path(get_include_path()
.PATH_SEPARATOR.__DIR__.'/../vendor/phpunit'
.PATH_SEPARATOR.__DIR__.'/../vendor/phpunit/Vendor/php-code-coverage'
.PATH_SEPARATOR.__DIR__.'/../vendor/phpunit/Vendor/php-file-iterator'
.PATH_SEPARATOR.__DIR__.'/../vendor/phpunit/Vendor/php-text-template'
.PATH_SEPARATOR.__DIR__.'/../vendor/phpunit/Vendor/php-timer'
.PATH_SEPARATOR.__DIR__.'/../vendor/phpunit/Vendor/php-token-stream'
.PATH_SEPARATOR.__DIR__.'/../vendor/phpunit/Vendor/phpunit-mock-objects'
);
app/AppKernel.phpのregisterBundles()を編集する
if (in_array($this->getEnvironment(), array('test'))) {
$bundles[] = new Behat\BehatBundle\BehatBundle();
$bundles[] = new Behat\MinkBundle\MinkBundle();
}
app/config/config_test.ymlでテスト用の設定を追加
framework:
test: ~
behat: ~
Behatコマンドの実行。コマンド名が「behat」のみに変わっていることに注意する。
Linux/Macの場合
$ php app/console --env=test behat --init Acme\\TestBundle
Windowsの場合
C:\xampp\htdocs\Symfony>php app/console --env=test behat --init "Acme\DemoBundle"