예제 #1
0
 public static function createBook(ParameterBag $bookParametrBag)
 {
     $book = new Book();
     $messages = array();
     $title = $bookParametrBag->get("title");
     if (empty($title)) {
         $messages["title_error"] = "Title should not be blank";
     } else {
         $book->title = $title;
     }
     $author = $bookParametrBag->get("author");
     if (empty($author)) {
         $messages["author_error"] = "Author should not be blank";
     } else {
         $book->author = $author;
     }
     $dateOfReading = $bookParametrBag->get("dateOfReading");
     if (empty($dateOfReading)) {
         $messages["dateOfReading_error"] = "Date of reading should not be blank";
     } elseif (!Utils::validateDate($dateOfReading)) {
         $messages["dateOfReading_error"] = "Date shold be formated as 'd-m-Y'. Your date is " . $dateOfReading;
     } else {
         $book->dateOfReading = \DateTime::createFromFormat('d-m-Y', $dateOfReading);
     }
     if (count($messages) > 0) {
         return $messages;
     } else {
         return $book;
     }
 }
예제 #2
0
 /**
  * @dataProvider casesProvider
  */
 public function testCommand($country, $startDate, $endDate, $sqlImports, $sqlExport, $testLocation)
 {
     $specs_file = $testLocation . 'specs.yml';
     $database_name = $country . "db";
     $this->database_name = $database_name;
     $options = array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION);
     $this->db_connection = self::$connection_factory->createConnection(array('pdo' => new \PDO(sprintf("mysql:host=%s;dbname={$database_name}", self::$database_host), self::$database_user, self::$database_password, $options)));
     $this->importData($sqlImports, $database_name, __DIR__ . '/tests_config/db/');
     fwrite(STDOUT, "Testing command\n");
     self::$commandTester->execute(array('command' => self::$command->getName(), 'country_code' => $country, 'specs_file' => $specs_file, '--startDate' => $startDate, '--endDate' => $endDate, '--fake_mo' => true));
     $commandDisplay = self::$commandTester->getDisplay();
     $commandResults = Utils::get_string_between($commandDisplay, "[RESULTS]", "[/RESULTS]");
     //Connect with mysqli since PDO does not support multi query.
     $mysqli = new mysqli(self::$database_host, self::$database_user, self::$database_password, $database_name);
     if (mysqli_connect_errno()) {
         fwrite(STDOUT, sprintf("Connect failed: %s\n", mysqli_connect_error()));
         return;
     }
     $cntRes = 0;
     $sqlFile = file_get_contents($testLocation . "/{$sqlExport}");
     //assert combinations match
     if ($mysqli->multi_query($sqlFile)) {
         do {
             /* store first result set */
             if ($result = $mysqli->store_result()) {
                 while ($row = $result->fetch_assoc()) {
                     $toSearch = sprintf('Mphone_ServiceID: %s %s', $row["Mphone"], $row["ServiceID"]);
                     $this->assertContains($toSearch, $commandResults);
                     $cntRes++;
                 }
                 $result->free();
             }
         } while ($mysqli->next_result());
     }
     //Assert same number of rows
     $this->assertContains("Total unsub: {$cntRes}", $commandDisplay);
     //fwrite(STDOUT, "Total unsub: $cntRes \n");
     $mysqli->close();
     //Clean the database (truncate all tables)
     $this->emptyDatabase($database_name);
 }