Voglio testare un metodo di esempio con hint di tipo scalare e tipi rigorosi in PHP7. Quando non passo un argomento, il metodo dovrebbe lanciare un TypeError
. PHPSpec tornare errore fatale:PHPSpec Catching TypeError in PHP7
Uncaught TypeError: Argument 1 passed to Example::test
<?php
class Example
{
public function test(string $name)
{
$this->name = $name;
}
}
class ExampleSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Test\Example');
}
function it_check_test_method_when_not_pass_argument()
{
$this->shouldThrow('\TypeError')->during('test');
}
}
All'inizio dichiaro: declare(strict_types=1);
Cosa c'è di sbagliato? Come posso testare il lancio di TypeError
?
Quindi l'eccezione viene lanciata ma non catturata? O non viene lanciato e dovrebbe essere? – Will
Metodo di lancio TypeError e I want catch TypeError. Voglio usare $ this-> shouldThrow ('\ TypeError') -> durante ('test'). Questo metodo in PHPSpec funziona quando il metodo restituisce Exception ma non TypeError. – Matrix12
Stai utilizzando la versione più recente di PHPSpec? – Will