2016-10-23 3 views
-1

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> 

나는 명령을 실행하는 경우 :

A screen of the console

도움 주셔서 감사합니다. Symfony와 PHPUnit에 익숙하지 않아 이런 종류의 문제로 많은 시간을 낭비했습니다.

+0

use 문에 대한 귀하의 의견에도 불구하고 테스트가 실행되고 있지 않다는 것은 꽤 분명합니다. 설정에서 다이로 확인한 다음 phpunit xml 파일에 수행 한 작업을 확인하십시오. – Cerad

+0

"설치 프로그램에서 다이와 함께 확인하십시오"라는 말의 의미를 이해할 수 없습니다. 서비스 userDAO에 관한 모든 행을 제거하면 제대로 작동하기 때문에 PHPunit가 올바르게 구성되었습니다. 그럼에도 불구하고 나는이 정보들을 더한다 – Namiro

답변

1

제가 틀렸을 때 제발 나를 교정 해주세요. 그러나 시험은 src\RepositoryBundle\Tests\DAO에 있고 폴더 앱에서 phpunit을 실행하고 있습니다. ...

시도 phpunit (편집 물론 c 옵션은 인수가 필요합니다 : /) 작동해야합니다.

구성이 '../src/*Bundle/Tests'를 찾도록 구성되었습니다. 앱 폴더를 테스트 검색을위한 장소로 제공하면 구성이 고려되지 않습니다.

+0

'phpunit -c'를 실행할 때 명령이 읽어야하는 설정 파일이 어디 있는지 말해야한다. 그리고이 설정 파일은 app /에 있습니다. 동일한 구성이지만 setUp()이없고 $ USERDAO -> ... 호출이 없으므로 테스트가 실행되므로 phpunit 명령에서 테스트를 찾을 수 있습니다. 그래서 문제는 내 서비스에서 온 전화에서 왔습니다. 그러나 나는 왜 그런지 모른다. – Namiro

+0

어쩌면 잘못된 접근 방식, 당신이 구성 파일을 제공해야합니다 - C 옵션을 제공하는 경우, 내 대답을 수정, offcourse. – Senaria21

+0

setUp() 디버깅을 시도 했습니까? 내 말은 아마도 먼저 tao 서비스에 대한 주석을 없애기 위해서 일 것이다. 작동중인 경우 서비스에 문제가있는 것입니다 (소리가 나는 것). – Senaria21