Example #1
0
 public function testAddException()
 {
     $entry = new Entry(self::FAKE_ID);
     $entry->addException('exception #1');
     $entry->addException('exception #2');
     $this->assertEquals(2, count($entry->getExceptions()));
 }
Example #2
0
 /**
  * Saves report to a file.
  *
  * @param Entry $entry
  * @throws ReportException
  */
 public function save(Entry $entry)
 {
     $content = sprintf("User: %s", $entry->getId());
     $messages = $this->createMessageReport($entry->getMessages());
     $exceptions = $this->createExceptionReport($entry->getExceptions());
     $content .= PHP_EOL . $messages . PHP_EOL . $exceptions;
     $this->saveToFile($content);
 }
Example #3
0
 public function add(Entry $entry)
 {
     $rowCount = 0;
     if ($entry->getId()) {
         ++$rowCount;
         foreach ($entry->getMessages() as $message) {
             ++$rowCount;
         }
     }
     self::$added = $rowCount;
     self::$entry = $entry;
 }
Example #4
0
 /**
  * Adds an Entry object to the database. Entry object contains User and Messages data.
  *
  * @param Entry $entry
  * @return int
  * @throws \DataAggregator\Store\StoreException
  */
 public function add(Entry $entry)
 {
     $this->pdo->beginTransaction();
     $stmt = $this->pdo->prepare(sprintf("INSERT INTO %s (provider_id) VALUES(:provider_id)", self::TABLE_USER));
     $stmt->bindValue(':provider_id', $entry->getId(), \PDO::PARAM_STR);
     $rowCount = 0;
     try {
         $stmt->execute();
         $userId = $this->pdo->lastInsertId();
         $rowCount += $this->prepareMultiInsert($userId, $entry->getMessages());
         $this->pdo->commit();
     } catch (\PDOException $ex) {
         $this->pdo->rollBack();
         throw new StoreException($ex->getMessage());
     }
     $rowCount += $stmt->rowCount();
     return $rowCount;
 }
 /**
  * @test
  */
 public function addEntry()
 {
     $entry = new Entry(self::FACEBOOK_ID);
     // 1 row
     $entry->addMessage(1, 'Message #1');
     // 2 rows
     $entry->addMessage(2, 'Message #2');
     // 3 rows
     $entry->addMessage(3, 'Message #3');
     // 4 rows
     $entry->addMessage(4, 'Message #4');
     // 5 rows
     $config = ['db' => self::DB, 'host' => self::HOST, 'user' => self::USER, 'password' => self::PASSWORD];
     $store = new MySqlStore($config);
     $store->connect();
     $this->assertEquals(5, $store->add($entry));
 }
 public function createExceptionReport()
 {
     $report = new TextReport($this->path);
     $messages = $this->invokeMethod($report, 'createExceptionReport', [$this->entry->getExceptions()]);
     $this->assertNotNull($messages);
 }