2011-10-06 118 views

回答

16

使用assertInstanceOf()而不是PHP內置的instanceof運算符或函數,以便獲得有意義的失敗消息。

function testInstanceOf() { 
    $obj = new Foo; 
    self::assertInstanceOf('Bar', $obj); 
} 

... 

Failed asserting that <Foo> is an instance of class "Bar". 
0

或者你也應該使用這種斷言是這樣的:

$this->assertSame(
     'Symfony\Component\Form\AbstractType', 
     get_parent_class('AppBundle\Form\CarType'), 
     'The form does not extend the AbstractType class' 
     ); 
相關問題