public function removeById(Uuid $id) { foreach ($this->users as $i => $user) { /** @var \Notes\Domain\Entity\User $user*/ if ($user->getId()->__toString() === $id->__toString()) { unset($this->users[$i]); return true; } } return false; }
* Time: 11:29 PM */ use Notes\Domain\Entity\UserGroup\Admin; use Notes\Domain\ValueObject\Uuid; use Notes\Domain\Entity\User; use Notes\Domain\ValueObject\StringLiteral; use Notes\Domain\Entity\Roles\AdminRole; describe('Notes\\Domain\\Entity\\Roles\\AdminRole', function () { describe('->__construct()', function () { it('should return a Admin object', function () { $actual = new AdminRole(); expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\Roles\\AdminRole'); }); }); // this tests what exists of this class atm im not sure if i will have to add the other methods to it later or if im on the right track describe('->__construct(params)', function () { it('should return a AdminRole object', function () { $roleID = new Uuid(); $name = "Full admins"; $createPermission = true; $deletePermission = true; $permissions = array("Can Create" => $createPermission, "Can Delete" => $deletePermission); $actual = new AdminRole($roleID, $name, $createPermission, $deletePermission); expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\Roles\\AdminRole'); expect($actual->getID())->equal($roleID->__toString()); expect($actual->getPermissions())->equal($permissions); expect($actual->getName())->equal($name); }); }); }); // end tests
* $LastChangedDate$ * $LastChangedBy$ */ use Notes\Domain\Entity\User; use Notes\Domain\ValueObject\StringLiteral; use Notes\Domain\ValueObject\Uuid; describe('Notes\\Domain\\Entity\\User', function () { describe('->__construct()', function () { it('should return a User object', function () { $actual = new User(new Uuid()); expect($actual)->to->be->instanceof('\\Notes\\Domain\\Entity\\User'); }); }); describe('->getId()', function () { it('should return the user\'s username', function () { $uuid = new Uuid(); expect($uuid->isValidV4())->to->be->true(); $user = new User($uuid); $actual = $user->getId(); expect($actual)->to->be->instanceof('\\Notes\\Domain\\ValueObject\\Uuid'); expect($actual->__toString())->equal($uuid->__toString()); }); }); describe('->get/setUsername', function () { it('should get/set the correct the user\'s username', function () { $user = new User(new Uuid()); $user->setUsername(new StringLiteral('Joe')); $actual = $user->getUsername(); expect($actual)->to->be->instanceof('\\Notes\\Domain\\ValueObject\\StringLiteral'); expect($actual->__toString())->equal('Joe'); });
<?php use Notes\Domain\ValueObject\Uuid; describe('ValueObject\\Uuid', function () { describe('->__construct()', function () { it('should return a Uuid object', function () { $actual = new Uuid(); expect($actual)->to->be->instanceof('Notes\\Domain\\ValueObject\\Uuid'); }); }); describe('->__toString()', function () { it('should return a valid V4 UUID identifier', function () { $actual = new Uuid(); $uuid = $actual->__toString(); expect(is_string($uuid))->true(); expect(preg_match('/[a-f0-9]{8}\\-[a-f0-9]{4}\\-4[a-f0-9]{3}\\-(8|9|a|b)[a-f0-9]{3}\\-[a-f0-9]{12}/', $uuid))->equal(1); }); }); });
*/ use Notes\Domain\Entity\UserGroup\Owner; use Notes\Domain\ValueObject\Uuid; use Notes\Domain\Entity\User; use Notes\Domain\ValueObject\StringLiteral; describe('Notes\\Domain\\Entity\\UserGroup\\Owner', function () { describe('->__construct()', function () { it('should return a owner object', function () { $actual = new Owner(); expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\UserGroup\\owner'); }); }); // i shall be testing the usergroupinterface functions here describe('->__construct("cs3620", "an array with user objects", true)', function () { it('should return a owner object that is initialized with a name and 2 initial user objects and should be able to create new notes', function () { $groupID = new Uuid(); $username = "******"; $password = "******"; $email = "*****@*****.**"; $firstName = "Gary"; $lastName = "Grice"; $user1 = new User(new Uuid(), $username, $password, $email, $firstName, $lastName); $username1 = "TheWorldsGreatest"; $password2 = "Imadeit12@"; $email3 = "*****@*****.**"; $firstName4 = "Robert"; $lastName5 = "Kelly"; $user2 = new User(new Uuid(), $username1, $password2, $email3, $firstName4, $lastName5); $user1Key = $user1->getUserID(); $user2Key = $user2->getUserID(); $initialUsers = array($user1Key => $user1, $user2Key => $user2);
* $LastChangedDate$ * $LastChangedBy$ */ use Notes\Domain\Entity\User; use Notes\Domain\ValueObject\StringLiteral; use Notes\Domain\ValueObject\Uuid; describe('Notes\\Domain\\Entity\\User', function () { describe('->__construct()', function () { it('should return a User object', function () { $actual = new User(new Uuid()); expect($actual)->to->be->instanceof('\\Notes\\Domain\\Entity\\User'); }); }); describe('->getId()', function () { it('should return the user\'s ID', function () { $uuid = new Uuid(); $user = new User($uuid); $actual = $user->getId(); expect($actual)->to->be->instanceof('Notes\\Domain\\ValueObject\\Uuid'); expect($actual->__toString())->equal($uuid->__toString()); }); }); describe('->getUsername()', function () { it('should return the user\'s username', function () { $user = new User(new Uuid()); $user->setUsername(new StringLiteral('joe')); $actual = $user->getUsername(); expect($actual)->to->be->instanceof('Notes\\Domain\\ValueObject\\StringLiteral'); expect($actual->__toString())->equal('joe'); }); });
/** * @param \Notes\Domain\ValueObject\Uuid $id * @return bool */ public function removeById(Uuid $id) { $userID = $id->__toString(); $query = "DELETE FROM USERS WHERE UserID = '{$userID}'"; mysql_query($query); return $this; }
* Date: 11/3/15 * Time: 7:12 PM */ use Notes\Domain\Entity\User; use Notes\Domain\ValueObject\Uuid; describe('Notes\\Domain\\Entity\\User', function () { describe('->__construct()', function () { it('should return a User object', function () { $actual = new User(); expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\User'); }); }); //tests to see if correct values are initialized and input describe('->construct("Swagzilla", "Yeezy2020!", "*****@*****.**", "Gary", "Grice")', function () { it('should return a User object instantiated with username Swagzilla, email swagzillablaze@gmail.com, password Yeezy2020, First name Gary, and last name Grice, password hashed', function () { $userID = new Uuid(); $username = "******"; $password = "******"; $email = "*****@*****.**"; $firstName = "Gary"; $lastName = "Grice"; $actual = new User($userID, $username, $password, $email, $firstName, $lastName); expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\User'); expect($actual->getUsername())->equal($username); expect($actual->getEmail())->equal($email); $hashpass = hash(sha256, $password); // the costructor will hash the password im not adding a random salt at this point so it will be easier to implement and test expect($actual->getPassword())->equal($password); expect($actual->getFirstName())->equal($firstName); expect($actual->getLastName())->equal($lastName); expect($actual->getUserID())->equal($userID->__toString());
/** * @param Uuid $uuid * @return User|\PDOStatement */ public function GetUser(Uuid $uuid) { $sql = 'SELECT * FROM user WHERE uuid = :uuid'; $sth = $this->conn->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY)); $sth->execute(array(':uuid' => $uuid->__toString())); foreach ($sth as $row) { return $this->generateUserFromRow($row); } }
/** * @param Uuid $uuid * @return boolean */ public function removeById(Uuid $uuid) { /** @var User $user */ foreach ($this->users as $i => $user) { if ($user->getId()->__toString() === $uuid->__toString()) { unset($this->users[$i]); return true; } } return false; }
public function removeById(Uuid $id) { $results = []; foreach ($this->users as $i => $user) { if ($user->getId()->__toString() === $id->__toString()) { unset($this->users[$i]); return true; } } return false; }