프로덕션 서버의 모든 코드를 업데이트하기 전에 테스트 데이터베이스에 행을 삽입하여 phpunit 테스트를 수행합니다. 테스트 데이터베이스가 프로덕션 데이터베이스의 내용을 반영하지 않으므로 프로덕션 데이터베이스에서 테스트를 수행하고 싶습니다. 테스트가 끝나면 테스트 중에 생성 된 모든 행을 제거하려고합니다. 이것을 달성하는 가장 좋은 방법은 무엇입니까? 나는 완벽하게 잘되고 생산 데이터를 변경할 위험이없는 방법을 생각할 수 없다.Symfony2 테스트 데이터베이스 프로덕션 환경
1
A
답변
1
Alexandre Salome이 설명한 접근법을 Isolation of tests in Symfony2에서 사용하여 트랜잭션 테스트와 롤백을 끝에 끝냅니다. 프로덕션 데이터베이스에서 사용하기 전에이 방법을 철저히 테스트해야하지만 분명히 유용합니다.
0
테스트를 위해 sqlite (기본값)를 사용하는 것이 훨씬 더 빠르며 프로덕션 데이터베이스에서 문제가 발생하더라도 걱정할 필요가 없습니다. 내가 한 일은 모든
EntityTest.php extends TestsHelper.php extends PHPUnit_Framework_TestCase
와의 설정은(), 나는 데이터베이스 및 비품을 만드는 것이 었습니다.
인터넷에서 코드를 가져 와서 작동합니다. 유용 할 수도 있습니다.
// class TestsHelper
/**
* @var Symfony\Component\DependencyInjection\Container
*/
protected $container;
public function setUp()
{
// Boot the AppKernel in the test environment and with the debug.
$this->kernel = new \AppKernel('test', true);
$this->kernel->boot();
// Store the container and the entity manager in test case properties
$this->container = $this->kernel->getContainer();
$this->em = $this->container->get('doctrine')->getEntityManager();
// Build the schema for sqlite
$this->generateSchema();
$this->generateFixtures() ;
parent::setUp();
}
public function tearDown()
{
// Shutdown the kernel.
$this->kernel->shutdown();
parent::tearDown();
}
protected function generateSchema()
{
// Get the metadatas of the application to create the schema.
$metadatas = $this->getMetadatas();
if (! empty($metadatas)) {
// Create SchemaTool
/**
* @var \Doctrine\ORM\Tools\SchemaTool
*/
$tool = new SchemaTool($this->em);
// $tool->dropDatabase() ;
$tool->createSchema($metadatas);
} else {
throw new Doctrine\DBAL\Schema\SchemaException('No Metadata Classes to process.');
}
}
/**
* Overwrite this method to get specific metadatas.
*
* @return Array
*/
protected function getMetadatas()
{
return $this->em->getMetadataFactory()->getAllMetadata();
}
그리고 generateFixtures()는 평소와 같이 그들을 만들 것에
는 :$entity = new MyEntity() ;
$this->em->persist($entity) ;
$this->em->flush() ;
+0
감사하지만 프로덕션 데이터베이스에 대한 테스트를 수행하려고했습니다. –
관련 문제
- 1. Tomcat 테스트 및 프로덕션 환경
- 2. Symfony2 - 테스트 폴더
- 3. 테스트 환경과 프로덕션 환경 간의 데이터가 다릅니다
- 4. BizTalk EDI 테스트 및 프로덕션 환경 설치
- 5. 루비에 테스트 환경 데이터베이스 만들기
- 6. Symfony2 프로덕션 캐시 오류
- 7. Tomcat 프로덕션/dev 환경
- 8. Symfony2 - PHPUnit 설정에 기반한 환경 재설정
- 9. Symfony2 및 Doctrine Mysql 테스트 데이터베이스 지속성
- 10. Symfony2와 프로덕션 환경 - allways는 링크에 app_dev를 표시합니다.
- 11. 로깅을위한 별도의 프로덕션 데이터베이스
- 12. Symfony2 환경 구성
- 13. 시시각각 변하는 테스트 환경
- 14. Maven의 프로덕션 데이터베이스 처리
- 15. Google App Engin의 프로덕션 및 테스트 환경 모범 사례
- 16. 테스트 환경 대신 프로덕션 환경을 테스트하는 방법 레일
- 17. Symfony2 테스트에서 데이터베이스 정리
- 18. Entity Framework 6에서 환경 변수가있는 준비/프로덕션 데이터베이스 간 전환
- 19. Symfony2 : sqlite로 단위 테스트
- 20. Symfony2 : 데이터베이스
- 21. Foxx에서 "테스트"환경 감지
- 22. Azure의 프로덕션 대 스테이징 환경
- 23. 개발 및 프로덕션 환경 만들기?
- 24. CakePHP : 개발 및 프로덕션 환경 관리
- 25. phpunit 테스트 환경 간 재설정
- 26. Azure Cloud에서 개발, 준비 및 프로덕션 환경
- 27. Symfony2 환경 변수를 저장하는 곳
- 28. 나뭇 가지 확장 - symfony2 환경
- 29. Vagrant + Symfony2 환경 ContextErrorException 기괴함
- 30. 매핑 프로덕션 데이터베이스
위대한 작품! 고맙습니다 ! –