###実現したいこと
PHPUnitを使用しテストを行いたいと思っています。
(Controllerのテストです)
モックの生成箇所でエラーになり、エラーメッセージの内容が理解できず、どのように解決すればいいのかわからなかったのでどなたかお教えいただければと思います。
###エラーメッセージ
1) Tests\Feature\ExampleTest::testFooController TypeError: Argument 1 passed to App\Http\Controllers\FooController::__construct() must be an instance of Foo\foo, instance of PHPUnit_Framework_MockObject_MockBuilder given, called in /tests/Feature/ExampleTest.php on line 70
###該当のソースコード
PHP
1 /** 2 * PHPUnit のモックを使った実装 3 */ 4 public function testFooController() 5 { 6 // モックの生成 7 $foo = $this->getMockBuilder(\App\Http\Controllers\FooController::class); 8 $foo->setMethods(['index']) 9 ->getMock(); 10 11 // モックの宣言 12 $foo->expects($this->once()) 13 ->method('index') 14 ->with($this->equalTo('test')); 15 16 // 実行 17 $subject = new Subject('My subject'); 18 $subject->attach($foo); 19 $subject->doSomething(); 20 }
PHP
1FooController.php 2 3 /** 4 * Create a new controller instance. 5 * 6 * @return void 7 */ 8 public function __construct(Foo\foo $foo) 9 { 10 $this->foo = $foo; 11 } 12 13 14 /** 15 * Show the application dashboard. 16 * 17 */ 18 public function index() 19 { 20 return view('users.index'); 21 } 22
###補足情報(言語/FW/ツール等のバージョンなど)
Laravel5.4
PHPUnit 5.7
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー