1
我嘗試當我運行這個測試使用的PHPUnit與laravel 5.2Laravel PHPUnit的 '未定義的變量:錯誤'
:
class TestInscription extends TestCase
{
/******************************************************************************/
/* pour lancer le test : C:\wamp\www\compet>phpunit tests/TestInscription.php */
/******************************************************************************/
function __construct()
{
parent::setUp();
}
public function testInscriptionAvecErreur()
{
$this->visit('inscription')
->seePageIs('inscription')
->see('Inscription')
->type('', 'nom')
->type('', 'prenom')
->type('', 'email')
->type('', 'password')
->type('', 'password_confirm')
->press('bouton_valider')
->seePageIs('inscription')
->see('Nom obligatoire')
->see('Prénom obligatoire')
->see('Adresse email obligatoire')
->see('Mot de passe obligatoire');
}
==>我有一個響應 「OK」。
當添加的第二測試化到同一類別,例如:
class TestInscription extends TestCase
{
/******************************************************************************/
/* pour lancer le test : C:\wamp\www\compet>phpunit tests/TestInscription.php */
/******************************************************************************/
function __construct()
{
parent::setUp();
}
public function testInscriptionAvecErreur()
{
$this->visit('inscription')
->seePageIs('inscription')
->see('Inscription')
->type('', 'nom')
->type('', 'prenom')
->type('', 'email')
->type('', 'password')
->type('', 'password_confirm')
->press('bouton_valider')
->seePageIs('inscription')
->see('Nom obligatoire')
->see('Prénom obligatoire')
->see('Adresse email obligatoire')
->see('Mot de passe obligatoire');
}
public function testInscriptionAvecErreurMdp()
{
$this->visit('inscription')
->seePageIs('inscription')
->see('Inscription')
->type('azerty', 'password')
->type('azertyu', 'password_confirm')
->press('bouton_valider')
->seePageIs('inscription')
->see('Les 2 mots de passe sont différents');
}
}
然後我有第一測試錯誤(第二個不被觸發)。錯誤是:
Time: 2.69 seconds, Memory: 20.50MB
There was 1 failure:
1) TestInscription::testInscriptionAvecErreur
A request to [http://localhost/inscription] failed. Received status code [500].
C:\wamp\www\compet\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithPages.php:196
C:\wamp\www\compet\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithPages.php:80
C:\wamp\www\compet\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithPages.php:61
C:\wamp\www\compet\tests\TestInscription.php:21
C:\wamp\www\ecole\vendor\phpunit\phpunit\src\TextUI\Command.php:149
C:\wamp\www\ecole\vendor\phpunit\phpunit\src\TextUI\Command.php:100
Caused by
exception 'ErrorException' with message 'Undefined variable: errors' in C:\wamp\www\compet\storage\framework\views\7a56ba5973bcafaa00c3a5edb3816871f0ac8a17.php:44
我看到了這樣的觀點:
<div class="form-group <?php echo e($errors->has('nom') ? 'has-error has-feedback' : ''); ?>">
當然,錯誤是因爲該變量 「$錯誤」,但什麼?
以及爲什麼第一次測試在單獨運行時運行良好。當我添加第二個測試時失敗?
的Merci
多米尼克