-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCacheExpressionDefaultTest.php
More file actions
82 lines (69 loc) · 2.82 KB
/
CacheExpressionDefaultTest.php
File metadata and controls
82 lines (69 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace CacheBundle\Tests;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Emag\CacheBundle\Annotation\CacheExpression;
use Emag\CacheBundle\Tests\Helpers\CacheableExpressionClass;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Kernel;
class CacheExpressionDefaultTest extends KernelTestCase
{
/**
* @var ContainerInterface
*/
protected $container;
public function setUp()
{
parent::setUp();
static::$class = null;
self::bootKernel(['environment' => 'test_expr_lang_default']);
$this->container = self::$kernel->getContainer();
}
protected static function getKernelClass()
{
return get_class(new class('test_expr_lang_default', []) extends Kernel
{
public function registerBundles()
{
return [
new \Emag\CacheBundle\EmagCacheBundle()
];
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__ . '/config_default_expression.yml');
}
public function __construct($environment, $debug)
{
parent::__construct($environment, $debug);
$loader = require __DIR__ . '/../vendor/autoload.php';
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
$this->rootDir = __DIR__ . '/app/';
}
});
}
public function testDefaultExpressionLanguage()
{
/** @var CacheableExpressionClass $object */
$object = $this->container->get('cache.expr.test.service');
$methodName = 'getIntenseResult';
$objectReflectionClass = new \ReflectionClass($object);
$annotationReader = $this->container->get('annotation_reader');
/** @var CacheExpression $cacheExpressionAnnotation */
$cacheExpressionAnnotation = $annotationReader->getMethodAnnotation(new \ReflectionMethod($objectReflectionClass->getParentClass()->getName(), $methodName), CacheExpression::class);
$cacheExpressionAnnotation
->setExpressionLanguage($this->container->get('emag.cache.expression.language'))
->setContext($object)
;
$result = $object->$methodName();
$this->assertContains($object->buildCachePrefix(), $cacheExpressionAnnotation->getCache());
$this->assertEquals(0, strpos($cacheExpressionAnnotation->getCache(), $object->buildCachePrefix()));
$this->assertEquals($result, $object->$methodName());
}
public function tearDown()
{
static::$class = null;
}
}