Cache attribute

Enable or disable a cache type using the Cache attribute.

Format

#[
   Cache(string $type, bool $status)
]

Parameters

Principles

  1. You can use more than one attribute for a test case or a test method.
  2. Multiple attributes are applied in the given order.
  3. Attributes from different scopes are not merged.
  4. A test method attribute completely overrides a test class attribute.
  5. 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

<?php

namespace 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()
    {
        ...
    }
}