/** * @test */ public function it_should_generate_a_short_uuid4() { $shortUuid = ShortUuid::uuid4(); $this->assertEquals(22, strlen($shortUuid)); }
/** * create dependent objects before running each test * */ public function setUp() { //run the default setUp() method first parent::setUp(); $this->VALID_TRAILUUID = ShortUuid::uuid4(); // var_dump($this->VALID_TRAILUUID); //create and insert a datetime object $this->VALID_CREATEDATE = DateTime::createFromFormat("Y-m-d H:i:s", $this->VALID_CREATEDATE); //create browser $this->VALID_BROWSER = "Safari"; $this->VALID_USERSALT = bin2hex(openssl_random_pseudo_bytes(32)); $this->VALID_USERHASH = $this->VALID_USERHASH = hash_pbkdf2("sha512", "password4321", $this->VALID_USERSALT, 262144, 128); //create and insert a userId to own the trail $this->user = new User(null, $this->VALID_BROWSER, $this->VALID_CREATEDATE, "192.168.1.168", "S", "*****@*****.**", $this->VALID_USERHASH, "Hyourname.tomorrow", $this->VALID_USERSALT); $this->user->insert($this->getPDO()); }
/** * mutator method for trailUuid * @param string $newTrailUuid value given for trail submissions * @throws InvalidArgumentException if $newTrailUuid is not a string or insecure * @throws RangeException If $newTrailUuid is not equal to 22 characters **/ public function setTrailUuid($newTrailUuid) { // base case if trail uuid is null, this is a new trail submission if ($newTrailUuid === null) { $this->trailUuid = null; return; } // base case if a new UUID is requested, make one if ($newTrailUuid === "CREATE-NEW-UUID") { $this->trailUuid = ShortUuid::uuid4(); return; } // verify the trail UUID is valid $newTrailUuid = trim($newTrailUuid); $newTrailUuid = trim($newTrailUuid); $newTrailUuid = filter_var($newTrailUuid, FILTER_SANITIZE_STRING); if ($newTrailUuid === false) { throw new InvalidArgumentException("uuid is empty of insecure"); } if (strlen($newTrailUuid) === 36) { // encode trail uuid to short form $uuid = Uuid::fromString($newTrailUuid); $shortUuid = new ShortUuid(); $this->trailUuid = $shortUuid->encode($uuid); } else { if (strlen($newTrailUuid) === 22) { $this->trailUuid = $newTrailUuid; } else { // throw an Range Exception throw new RangeException("trail uuid is not the correct length for the data base"); } } }
/** * @test */ public function it_should_generate_a_short_uuid4() { $shortUuid = ShortUuid::uuid4(); $this->assertLessThanOrEqual(22, strlen($shortUuid)); $this->assertGreaterThanOrEqual(21, strlen($shortUuid)); }