Skip to content

Commit

Permalink
retorna false se houver erro no regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
asaferamos committed May 25, 2018
1 parent 808ec67 commit 2ca7b10
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/RastreioParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ public function getEventsList(){
* @var [type]
*/
preg_match_all($this->_conf['regexp']['table'], $correiosPage, $cTable, PREG_SET_ORDER,0);

/**
* Regeexp para captura das <tr>
* @var [type]
*/
if(empty($cTable)) return false;

preg_match_all($this->_conf['regexp']['tr'], $cTable[0][0], $cTr);


Expand Down
35 changes: 24 additions & 11 deletions tests/RastreioParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,37 @@ public function testCode(){
public function testGetEventsList(){
$C = new Baru\Correios\RastreioParser;

$C->setCode('RE881745030BR');
$E = $C->getEventsList();

foreach ($E as $key => $value) {
var_dump($value);
$C->setCode('RE88174514BR');

try {

$E = $C->getEventsList();

foreach ($E as $key => $value) {
var_dump($value);
}

unset($C);

} catch (\Exception $e) {
echo $e->getMessage();
}

unset($C);
}

public function testGetEventLast(){
$C = new Baru\Correios\RastreioParser;

$C->setCode('RE881746675BR');
$E = $C->getEventLast();

$C->setCode('RE88174514BR');

var_dump($E);
try {
$E = $C->getEventLast();

unset($C);
var_dump($E);

unset($C);
} catch (\Exception $e) {
echo $e->getMessage();
}
}
}

0 comments on commit 2ca7b10

Please sign in to comment.