public function testUpdatingEntry() { $this->assertEquals(2, $this->getConnection()->getRowCount('cfp'), "Pre-Condition"); $cpl = new CfpPersistenceLayer($this->pdo); $cfp = new Cfp(); $cfp->setEventUri('http://example.com'); $newHash = $cpl->update($cfp, 'ff'); $this->assertEquals(sha1('http://example.com'), $newHash); $this->assertEquals(2, $this->getConnection()->getRowCount('cfp'), "Post-Condition"); $results = $cpl->select(sha1('http://example.com')); $this->assertEquals(1, $results->count()); }
public function select($hash = null) { $statement = 'SELECT * FROM `cfp`'; $values = []; if ($hash !== null) { $statement .= ' WHERE `hash`= :hash'; $values['hash'] = $hash; } $statement = $this->pdo->prepare($statement); $list = new \Callingallpapers\Api\Entity\CfpList(); $statement->execute($values); $content = $statement->fetchAll(); if (count($content) < 1) { throw new \UnexpectedValueException('No CFPs found', 404); } foreach ($content as $item) { $cfp = new \Callingallpapers\Api\Entity\Cfp(); $cfp->setName($item['name']); $cfp->setDateCfpEnd(new \DateTimeImmutable($item['dateCfpEnd'])); $cfp->setDateCfpStart(new \DateTimeImmutable($item['dateCfpStart'])); $cfp->setUri($item['uri']); $cfp->setTimezone(new \DateTimeZone($item['timezone'])); $cfp->setDateEventStart(new \DateTimeImmutable($item['dateEventStart'])); $cfp->setDateEventEnd(new \DateTimeImmutable($item['dateEventEnd'])); $cfp->setDescription($item['description']); $cfp->setEventUri($item['eventUri']); $cfp->setIconUri($item['iconUri']); $cfp->setLatitude($item['latitude']); $cfp->setLongitude($item['longitude']); $cfp->setLocation($item['location']); $cfp->setTags(explode(',', $item['tags'])); $cfp->setLastUpdated(new \DateTimeImmutable($item['lastUpdate'])); $list->add($cfp); } return $list; }
public static function setEventUri(Cfp $cfp, array $array) { if (!isset($array['eventUri'])) { throw new \InvalidArgumentException('Event-URI has to be specified'); } $cfp->setEventUri(filter_var($array['eventUri'], FILTER_VALIDATE_URL)); }