2016-10-07 8 views
1

私はCakePHP 3コンポーネントを模擬しようとしています。CakePHP 3コンポーネントを模擬しようとしたときにエラーが発生しました

私はこれを試してみました:

$authComponent = $this->getMockBuilder(App\Controller\Component\AuthorizationComponent::class) 
    ->getMock(); 

$authComponent 
    ->method('isAuthorized') 
    ->willReturn($this->returnValue(true)); 

テストを実行している場合しかし、それは言う:

Trying to configure method "isAuthorized" which cannot be configured because it does not exist, has not been specified, is final, or is static 

は、おそらく私が間違ってモックを作成しました。それを正しく行う方法を教えてもらえますか?

+1

あなたのコンポーネントがどのように見えるんか? – jeremyharris

答えて

0

getMock()setMethods()と嘲笑のメソッドを指定します。

$authComponent = $this 
    ->getMockBuilder(App\Controller\Component\AuthorizationComponent::class) 
    ->setMethods(['isAuthorized']) 
    ->getMock(); 
関連する問題