$faker = \Faker\Factory::create(); $firstName = new StringLiteral($faker->firstName); $lastName = new StringLiteral($faker->lastName); $email = new StringLiteral($faker->email); $user = new User($firstName, $lastName, $email); expect($user)->to->be->instanceof('Notes\\Domain\\Entity\\User'); }); }); describe('-->__toString()', function () { it('should return string "firstname lastname"', function () { $faker = \Faker\Factory::create(); $firstName = new StringLiteral($faker->firstName); $lastName = new StringLiteral($faker->lastName); $email = new StringLiteral($faker->email); $user = new User($firstName, $lastName, $email); expect(is_string($user->__toString())); }); }); describe('->__getId()', function () { it('should return a value V4 UUID identifier', function () { $id = new Uuid(); expect($id->isValidV4())->to->be->true(); $faker = \Faker\Factory::create(); $firstName = new StringLiteral($faker->firstName); $lastName = new StringLiteral($faker->lastName); $email = new StringLiteral($faker->email); $user = new User($id, $firstName, $lastName, $email); $actual = $user->getId(); expect($actual)->to->be->instanceof('Notes\\Domain\\ValueObject\\Uuid'); expect($actual->__toString())->equal($id->__toString()); });
/** * @param \Notes\Domain\Entity\User $search * @param \Notes\Domain\Entity\User $newUser */ public function modify(User $search, User $newUser) { $results = []; foreach ($this->users as $user) { /** @var \Notes\Domain\Entity\User $userToGet */ if ($user->__toString() === $search->__toString()) { $results[] = $user; } } if ($this->count() == 1) { $results[0]->setFirstName($newUser->getFirstName()); $results[0]->setLastName($newUser->getLastName()); } foreach ($results as $user) { $user->setFirstName($newUser->getFirstName()); $user->setLastName($newUser->getLastName()); } }
use Notes\Domain\ValueObject\StringLiteral; describe('Notes\\Domain\\Entity\\User', function () { describe('->__construct()', function () { it('should return a User object', function () { $faker = \Faker\Factory::create(); $uuid = new StringLiteral($faker->uuid); $actual = new User($uuid); expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\User'); }); }); describe('->__toString()', function () { it('should return a string with user information', function () { $faker = \Faker\Factory::create(); $uuid = new StringLiteral($faker->uuid); $actual = new User($uuid); expect(is_string($actual->__toString()))->equal(true); }); }); describe('->getId()', function () { it('should return the User\'s id', function () { $userFactory = new UserFactory(); $faker = \Faker\Factory::create(); $uuid = new StringLiteral($faker->uuid); $actual = new User($uuid); $actual = $userFactory->create(); expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\User'); expect($actual->getId())->to->be->instanceof('Notes\\Domain\\ValueObject\\Uuid'); }); }); describe('->getUsername()', function () { it('should return the User\'s username', function () {