Cache annotation

Enable or disable a cache type using the @magentoCache annotation.

Format

/**
 * @magentoCache [<type>|all] [enabled|disabled]
 * @magentoCache [<type>|all] [enabled|disabled]
 */

Here,

Principles

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

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