0
可能性がありますか、またはメソッドを擬似したクラスの引数をテストすることをお勧めしますか? 例:テストされたメソッドのテスト引数
class CarType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->addEventSubscriber(new User('argument example')
}
}
これは私のテストで:
public function testFormBuilder()
{
$builder = $this->getMockBuilder('Symfony\Component\Form\FormBuilder')
->disableOriginalConstructor()
->getMock();
// Test
$type = new CarType();
$this->builder->expects($this->once())
->method('addEventSubscriber')
->with(
$this->isInstanceOf(User::class)
);
$type->buildForm($this->builder, []);
}
このテスト作業罰金、しかし...私はUser
クラスの最初の引数が文字列であるかどうかを知りたい ことができますが、私はこの同じテストでやっている?
'User'の引数は、ハコードされた値か' $ options'にあるものですか?もしそれが文字列であるかどうかを本当に確認する必要があるのであれば、 'User'コンストラクタでパラメータの検証を行う必要があります。phpunitでテストできます。 – olibiaz