Skip to content

Commit

Permalink
[test] fix old static cache tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phproberto committed Dec 9, 2019
1 parent d73971b commit de739f3
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions tests/tests/Traits/HasStaticCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,45 @@ public function clearStaticCacheClearsCache()
$staticCacheProperty->setAccessible(true);

$cache = [
'mycache' => 'myvalue'
ClassWithStaticCache::class => [
'mycache' => 'myvalue'
]
];

$this->assertEquals([], $staticCacheProperty->getValue(ClassWithStaticCache::class));

$staticCacheProperty->setValue(ClassWithStaticCache::class, $cache);
$this->assertEquals($cache, $staticCacheProperty->getValue(ClassWithStaticCache::class));

ClassWithStaticCache::clearStaticCache();

$this->assertEquals([], $staticCacheProperty->getValue(ClassWithStaticCache::class));
$this->assertEquals([ClassWithStaticCache::class => []], $staticCacheProperty->getValue(ClassWithStaticCache::class));
}

/**
* @test
*
* @return void
*/
public function getStaticCacheReturnsReferenceToCache()
public function getFromStaticCacheReturnsCachedValue()
{
$class = new ClassWithStaticCache;

$reflection = new \ReflectionClass($class);
$staticCacheProperty = $reflection->getProperty('staticCache');
$staticCacheProperty->setAccessible(true);

$method = $reflection->getMethod('getStaticCache');
$method->setAccessible(true);
$cache = [
ClassWithStaticCache::class => [
'my-key' => 'my-value'
]
];

$staticCacheProperty->setValue($class, $cache);

$staticCache = $method->invoke($class);
$staticCache['test'] = 'value';
$method = $reflection->getMethod('getFromStaticCache');
$method->setAccessible(true);

$this->assertEquals('value', $staticCacheProperty->getValue($class)['test']);
$this->assertEquals('my-value', $method->invoke($class, 'my-key'));
}
}

0 comments on commit de739f3

Please sign in to comment.