Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion tests/CacheWrapperTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php
namespace CacheBundle\Tests;

use CacheBundle\Annotation\Cache;
use CacheBundle\Tests\Helpers\CacheableClass;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Monolog\Handler\TestHandler;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
Expand Down Expand Up @@ -70,6 +73,28 @@ public function testWithParams()
$this->assertEquals($dataWithParam, $object->getCachedTime(300));
}

public function testWithSamePrefix()
{
/** @var CacheableClass $object */
$object = $this->container->get('cache.testservice');

$objectReflectionClass = new \ReflectionClass($object);
$annotationReader = new AnnotationReader();

/** @var Cache $methodOne */
$methodOne = $annotationReader->getMethodAnnotation(new \ReflectionMethod($objectReflectionClass->getParentClass()->getName(), 'getComputationOneWithoutParametersSamePrefix'), Cache::class);
/** @var Cache $methodTwo */
$methodTwo = $annotationReader->getMethodAnnotation(new \ReflectionMethod($objectReflectionClass->getParentClass()->getName(), 'getComputationTwoWithoutParametersSamePrefix'), Cache::class);

$resultOne = $object->getComputationOneWithoutParametersSamePrefix();
$resultTwo = $object->getComputationTwoWithoutParametersSamePrefix();

$this->assertEquals($methodOne->getCache(), $methodTwo->getCache());
$this->assertNotEquals($resultOne, $resultTwo);
sleep(1);
$this->assertNotEquals($object->getComputationOneWithoutParametersSamePrefix(), $object->getComputationTwoWithoutParametersSamePrefix());
}

public function testWithParamsExtendedClass()
{
$object = $this->container->get('cache.testservice.extended');
Expand Down Expand Up @@ -105,7 +130,7 @@ public function testWithMultiParams()

/**
* @expectedExceptionMessage Missing param3
* @expectedException CacheBundle\Exception\CacheException
* @expectedException \CacheBundle\Exception\CacheException
*/
public function testWithWrongParamNames()
{
Expand Down
20 changes: 20 additions & 0 deletions tests/Helpers/CacheableClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,24 @@ protected function protectedMethod()
{
return time();
}

/**
* @Cache(cache="__key")
*
* @return int
*/
public function getComputationOneWithoutParametersSamePrefix() : int
{
return 10;
}

/**
* @Cache(cache="__key")
*
* @return int
*/
public function getComputationTwoWithoutParametersSamePrefix() : int
{
return 20;
}
}