Example #1
0
 public function testSlug()
 {
     $project = new Project('Twig Local');
     $this->assertEquals('twig-local', $project->getSlug());
     $project->setSlug('twig-local-my-slug');
     $this->assertEquals('twig-local-my-slug', $project->getSlug());
 }
Example #2
0
 public function updateProject(Project $project)
 {
     $stmt = $this->db->prepare('INSERT OR REPLACE INTO project (slug, name, repository, branch, command, url_pattern) VALUES (:slug, :name, :repository, :branch, :command, :url_pattern)');
     $stmt->bindValue(':slug', $project->getSlug(), SQLITE3_TEXT);
     $stmt->bindValue(':name', $project->getName(), SQLITE3_TEXT);
     $stmt->bindValue(':repository', $project->getRepository(), SQLITE3_TEXT);
     $stmt->bindValue(':branch', $project->getBranch(), SQLITE3_TEXT);
     $stmt->bindValue(':command', $project->getCommand(), SQLITE3_TEXT);
     $stmt->bindValue(':url_pattern', $project->getUrlPattern(), SQLITE3_TEXT);
     if (false === $stmt->execute()) {
         // @codeCoverageIgnoreStart
         throw new \RuntimeException(sprintf('Unable to save project "%s".', $project->getName()));
         // @codeCoverageIgnoreEnd
     }
     // related commits
     $stmt = $this->db->prepare('SELECT sha, author, date, build_date, message, status, output FROM `commit` WHERE slug = :slug ORDER BY build_date DESC LIMIT 100');
     $stmt->bindValue(':slug', $project->getSlug(), SQLITE3_TEXT);
     if (false === ($results = $stmt->execute())) {
         // @codeCoverageIgnoreStart
         throw new \RuntimeException(sprintf('Unable to get latest commit for project "%s".', $project->getName()));
         // @codeCoverageIgnoreEnd
     }
     $commits = array();
     while ($result = $results->fetchArray(\SQLITE3_ASSOC)) {
         $commits[] = $this->createCommit($project, $result);
     }
     $project->setCommits($commits);
     // project building?
     $stmt = $this->db->prepare('SELECT COUNT(*) AS count FROM `commit` WHERE slug = :slug AND status = "building"');
     $stmt->bindValue(':slug', $project->getSlug(), SQLITE3_TEXT);
     $building = false;
     if (false !== ($result = $stmt->execute())) {
         if (false !== ($result = $result->fetchArray(\SQLITE3_ASSOC))) {
             if ($result['count'] > 0) {
                 $building = true;
             }
         }
     }
     $project->setBuilding($building);
 }
Example #3
0
 public function testConstructor()
 {
     $project = new Project('Twig Local');
     $this->assertEquals('Twig Local', $project->getName());
     $this->assertEquals('twig-local', $project->getSlug());
     $this->assertEquals('master', $project->getBranch());
     $this->assertEquals(array(), $project->getNotifiers());
     $project = new Project('Twig Local', 'repo', array(), 'twig');
     $this->assertEquals('twig', $project->getSlug());
     $this->assertEquals(array(), $project->getNotifiers());
     $project = new Project('Twig Local', 'repo');
     $this->assertEquals('repo', $project->getRepository());
     $this->assertEquals('master', $project->getBranch());
     $project = new Project('Twig Local', 'repo@feat');
     $this->assertEquals('repo', $project->getRepository());
     $this->assertEquals('feat', $project->getBranch());
     $project = new Project('Twig Local', 'repo', array($notifier1 = $this->getMock('Sismo\\Notifier'), $notifier2 = $this->getMock('Sismo\\Notifier')));
     $this->assertSame(array($notifier1, $notifier2), $project->getNotifiers());
 }
Example #4
0
 /**
  * Create or update the information of a project.
  *
  * If the project is already available, the information of the existing project will be updated.
  *
  * @param Project $project The project to create or update.
  *
  * @return StorageInterface $this
  */
 public function updateProject(Project $project)
 {
     $stmt = $this->db->prepare('SELECT COUNT(*) FROM project WHERE slug = :slug');
     $stmt->bindValue(':slug', $project->getSlug(), \PDO::PARAM_STR);
     if (false === $stmt->execute()) {
         // @codeCoverageIgnoreStart
         throw new \RuntimeException(sprintf('Unable to verify existence of project "%s".', $project->getName()));
         // @codeCoverageIgnoreEnd
     }
     if ($stmt->fetchColumn(0)) {
         $stmt = $this->db->prepare('UPDATE project SET slug = :slug, name = :name, repository = :repository, branch = :branch, command = :command, url_pattern = :url_pattern WHERE slug = :slug');
     } else {
         $stmt = $this->db->prepare('INSERT INTO project (slug, name, repository, branch, command, url_pattern) VALUES (:slug, :name, :repository, :branch, :command, :url_pattern)');
     }
     $stmt->bindValue(':slug', $project->getSlug(), \PDO::PARAM_STR);
     $stmt->bindValue(':name', $project->getName(), \PDO::PARAM_STR);
     $stmt->bindValue(':repository', $project->getRepository(), \PDO::PARAM_STR);
     $stmt->bindValue(':branch', $project->getBranch(), \PDO::PARAM_STR);
     $stmt->bindValue(':command', $project->getCommand(), \PDO::PARAM_STR);
     $stmt->bindValue(':url_pattern', $project->getUrlPattern(), \PDO::PARAM_STR);
     if (false === $stmt->execute()) {
         // @codeCoverageIgnoreStart
         throw new \RuntimeException(sprintf('Unable to save project "%s".', $project->getName()));
         // @codeCoverageIgnoreEnd
     }
     // related commits
     $stmt = $this->db->prepare('SELECT sha, author, date, build_date, message, status, output FROM `commit` WHERE slug = :slug ORDER BY `status` = "building" DESC, build_date DESC LIMIT 100');
     $stmt->bindValue(':slug', $project->getSlug(), \PDO::PARAM_STR);
     if (false === $stmt->execute()) {
         // @codeCoverageIgnoreStart
         throw new \RuntimeException(sprintf('Unable to get latest commit for project "%s".', $project->getName()));
         // @codeCoverageIgnoreEnd
     }
     $commits = array();
     while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         $commits[] = $this->createCommit($project, $result);
     }
     $project->setCommits($commits);
     // project building?
     $stmt = $this->db->prepare('SELECT COUNT(*) AS count FROM `commit` WHERE slug = :slug AND status = "building"');
     $stmt->bindValue(':slug', $project->getSlug(), \PDO::PARAM_STR);
     $building = false;
     if ($stmt->execute() and intval($stmt->fetchColumn(0))) {
         $building = true;
     }
     $project->setBuilding($building);
 }