/** * Creates a data object from an array of values (database namings). * * @param array $data * * @return Run */ public function fromDatabaseArray(array $data) { $run = new Run(); $run->setRunId($data['run_id'] ?? null); $run->setTsAccessed($data['ts_accessed'] ?? null); $run->setTsCreated($data['ts_created'] ?? null); return $run; }
public function testPersistNewRun() { $repository = new RunRepository(); $run = new Run(); $run->setRunId(self::$testRunIdNew); $repository->persist($run); $dbRun = $repository->retrieve($run->getRunId()); $this->assertEquals($run->getRunId(), $dbRun->getRunId()); $this->assertNotNull($dbRun->getTsAccessed()); $this->assertNotNull($dbRun->getTsCreated()); }
/** * Stores a run object to the database. * * @param Run $run * * @throws InvalidArgumentException */ public function persist(Run $run) { if (empty($run->getRunId())) { throw new \InvalidArgumentException('missing run id'); } $conn = $this->database->getConnection(); $stmt = $conn->prepare('REPLACE INTO runs (run_id, ts_created, ts_accessed)' . ' VALUES (:run_id, :ts_created, :ts_accessed)'); $now = time(); $stmt->bindValue(':run_id', $run->getRunId()); $stmt->bindValue(':ts_accessed', $now); $stmt->bindValue(':ts_created', $run->getTsCreated() ?? $now); $stmt->execute(); }
/** * Creates a mock run. * * @param string $runId * @return Run */ private function mockRun($runId) { $run = new Run(); $run->setRunId($runId); return $run; }