From 226554b5b88827a4d01f5cd580bff54c02d85742 Mon Sep 17 00:00:00 2001 From: Niels Leenheer Date: Sun, 21 Feb 2016 15:49:28 +0100 Subject: [PATCH] Add an extra test that check if the result was actually retrieved from cache --- src/Cache.php | 8 ++++++++ tests/unit/CacheTest.php | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/Cache.php b/src/Cache.php index b25f81fa2..833b33790 100644 --- a/src/Cache.php +++ b/src/Cache.php @@ -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 @@ -37,6 +43,8 @@ private function applyCachedData($data) foreach ($data as $key => $value) { $this->$key = $value; } + + $this->cached = true; } diff --git a/tests/unit/CacheTest.php b/tests/unit/CacheTest.php index 901887308..df4c823fa 100644 --- a/tests/unit/CacheTest.php +++ b/tests/unit/CacheTest.php @@ -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); } }