私はsymfonyの2.8にLiipFunctionalTestBundleに基づいて、私の機能テスト(中備品を追加したいと考えたとしても、それは私が取り組んでのdevのデータベースがあり、私は私が持っていますので、まだ備品を追加する必要があります:リップ機能テストでフィクスチャを追加する方法(symfony 2.8)? 。
- 地域各機能テストは私にとっていいことではないだろう後にDBをパージ有するデータ(国、地域、郡)
- VEHICULEブランドやモデル
- ...
その結果、。
注意:コマンドラインから(パージなし)追加は備品は、成功して取り組んでいる:php app/console doctrine:fixtures:load --append
をので、以下の私の機能テストです:
<?php
namespace Minn\APIBundle\Tests\Controller;
use Liip\FunctionalTestBundle\Test\WebTestCase as WebTestCase;
//use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as WebTestCase;
use Minn\APIBundle\Tests\Fixtures\Entity\LoadBrandData;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
class BrandControllerTest extends WebTestCase {
public function setUp() {
$this->auth = array(
'PHP_AUTH_USER' => 'restapi',
'PHP_AUTH_PW' => 'secretpw',
);
$this->client = static::createClient(array(), $this->auth);
}
public function testJsonGetPageAction() {
$fixtures = array('Minn\APIBundle\Tests\Fixtures\Entity\LoadBrandData');
$this->loadFixtures($fixtures);
$brands = LoadBrandData::$brands;
$brand = array_pop($brands);
$route = $this->getUrl('api_1_brand_get_brand', array('id' => $brand->getId(), '_format' => 'json'));
$this->client->request('GET', $route, array('ACCEPT' => 'application/json'));
$response = $this->client->getResponse();
$this->assertJsonResponse($response, 200);
$content = $response->getContent();
$decoded = json_decode($content, true);
$this->assertTrue(isset($decoded['id']));
}
// ..
}
このテストでは、DBをパージします。
// removed code
$fixtures = array('Minn\APIBundle\Tests\Fixtures\Entity\LoadBrandData');
$this->loadFixtures($fixtures);
// new code
$this->runCommand('doctrine:fixtures:load --append --no-interaction --fixtures=src/Minn/APIBundle/Tests/Fixtures/Entity/LoadBrandData.php');
しかし、機能テストは動作しませdoest:だから、私はこの変更を行うことによってlinkで提案されているコードを試してみました。
There was 1 error:
1) Minn\APIBundle\Tests\Controller\BrandControllerTest::testJsonGetPageAction
Error: Call to a member function getId() on null
/home/amine/NetBeansProjects/minnapi/src/Minn/APIBundle/Tests/Controller/BrandControllerTest.php:27
私はこの変更を行うことによって機能にloadFixtures()を利用可能なオプションを使用してみました:
// removed code:
$fixtures = array('Minn\APIBundle\Tests\Fixtures\Entity\LoadBrandData');
$this->loadFixtures($fixtures);
// new code
$fixtures = array('Minn\APIBundle\Tests\Fixtures\Entity\LoadBrandData');
$this->loadFixtures($fixtures, null,'doctrine', ORMPurger::PURGE_MODE_DELETE);
評決:DBは常に機能テストの各実行後にパージされます。
だから、どんな提案?
おかげで、
NB:は、機能的テストのためにSQLiteデータベースを使用することが可能であるcomposer.json
"doctrine/doctrine-fixtures-bundle": "dev-master",
"phpunit/phpunit": "5.4.*",
"liip/functional-test-bundle":"1.6.*",
"guzzle/guzzle": "v3.9.*"
機能テストに別のデータベースを使用しない理由はありますか? – geoB
私はすべてのアイデアに公開しています。リンクや例がありますか? –
バンドルの設定で説明したようにSQLiteデータベースを使用していますか? –