TestDiscoveryCacheContextTest.php in Drupal 8
File
core/modules/simpletest/tests/src/Kernel/Cache/Context/TestDiscoveryCacheContextTest.php
View source
<?php
namespace Drupal\Tests\simpletest\Kernel\Cache\Context;
use Drupal\KernelTests\KernelTestBase;
use Drupal\simpletest\Cache\Context\TestDiscoveryCacheContext;
use Drupal\simpletest\TestDiscovery;
class TestDiscoveryCacheContextTest extends KernelTestBase {
public static $modules = [
'simpletest',
];
public function testContext() {
$discovery = $this
->getMockBuilder(TestDiscovery::class)
->setMethods([
'getTestClasses',
])
->disableOriginalConstructor()
->getMock();
$discovery
->expects($this
->any())
->method('getTestClasses')
->willReturnOnConsecutiveCalls([
'group1' => [
'Test',
],
], [
'group2' => [
'Test2',
],
]);
$cache_context = new TestDiscoveryCacheContext($discovery, $this->container
->get('private_key'));
$context_hash = $cache_context
->getContext();
$hash_ref = new \ReflectionProperty($cache_context, 'hash');
$hash_ref
->setAccessible(TRUE);
$hash_ref
->setValue($cache_context, NULL);
$this
->assertNotSame($context_hash, $cache_context
->getContext());
}
}