Cache Annotation
Enable or disable a cache type using the @magentoCache annotation.
Format
1
2
3
4
/**
* @magentoCache [<type>|all] [enabled|disabled]
* @magentoCache [<type>|all] [enabled|disabled]
*/
Here,
<type>is a placeholder for a cache typeallis a value for any cache typeenabledordisabledto enable or disable the cache respectively
Principles
- You can use more than one annotation for a test case or a test method.
- Multiple annotations are applied in the given order.
- Annotations from different scopes are not merged.
- A test method annotation completely overrides a test case annotation.
- All cache types are disabled by default.
Test case
@magentoCache annotation at the test case level is applied to all tests.
Test method
@magentoCache annotation at a test method level configures the test only.
It completely overrides the annotation specified for the test case.
Example
Cache annotations example:
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
<?php
namespace Magento\Foo;
/**
* @magentoCache all enabled
*/
class BarTest extends \PHPUnit\Framework\TestCase
{
public function testOne()
{
...
}
/**
* @magentoCache config disabled
*/
public function testTwo()
{
...
}
/**
* @magentoCache all enabled
* @magentoCache config disabled
*/
public function testThree()
{
...
}
/**
* @magentoCache config disabled
* @magentoCache all enabled
*/
public function testFour()
{
...
}
}
- Each test method without the
@magentoCacheannotation is run with all cache types enabled. testOne()is run with all cache types enabled.-
testTwo()is run with all cache types disabled.The
@magentoCache config disabledcompletely overrides the test case annotation. The test case annotation wasn’t applied in this case. By default, all cache types are disabled. Thus any disabling annotations does not make much sense here. testThree()is run with all butconfigcache type enabled.-
testFour()is run with all the cache types enabled.All cache types are disabled initially, so
@magentoCache config disableddoesn’t make sense here.