PHPUnit: Wrong practice of using multiple statements for mocking methods in one test?

I am testing an object that is intended to be tested if the user owns this email. Therefore, when the "tryEmail" method is called, it sends a message with a confirmation link to the specified email address. My test is as follows:

public function testSendingWasSuccessful() {

    $confirmationObject = $this->getMock('LT\EmailConfirmation\Model\ConfirmationObjectInterface');

    $testType = 'test.type';
    $testEmail = 'test@example.com';
    $testData = [];

    // EmailTester should create a new confirmation object.
    $this->manager->expects(static::once())
        ->method('create')->with($testType, $testEmail)
        ->willReturn($confirmationObject);

    // Then it should send the confirmation message.
    $this->mailer->expects(static::once())
        ->method('send')->with(static::identicalTo($confirmationObject))
        ->willReturn(true);

    // And save the confirmation object.
    $this->manager->expects(static::once())
        ->method('save')->with(static::identicalTo($confirmationObject));

    $tester = new EmailTester($this->repository, $this->manager, $this->confirmationHandler, $this->mailer);

    static::assertTrue($tester->tryEmail($testType, $testEmail, $testData));
}

, , , - . ? . , , , , "tryEmail" .

, tryEmail . , , , , , . , , . : static::identicalTo($confirmationObject), : check if the object passed to the mailer is the same as the one created before. , EmailTester, , - . - ? , , ?

? ? ?

: - , ( )? , , . , . ?

+4
1

" " , . .

- . , , , .

, . , , - , , , , . , , .

, , , , . , , . LT\EmailConfirmation\Model\ConfirmationObjectInterface . .

, , , .

+1

Source: https://habr.com/ru/post/1648219/


All Articles