2017-01-12 6 views
2

미안하지만 어리석은 질문 일지 모르지만 인터넷 검색을 통해 답변을 찾을 수 없습니다.yii2의 비품을 이용한 코드 동의 수용 테스트

내 질문은 : 나는 데이터 디렉토리에 데이터가 고정 클래스가 선언

use yii\test\FixtureTrait; 
    public function fixtures() { 
     return ['tasks' => TasksFixture::className()]; 
    } 

다음 한 해당 파일에서, 백엔드 \ 수용에서 파일 TaskCest.php을 만들었습니다. 내가 스크립트를 실행할 때 오류 다음 얻을

그러나 : 파일 yii2의 \ 테스트에서,

[yii\base\ErrorException] ltrim() expects parameter 1 to be string, object given 

오류가 분명하다,하지만 난 이해하지 못할 \ FixtureTrait.php : 나는 이름 매개 변수가 될 것으로 예상하고 기능이 (145) 문자열하지만 자동으로 전달되는 개체 [나는 getFixture를 호출하지 않는다]. 무엇이 문제입니까? 누군가가 똑같이 직면 했습니까?

-vvv 출력

시험 검사/승인/TaskCest.php : getFixture

[yii\base\ErrorException] ltrim() expects parameter 1 to be string, object given 

/home/nginx/www/planning-back/vendor/codeception/codeception/src/Codeception/Lib/Di.php:123 
/home/nginx/www/planning-back/vendor/codeception/codeception/src/Codeception/Lib/Di.php:123 
/home/nginx/www/planning-back/vendor/codeception/codeception/src/Codeception/Test/Cest.php:136 
/home/nginx/www/planning-back/vendor/codeception/codeception/src/Codeception/Test/Cest.php:148 
/home/nginx/www/planning-back/vendor/codeception/codeception/src/Codeception/Test/Cest.php:82 
/home/nginx/www/planning-back/vendor/codeception/codeception/src/Codeception/Test/Test.php:90 
/home/nginx/www/planning-back/vendor/phpunit/phpunit/src/Framework/TestSuite.php:728 
/home/nginx/www/planning-back/vendor/codeception/codeception/src/Codeception/PHPUnit/Runner.php:98 
/home/nginx/www/planning-back/vendor/codeception/codeception/src/Codeception/SuiteManager.php:154 
/home/velaro/.config/composer/vendor/codeception/codeception/src/Codeception/Codecept.php:183 
/home/velaro/.config/composer/vendor/codeception/codeception/src/Codeception/Codecept.php:152 
/home/velaro/.config/composer/vendor/codeception/codeception/src/Codeception/Command/Run.php:282 
/home/velaro/.config/composer/vendor/symfony/console/Command/Command.php:255 
/home/velaro/.config/composer/vendor/symfony/console/Application.php:829 
/home/velaro/.config/composer/vendor/symfony/console/Application.php:191 
/home/velaro/.config/composer/vendor/symfony/console/Application.php:122 
/home/velaro/.config/composer/vendor/codeception/codeception/src/Codeception/Application.php:103 
/home/velaro/.config/composer/vendor/codeception/codeception/codecept:34 
+0

오류 스택을 확인하거나 붙여 넣을 수 있습니까? 나는 이걸 어디에서 얻을 수 있는지 찾을 수 없습니다. – Bizley

+0

스택에'--debug '를 사용하여 코드 실행을 실행하십시오. – Bizley

+0

디버그 옵션으로 실행해도 붉은 색, 스택 없음으로 출력됩니다. – Velaro

답변

1

Codeception이 Cest - 클래스의 모든 public 메소드를 검색 (테스트 같은 특성의 방법을 인식 특성의 방법을 포함하고 실행). 특성을 다른 클래스 FixtureLoader으로 추출하여 Cest 파일에 포함시켜야합니다.

class FixtureLoader 
{ 
    use \yii\test\FixtureTrait; 

    public $fixtures; 

    public function fixtures() 
    { 
     return $this->fixtures; 
    } 
} 

abstract class ApiCest 
{ 
    /** 
    * @var FixtureLoader 
    */ 
    protected $fixtureLoader; 

    public function __construct() 
    { 
     $this->fixtureLoader = new FixtureLoader(); 
    } 

    protected function fixtures() 
    { 
     return []; 
    } 

    public function _before(\FunctionalTester $I) 
    { 
     $this->fixtureLoader->fixtures = $this->fixtures(); 
     $this->fixtureLoader->loadFixtures(); 
    } 

    public function _after(\FunctionalTester $I) 
    { 
     $this->fixtureLoader->unloadFixtures(); 
    } 
} 


class UserCest extends ApiCest 
{ 
    protected function fixtures() 
    { 
     return [ 
      'users' => UserFixture::className(), 
     ]; 
    } 

    public function testSomething(\FunctionalTester $I) 
    { 
     $I->sendGET('/user'); 
     $I->seeResponseCodeIs(200); 
    } 
}