/** * Check that a Username is unique * * @param Username $username * @throws ValueIsNotUniqueException * @return void */ private function checkUsernameIsUnique(Username $username) { $specification = new UsernameIsUnique($this->userRepository); if (!$specification->isSatisfiedBy($username)) { throw new ValueIsNotUniqueException("{$username} has already been taken"); } }
/** @test */ public function should_return_false_when_not_unique() { $this->repository->shouldReceive('userOfUsername')->andReturn(['id' => 1]); $this->assertFalse($this->spec->isSatisfiedBy(new Username('philipbrown'))); }