내가 심포니 2.8 LiipFunctionalTestBundle에 따라 제 기능 테스트 (에 설비를 추가하고 싶습니다 비록 그것이 내가 작업 dev에 데이터베이스가, 나는 내가 가지고있는 것이기 때문에 여전히 설비를 추가해야합니까 :liip 기능 테스트에서 조명기를 추가하는 방법 (심포니 2.8)? .
- 지역 데이터 (국가, 지역, 군)
- vehicule 브랜드 및 모델
- ... 각각의 기능 테스트는 나를 위해 좋은하지 않습니다 후 DB가 제거 가진 결과적으로
.
주의 사항 : 명령 줄을 통해 (정화없이) 덧붙이 비품은 성공하고있다 : 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');
하지만, 기능 테스트가 작동하지 도다 : 그래서, 나는이 변화를 수행하여 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 : 번들 버전 composer.json
"doctrine/doctrine-fixtures-bundle": "dev-master",
"phpunit/phpunit": "5.4.*",
"liip/functional-test-bundle":"1.6.*",
"guzzle/guzzle": "v3.9.*"
기능 테스트를 위해 별도의 데이터베이스를 사용하지 않는 이유가 있습니까? – geoB
나는 모든 아이디어에 대해 열려 있습니다. 링크 나 예제가 있습니까? –
번들 구성에서 설명한대로 SQLite 데이터베이스를 사용합니까? –