samedi 27 juin 2015

Testing command handler with phpspec

Lately I'm giving a try to phpspec. It works great, but I have got a problem with testing command handlers. For example in PHPUnit I test it that way:

/**
 * @test
 */
public function it_should_change_an_email()
{
    $this->repository->add($this->employee);

    $this->handler->changeEmail(
        new ChangeEmailCommand(
            $this->employee->username()->username(),
            'new@email.com'
        )
    );

    Asserts::assertEquals(new Email('new@email.com'), $this->employee->email());
}

and setup:

protected function setUp()
{
    $this->repository = new InMemoryEmployeeRepository();
    $this->createEmployee();

    $this->handler = new EmployeeCommandHandler($this->repository);
}

The main point is that this test make assertions on the Employee object to check if CommandHandler is working good. But in phpspec I can't make assertion on different object than the specifying one, in this case I can only make assertion on my CommandHandler. So how I can test a command handler in phpspec?

Aucun commentaire:

Enregistrer un commentaire