| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Tests\Cache\Storage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Tests\Cache\Mock\AbstractStorageMock; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * Class MemcacheStorageTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @package Tests\Cache | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | class AbstractStorageTest extends \PHPUnit\Framework\TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      * @var \DateInterval | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     public $ttl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * @var AbstractStorageMock | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     public $abstractStorage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * AbstractStorage Setup. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * AbstractStorageMock simply extends AbstractStorage. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     public function setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $this->ttl = new \DateInterval('P1M'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $this->abstractStorage = new AbstractStorageMock($this->ttl); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * Test immutable setter AbstractStorage::withTtl | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |     public function testWithTtl(){ | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |         $newDateInterval = new \DateInterval('P2M'); | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |         $newTtl = $this->abstractStorage->withTtl($newDateInterval); | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |         $this->assertNotSame($this->abstractStorage->getTtl(), $newTtl->getTtl()); | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * Test getter AbstractStorage::getTtl | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     public function testGetTtl(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $ttl = $this->abstractStorage->getTtl(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $this->assertSame($this->ttl, $ttl); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * Get get ttl when provided with null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     public function testGetTtlTimestampWhenNull(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $dateTime = new \DateTime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $dateTime->add( $this->ttl ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $expected = $dateTime->getTimestamp(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $actual = $this->abstractStorage->getTtlTimestamp(null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $this->assertEquals($expected, $actual); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * Test get ttl when provided with an integer. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     public function testGetTtlTimestampWhenInt(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $expected = 60*60*7; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $actual = $this->abstractStorage->getTtlTimestamp($expected); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $this->assertEquals($expected, $actual); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 69 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 70 |  |  |  |