mercredi 30 août 2017

Mocks vs Stubs in PHPUnit

I know stubs verify state and the monks verify behavior

How can I make a mock in PHPUnit to verify the behavior of the methods? Phpunit does not have verification methods (verify()), And I do not know how to make a moks is PHPUnit.

In the documentation, to create a stub is well explained:

    // Create a stub for the SomeClass class.
    $stub = $this->createMock(SomeClass::class);

    // Configure the stub.
    $stub->method('doSomething')
         ->willReturn('foo');

    // Calling $stub->doSomething() will now return 'foo'.
    $this->assertEquals('foo', $stub->doSomething());

But in this case, I am verifying status, saying that return an answer.

How would be the example to create a mock and verify behavior?

Aucun commentaire:

Enregistrer un commentaire