Skip to content

Commit

Permalink
Add an extra test that check if the result was actually retrieved fro…
Browse files Browse the repository at this point in the history
…m cache
  • Loading branch information
NielsLeenheer committed Feb 21, 2016
1 parent 9d95002 commit 226554b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ trait Cache
private $cache;
private $expires;

/**
* @var boolean $cached Was this result retrieve from the cache?
*/

public $cached = false;


/**
* Enable caching of results
Expand Down Expand Up @@ -37,6 +43,8 @@ private function applyCachedData($data)
foreach ($data as $key => $value) {
$this->$key = $value;
}

$this->cached = true;
}


Expand Down
2 changes: 2 additions & 0 deletions tests/unit/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ function countCachedItems($pool) {
$result = $parser->toArray();

$this->assertEquals(1, countCachedItems($pool));
$this->assertEquals(false, $parser->cached);

$parser = new Parser();
$parser->setCache($pool);
$parser->analyse("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; InfoPath.1)");

$this->assertEquals($result, $parser->toArray());
$this->assertEquals(true, $parser->cached);
}
}

0 comments on commit 226554b

Please sign in to comment.