Sto scrivendo un test di unità in Laravel 5.0 e nella classe di richiesta sto utilizzando un altro sacchetto per mostrare i messaggi di errore di convalida.LARAVEL 5.0 + Unit Test - assertSessionHasErrors con diversi pacchetti
Sto usando questo nel mio file:
/* ExampleRequest.php */
namespace App\Http\Requests;
use App\Http\Requests\Request;
use Illuminate\Support\Facades\Auth;
class ExampleRequest extends Request {
protected $errorBag = 'otherbag';
public function rules(){
return [
'my_field' => 'required'
];
}
}
Nel mio file di prova, sto testando utilizzare questo:
/* ExampleTest.php */
class ExampleTest extends TestCase {
public function testPostWithoutData(){
$response = $this->call('POST', 'url/to/post',[
'my_field' => ''
]);
$this->assertSessionHasErrors('my_field');
}
}
Se corro i test, non può ottenere la giusta affermare e restituire questo problema:
Session missing error:
my_field
Failed asserting thatfalse
istrue
.
Se prendo l'attributo $errorBag
dal file di richiesta, non ho i problemi.
Posso fornire maggiori dettagli in base alle esigenze.
Puoi spiegare perché hai 'protetto $ errorBag = 'otherbag';' nel tuo oggetto? Che cosa fa questo e perché? –
Perché ho due posti per mostrare gli errori nella mia vista ... E lo gestisco con borse diverse .... – giordanolima