/** * @param string $value * @throws InvalidArgumentExpection */ public function __construct($value = StringLiteral::EMPTY_STR) { parent::__construct($value); if (empty($this->value)) { $this->generateV4(); } if (!$this->isValidV4()) { throw new InvalidArgumentExpection(__METHOD__ . '(): $value is not a valid v4 uuid'); } }
public function __construct($value = '') { parent::__construct($value); if (empty($this->value)) { $this->generateV4(); } if (!$this->isValidV4()) { throw new InvalidArgumentException(__METHOD__ . '(): $value must be a valid V4 UUID'); } }
public function __construct($value = StringLiteral::EMPTY_STR) { //must use this to call the constructor parent::__construct($value); if (empty($this->value)) { $this->generateV4(); } if (!$this->isValidV4()) { throw new InvalidArgumentException(__METHOD__ . '(): $value is not a valid v4 UUID'); } }
$actual = new StringLiteral($value); expect($actual)->to->be->instanceof('Notes\\Domain\\ValueObject\\StringLiteral'); expect($actual->__toString())->equal($value); }); }); describe('->__construct(123)', function () { it('should return an InvalidArgumentException', function () { $value = 123; $exception = null; try { new StringLiteral($value); } catch (Exception $e) { $exception = $e; } expect($exception)->to->be->instanceof('\\InvalidArgumentException'); }); }); describe('->__toString()', function () { it('should return the default value of StringLiteral', function () { $actual = new StringLiteral(); expect($actual->__toString())->equal(''); expect($actual->__toString())->empty(); }); it('should return "foo"', function () { $value = 'foo'; $actual = new StringLiteral($value); expect($actual)->to->be->instanceof('Notes\\Domain\\ValueObject\\StringLiteral'); expect($actual->__toString())->equal($value); }); }); });
<?php use Notes\Domain\ValueObject\StringLiteral; describe('StringLiteral', function () { describe('->__construct()', function () { it('should return a StringLiteral object', function () { $actual = new StringLiteral(); expect($actual)->to->be->instanceof('ValueObject\\StringLiteral'); }); }); describe('->__construct("foo")', function () { it('should return a StringLeteral object with the value of "foo"', function () { $value = 'foo'; $actual = new StringLiteral($value); expect($actual)->to->be->instanceof('ValueObject\\StringLiteral'); expect($actual->__toString())->equal($value); }); }); describe('->__toString()', function () { it('should return the default', function () { $actual = new StringLiteral(); expect($actual->__toString())->equal(''); }); it('should return "foo"', function () { $value = 'foo'; $actual = new StringLiteral($value); expect($actual->__toString())->equal($value); }); }); });
it('should return the user\'s system generated uuid', function () { $faker = \Faker\Factory::create(); $uuid = new Uuid(); expect($uuid->isValidV4())->to->be->true(); $username = new StringLiteral($faker->userName); $user = new User($uuid, $username); $actual = $user->getId(); expect($actual)->to->be->instanceof('Notes\\Domain\\ValueObject\\Uuid'); expect($actual->__toString())->equal($uuid->__toString()); }); }); describe('->getUsername()', function () { it('should get the correct username', function () { $faker = \Faker\Factory::create(); $uuid = new Uuid(); $userName = new StringLiteral($faker->userName); $user = new User($uuid, $userName); $actual = $user->getUsername(); expect($actual)->to->be->instanceof('Notes\\Domain\\ValueObject\\StringLiteral'); expect($actual->__toString())->equal($userName->__toString()); }); }); describe('->get/setEmail()', function () { it('should set & get the correct email', function () { $faker = \Faker\Factory::create(); $uuid = new Uuid(); $userName = new StringLiteral($faker->userName); $user = new User($uuid, $userName); $email = new StringLiteral($faker->email); $user->setEmail($email); $actual = $user->getEmail();