Cache attribute
Enable or disable a cache type using the Cache
attribute.
Format
Copied to your clipboard#[Cache(string $type, bool $status)]
Parameters
- type
- The cache type. Or "all" to change the status of all cache types.
- status
- Accepts TRUE or FALSE to enable or disable cache respectively.
Principles
- You can use more than one attribute for a test case or a test method.
- Multiple attributes are applied in the given order.
- Attributes from different scopes are not merged.
- A test method attribute completely overrides a test class attribute.
- All cache types are disabled by default.
Test class attribute
The Cache
attribute at the test case level is applied to all tests.
Test method attribute
The Cache
attribute at a test method level configures the test method only.
It completely overrides the attribute specified for the test class.
Example
Copied to your clipboard<?phpnamespace Magento\Foo;#[Cache('all', true)]class BarTest extends \PHPUnit\Framework\TestCase{public function testOne(){...}#[Cache('config', false)]public function testTwo(){...}#[Cache('all', true),Cache('config', false)]public function testThree(){...}#[Cache('config', false),Cache('all', true)]public function testFour(){...}}
Each test method without the
Cache
attribute is run with all cache types enabled.testOne()
is run with all cache types enabled.testTwo()
is run with all cache types disabled.The
Cache('config', false)
completely overrides the test method attribute. The test method attribute wasn't applied in this case. By default, all cache types are disabled, so disabling attributes does not make much sense here.testThree()
is run with all butconfig
cache type enabled.testFour()
is run with all the cache types enabled.All cache types are disabled initially, so
Cache('config', false)
doesn't make sense here.