DAO 서비스를 테스트하고 싶습니다.phpunit에서 Symfony 서비스 사용
문제는 테스트를 실행할 때 아무 것도 추가되지 않는다는 것입니다. 테스트는 실행되지 않습니다. 하지만 필자는 설정 파일 phpunit.xml.dist가 ok입니다. 예를 들어 "사용"라인에서 실수를하면 테스트 오류가 발생합니다.
그래서 나는 당신의 도움이 필요합니다 ..
내 첫 번째 테스트 :
namespace RepositoryBundle\Tests\DAO;
use RepositoryBundle\Entity\User;
use RepositoryBundle\Enum\RoleEnum;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class UserDAOTest extends KernelTestCase
{
private $userDAO;
private $logger;
public function setUp()
{
self::bootKernel();
$this->userDAO = static::$kernel->getContainer()->get('repository.userDAO');
$this->logger = static::$kernel->getContainer()->get('logger');
$logger->notice('Show the log'); // Nothing is in my console.. (I configure Monolog to display in the console)
}
public function testTRUC()
{
//Stupid test but not executed !!!???
$i = 1;
$this->assertTrue($i == 1);
}
public function testCreate()
{
//Real test but not executed !!!???
$user1 = new User();
$user1->setName("TestName");
$user1->setEmail("TestEmail");
$user1->setPassword("TestPassword");
$user1->setMemberNumber(12345);
$user1->setAdmin(true);
$user1->setRole(RoleEnum::User);
$user1 = $UserDAO->save($user1);
$this->assertTrue($user1->getId() > 0);
$this->assertEquals("TestName", $user1->getName());
$this->assertEquals("TestEmail", $user1->getEmail());
$this->assertEquals("TestPassword", $user1->getPassword());
$this->assertEquals(12345, $user1->getMemberNumber());
$this->assertEquals(true, $user1->isAdmin());
$this->assertEquals(RoleEnum::User, $user1->getRole());
}
phpunit.xml.dist
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="phpunit.xsd"
bootstrap="bootstrap.php.cache"
backupGlobals="false"
verbose="true">
<testsuites>
<testsuite name="Project Test Suite">
<directory>../src/*Bundle/Tests</directory>
</testsuite>
</testsuites>
<php>
<const name="PHPUNIT_TESTSUITE" value="true"/>
</php>
</phpunit>
나는 명령을 실행하는 경우 :
을도움 주셔서 감사합니다. Symfony와 PHPUnit에 익숙하지 않아 이런 종류의 문제로 많은 시간을 낭비했습니다.
use 문에 대한 귀하의 의견에도 불구하고 테스트가 실행되고 있지 않다는 것은 꽤 분명합니다. 설정에서 다이로 확인한 다음 phpunit xml 파일에 수행 한 작업을 확인하십시오. – Cerad
"설치 프로그램에서 다이와 함께 확인하십시오"라는 말의 의미를 이해할 수 없습니다. 서비스 userDAO에 관한 모든 행을 제거하면 제대로 작동하기 때문에 PHPunit가 올바르게 구성되었습니다. 그럼에도 불구하고 나는이 정보들을 더한다 – Namiro