public function testIncorrect()
 {
     $dom = SimpleHtmlDom::fromUrl(__DIR__ . '/incorrect.html');
     $a = new LuckyNumberParser();
     $result = $a->getLuckyNumber($dom);
     $this->assertEquals(null, $result);
     $this->assertGreaterThan(0, count($a->getErrors()));
 }
示例#2
0
 private function updateLuckyNumbers($dom)
 {
     $model = new LuckyNumberRepository();
     $parser = new LuckyNumberParser();
     $remote = $parser->getLuckyNumber($dom);
     $this->logErrors('LuckyNumberParser', $parser->getErrors());
     if ($remote !== null) {
         $local = $model->getByDate($remote->date);
         if ($local === null || $remote->value !== $local->value) {
             $model->setValue($remote->date, $remote->value);
             echo "updated ln/{$remote->date}\n";
         }
     }
 }
 /**
  * @param SimpleHtmlDom $dom
  * @return LuckyNumber|null
  */
 public function getLuckyNumber($dom)
 {
     $text = LuckyNumberParser::findText($dom);
     if ($text === null) {
         return null;
     }
     try {
         return LuckyNumberParser::parseText($text);
     } catch (Exception $e) {
         $this->errors[] = "Niewłaściwy format danych: " . $e->getMessage();
         return null;
     }
 }