유도가있는 LARAVLES Facades 테스트가 항상 실패 할 때도 항상 통과합니다.

StackOverflow https://stackoverflow.com//questions/24028829

문제

유닛 테스트 중에 LARAVLE에서 일부 정면을 조롱하려고하지만 테스트가 항상 상관없이 항상 통과하는 것 같습니다.

예를 들어,이 예제는 여기에있는 LARAVLE 문서에서 가져온 것입니다.

Event::shouldReceive('fire')->once()->with('foo', array('name' => 'Dayle'));
.

테스트 방법 중 하나에 넣을 수 있으며 항상 종류가 Event 외관으로 수행되지 않은 경우에도 항상 통과합니다.

여기에 테스트 클래스가 있습니다.

class SessionsControllerTest
extends TestCase
{    
    public function test_invalid_login_returns_to_login_page()
    {
        // All of these pass even when they should fail
        Notification::shouldReceive('error')->once()->with('Incorrect email or password.');
        Event::shouldReceive('fire')->once()->with('foo', array('name' => 'Dayle'));
        Notification::shouldReceive('nonsense')->once()->with('nonsense');

        // Make login attempt with bad credentials
        $this->post(action('SessionsController@postLogin'), [
            'inputEmail'     => 'bademail@example.com',
            'inputPassword'  => 'badpassword'
        ]);

        // Should redirect back to login form with old input
        $this->assertHasOldInput();
        $this->assertRedirectedToAction('SessionsController@getLogin');
    }

}
.

facades를 테스트하기 위해 누락 된 것은 무엇입니까?나는 설치없이 Laravel Facade에서 shouldReceive()를 호출 할 수 있어야한다고 생각하는 것입니다.

도움이 되었습니까?

해결책

조롱을 알아야 할 조각을 알아야합니다.당신은

을 넣어 그것을 할 수 있습니다.
\Mockery::close();
.

테스트 방법이 끝나거나 테스트 클래스의 티어 다운 방법에서

또는 phpunit.xml

에 이것을 추가하여 조롱의 phpunit 통합을 설정할 수 있습니다.
<listeners>
  <listener class="\Mockery\Adapter\Phpunit\TestListener"></listener>
</listeners>
.

http://docs.mockery.io/en/latest/reference/phpunit_integration.html <./ A> 자세한 내용은

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top