diff --git a/core/tests/Drupal/Tests/Component/Annotation/AnnotatedClassDiscoveryCachedTest.php b/core/tests/Drupal/Tests/Component/Annotation/AnnotatedClassDiscoveryCachedTest.php new file mode 100644 index 0000000000..ef839c9075 --- /dev/null +++ b/core/tests/Drupal/Tests/Component/Annotation/AnnotatedClassDiscoveryCachedTest.php @@ -0,0 +1,63 @@ + [$discovery_path]]); + $this->assertEquals([ + 'discovery_test_1' => [ + 'id' => 'discovery_test_1', + 'class' => 'com\example\PluginNamespace\DiscoveryTest1', + ], + ], $discovery->getDefinitions()); + + // Gain access to the file cache so we can change it. + $ref_file_cache = new \ReflectionProperty($discovery, 'fileCache'); + $ref_file_cache->setAccessible(TRUE); + /* @var $file_cache \Drupal\Component\FileCache\FileCacheInterface */ + $file_cache = $ref_file_cache->getValue($discovery); + // The file cache is keyed by the file path, and we'll add some known + // content to test against. + $file_cache->set($file_path, [ + 'id' => 'wrong_id', + 'content' => serialize(['an' => 'array']), + ]); + + // Now perform the same query and check for the cached results. + $this->assertEquals([ + 'wrong_id' => [ + 'an' => 'array', + ], + ], $discovery->getDefinitions()); + } + +} diff --git a/core/tests/Drupal/Tests/Component/Annotation/AnnotatedClassDiscoveryTest.php b/core/tests/Drupal/Tests/Component/Annotation/AnnotatedClassDiscoveryTest.php index 333a2514f2..85c6f010f3 100644 --- a/core/tests/Drupal/Tests/Component/Annotation/AnnotatedClassDiscoveryTest.php +++ b/core/tests/Drupal/Tests/Component/Annotation/AnnotatedClassDiscoveryTest.php @@ -4,13 +4,26 @@ use Drupal\Component\Annotation\Plugin; use Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery; -use Drupal\Tests\UnitTestCase; +use Drupal\Component\FileCache\FileCacheFactory; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass \Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery * @group Annotation */ -class AnnotatedClassDiscoveryTest extends UnitTestCase { +class AnnotatedClassDiscoveryTest extends TestCase { + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + // Ensure that the NullFileCache implementation is used for the FileCache as + // unit tests should not be relying on caches implicitly. + FileCacheFactory::setConfiguration([FileCacheFactory::DISABLE_CACHE => TRUE]); + // Ensure that FileCacheFactory has a prefix. + FileCacheFactory::setPrefix('prefix'); + } /** * @covers ::__construct diff --git a/core/tests/Drupal/Tests/Component/Annotation/AnnotationBaseTest.php b/core/tests/Drupal/Tests/Component/Annotation/AnnotationBaseTest.php index 80c8988984..91d5ae28c3 100644 --- a/core/tests/Drupal/Tests/Component/Annotation/AnnotationBaseTest.php +++ b/core/tests/Drupal/Tests/Component/Annotation/AnnotationBaseTest.php @@ -3,13 +3,13 @@ namespace Drupal\Tests\Component\Annotation; use Drupal\Component\Annotation\AnnotationBase; -use Drupal\Tests\UnitTestCase; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass \Drupal\Component\Annotation\AnnotationBase * @group Annotation */ -class AnnotationBaseTest extends UnitTestCase { +class AnnotationBaseTest extends TestCase { /** * @covers ::getProvider diff --git a/core/tests/Drupal/Tests/Component/Annotation/MockFileFinderTest.php b/core/tests/Drupal/Tests/Component/Annotation/MockFileFinderTest.php index 157f5a5335..697551c33a 100644 --- a/core/tests/Drupal/Tests/Component/Annotation/MockFileFinderTest.php +++ b/core/tests/Drupal/Tests/Component/Annotation/MockFileFinderTest.php @@ -3,13 +3,13 @@ namespace Drupal\Tests\Component\Annotation; use Drupal\Component\Annotation\Reflection\MockFileFinder; -use Drupal\Tests\UnitTestCase; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass \Drupal\Component\Annotation\Reflection\MockFileFinder * @group Annotation */ -class MockFileFinderTest extends UnitTestCase { +class MockFileFinderTest extends TestCase { /** * @covers ::create diff --git a/core/tests/Drupal/Tests/Component/Annotation/PluginIdTest.php b/core/tests/Drupal/Tests/Component/Annotation/PluginIdTest.php index 2c00c0c0e3..f115de34f1 100644 --- a/core/tests/Drupal/Tests/Component/Annotation/PluginIdTest.php +++ b/core/tests/Drupal/Tests/Component/Annotation/PluginIdTest.php @@ -3,25 +3,25 @@ namespace Drupal\Tests\Component\Annotation; use Drupal\Component\Annotation\PluginID; -use Drupal\Tests\UnitTestCase; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass \Drupal\Component\Annotation\PluginId * @group Annotation */ -class PluginIdTest extends UnitTestCase { +class PluginIdTest extends TestCase { /** * @covers ::get */ public function testGet() { // Assert plugin starts empty regardless of constructor. - $plugin = new PluginId([ + $plugin = new PluginID([ 'foo' => 'bar', 'biz' => [ 'baz' => 'boom', ], - 'nestedAnnotation' => new PluginId([ + 'nestedAnnotation' => new PluginID([ 'foo' => 'bar', ]), 'value' => 'biz', @@ -47,7 +47,7 @@ public function testGet() { * @covers ::getId */ public function testGetId() { - $plugin = new PluginId([]); + $plugin = new PluginID([]); $plugin->value = 'example'; $this->assertEquals('example', $plugin->getId()); } diff --git a/core/tests/Drupal/Tests/Component/Annotation/PluginTest.php b/core/tests/Drupal/Tests/Component/Annotation/PluginTest.php index 84f99859f2..d942764005 100644 --- a/core/tests/Drupal/Tests/Component/Annotation/PluginTest.php +++ b/core/tests/Drupal/Tests/Component/Annotation/PluginTest.php @@ -3,13 +3,13 @@ namespace Drupal\Tests\Component\Annotation; use Drupal\Component\Annotation\Plugin; -use Drupal\Tests\UnitTestCase; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass \Drupal\Component\Annotation\Plugin * @group Annotation */ -class PluginTest extends UnitTestCase { +class PluginTest extends TestCase { /** * @covers ::__construct