77use Detection \Exception \MobileDetectException ;
88use Detection \MobileDetect ;
99use PHPUnit \Framework \TestCase ;
10+ use Psr \SimpleCache \InvalidArgumentException ;
1011
1112final class MobileDetectWithCacheTest extends TestCase
1213{
@@ -33,6 +34,7 @@ public function testFlattenHeaders()
3334
3435 /**
3536 * @throws MobileDetectException
37+ * @throws InvalidArgumentException
3638 */
3739 public function testDefaultCacheClassCreatesACacheRecord ()
3840 {
@@ -41,41 +43,17 @@ public function testDefaultCacheClassCreatesACacheRecord()
4143 $ isMobile = $ detect ->isMobile ();
4244
4345 $ this ->assertTrue ($ isMobile );
44- $ this ->assertEquals (1 , $ detect ->getCache ()->count ());
45- $ this ->assertSame (
46- sha1 ("mobile:Some iPhone user agent: " ),
47- $ detect ->getCache ()->getKeys ()[0 ]
48- );
49- }
50-
51- /**
52- * @throws MobileDetectException
53- */
54- public function testDefaultCacheClassCreatesASingleCacheRecordOnMultipleIsMobileCalls ()
55- {
56- $ detect = new MobileDetect ();
57- $ detect ->setUserAgent ('Some iPhone user agent ' );
58- $ isMobile = $ detect ->isMobile ();
59- $ this ->assertTrue ($ isMobile );
60- $ this ->assertEquals (1 , $ detect ->getCache ()->count ());
61-
62- $ isMobile = $ detect ->isMobile ();
63- $ this ->assertTrue ($ isMobile );
64- $ this ->assertEquals (1 , $ detect ->getCache ()->count ());
65-
66- $ detect ->isMobile ();
67- $ detect ->isMobile ();
68- $ detect ->isMobile ();
69- $ this ->assertEquals (1 , $ detect ->getCache ()->count ());
46+ $ this ->assertTrue ($ detect ->getCache ()->has (sha1 ("mobile:Some iPhone user agent: " )));
7047 }
7148
7249 /**
7350 * @throws MobileDetectException
7451 */
7552 public function testDefaultCacheClassCreatesMultipleCacheRecordsForAllCalls ()
7653 {
54+ $ userAgent = 'iPad; AppleWebKit/533.17.9 Version/5.0.2 Mobile/8C148 Safari/6533.18.5 ' ;
7755 $ detect = new MobileDetect ();
78- $ detect ->setUserAgent (' iPad; AppleWebKit/533.17.9 Version/5.0.2 Mobile/8C148 Safari/6533.18.5 ' );
56+ $ detect ->setUserAgent ($ userAgent );
7957
8058 $ isMobile = $ detect ->isMobile ();
8159 $ isTablet = $ detect ->isTablet ();
@@ -96,23 +74,14 @@ public function testDefaultCacheClassCreatesMultipleCacheRecordsForAllCalls()
9674 $ this ->assertTrue ($ isiOS );
9775 $ this ->assertTrue ($ isiOS2 );
9876
99- $ this ->assertEquals (4 , $ detect ->getCache ()->count ());
100- $ this ->assertSame (
101- sha1 ("mobile:iPad; AppleWebKit/533.17.9 Version/5.0.2 Mobile/8C148 Safari/6533.18.5: " ),
102- $ detect ->getCache ()->getKeys ()[0 ]
103- );
104- $ this ->assertSame (
105- sha1 ("tablet:iPad; AppleWebKit/533.17.9 Version/5.0.2 Mobile/8C148 Safari/6533.18.5: " ),
106- $ detect ->getCache ()->getKeys ()[1 ]
107- );
108- $ this ->assertSame (
109- sha1 ("iPad:iPad; AppleWebKit/533.17.9 Version/5.0.2 Mobile/8C148 Safari/6533.18.5: " ),
110- $ detect ->getCache ()->getKeys ()[2 ]
111- );
112- $ this ->assertSame (
113- sha1 ("iOS:iPad; AppleWebKit/533.17.9 Version/5.0.2 Mobile/8C148 Safari/6533.18.5: " ),
114- $ detect ->getCache ()->getKeys ()[3 ]
115- );
77+ $ this ->assertInstanceOf (CacheItem::class, $ detect ->getCache ()->get (sha1 ("mobile: $ userAgent: " )));
78+ $ this ->assertTrue ($ detect ->getCache ()->get (sha1 ("mobile: $ userAgent: " ))->get ());
79+ $ this ->assertInstanceOf (CacheItem::class, $ detect ->getCache ()->get (sha1 ("tablet: $ userAgent: " )));
80+ $ this ->assertTrue ($ detect ->getCache ()->get (sha1 ("tablet: $ userAgent: " ))->get ());
81+ $ this ->assertInstanceOf (CacheItem::class, $ detect ->getCache ()->get (sha1 ("iPad: $ userAgent: " )));
82+ $ this ->assertTrue ($ detect ->getCache ()->get (sha1 ("iPad: $ userAgent: " ))->get ());
83+ $ this ->assertInstanceOf (CacheItem::class, $ detect ->getCache ()->get (sha1 ("iOS: $ userAgent: " )));
84+ $ this ->assertTrue ($ detect ->getCache ()->get (sha1 ("iOS: $ userAgent: " ))->get ());
11685 }
11786
11887 /**
0 commit comments