2017-01-12 3 views
2

Sorry für vielleicht dumme Frage, aber ich kann keine Antwort durch googlen finden.codeception Abnahmetest mit Fixtures in yii2

Meine Frage ist: Ich erstellte Datei TaskCest.php unter Annahme Backend \, die in dieser Datei Erklärung folgende haben

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

ich mit Daten in Datenverzeichnis, dass die Befestigungs Klasse.

Aber wenn ich Skript ausführen ich folgende Fehlermeldung erhalten:

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

Fehler liegt auf der Hand, aber ich kann nicht verstehen, in der Datei yii2 \ test \ FixtureTrait.php: 145 I Funktion haben, die Parameter name erwartet zu sein String aber Objekt wird automatisch übergeben [Ich rufe getFixture nicht an]. Was ist das Problem? Hatte jemand dasselbe gesehen?

-vvv Ausgang

Test-Tests/Annahme/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

Kann Fehlerstack überprüfen oder einfügen? Ich kann nicht herausfinden, woher du das hast. – Bizley

+0

Führen Sie die Codeception mit '--debug' für den Stack aus. – Bizley

+0

es ist nur wie ich in roter Farbe, kein Stapel gedruckt, auch wenn ich mit Debug-Option – Velaro

Antwort

1

Codeception Merkmal Methoden wie Tests erkennen (es alle öffentlichen Methoden der Cest -Klasse gehören die Eigenschaft Methoden suchen und es laufen). Sie sollten das Merkmal in eine andere Klasse FixtureLoader extrahieren und es in Ihre Cest-Datei aufnehmen.

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); 
    } 
} 
Verwandte Themen