Loading core/tests/Drupal/Tests/Component/Datetime/TimeTest.php +7 −7 Original line number Diff line number Diff line Loading @@ -9,8 +9,10 @@ use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\PreserveGlobalState; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; /** * Tests the Time class. Loading @@ -24,11 +26,9 @@ class TimeTest extends TestCase { /** * The mocked request stack. * * @var \Symfony\Component\HttpFoundation\RequestStack|\PHPUnit\Framework\MockObject\MockObject * The request stack stub. */ protected $requestStack; protected RequestStack&Stub $requestStack; /** * The mocked time class. Loading @@ -43,7 +43,7 @@ class TimeTest extends TestCase { protected function setUp(): void { parent::setUp(); $this->requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock(); $this->requestStack = $this->createStub(RequestStack::class); $this->time = new Time($this->requestStack); } Loading @@ -57,7 +57,7 @@ public function testGetRequestTime(): void { $request->server->set('REQUEST_TIME', $expected); // Mocks a the request stack getting the current request. $this->requestStack->expects($this->any()) $this->requestStack ->method('getCurrentRequest') ->willReturn($request); Loading @@ -74,7 +74,7 @@ public function testGetRequestMicroTime(): void { $request->server->set('REQUEST_TIME_FLOAT', $expected); // Mocks a the request stack getting the current request. $this->requestStack->expects($this->any()) $this->requestStack ->method('getCurrentRequest') ->willReturn($request); Loading core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php +3 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,9 @@ public function testGetContextValue($expected, $context_value, $is_required, $da $ref_context_value = new \ReflectionProperty($mock_context, 'contextValue'); // Set contextValue to a testable state. $ref_context_value->setValue($mock_context, $context_value); // Set expectation for getContextDefinition(). $mock_context->expects($this->never()) ->method('getContextDefinition'); // Exercise getContextValue(). $this->assertEquals($context_value, $mock_context->getContextValue()); } Loading core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php +1 −3 Original line number Diff line number Diff line Loading @@ -58,11 +58,9 @@ public function testGetPluginClassWithMissingClassWithArrayPluginDefinition(): v * Tests getPluginClass() with a missing class definition. */ public function testGetPluginClassWithMissingClassWithObjectPluginDefinition(): void { $plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class) ->getMock(); $this->expectException(PluginException::class); $this->expectExceptionMessage('The plugin (corn) did not specify an instance class.'); DefaultFactory::getPluginClass('corn', $plugin_definition); DefaultFactory::getPluginClass('corn', $this->createStub(PluginDefinitionInterface::class)); } /** Loading core/tests/Drupal/Tests/Component/Plugin/Discovery/AttributeBridgeDecoratorTest.php +2 −2 Original line number Diff line number Diff line Loading @@ -34,8 +34,8 @@ public function testGetDefinitions(): void { 'id' => 'bar', 'class' => 'com\example\PluginNamespace\AttributeDiscoveryTest1', ]; $discovery = $this->createMock(DiscoveryInterface::class); $discovery->expects($this->any()) $discovery = $this->createStub(DiscoveryInterface::class); $discovery ->method('getDefinitions') ->willReturn($definitions); Loading core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryCachedTraitTest.php +2 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,8 @@ public function testGetDefinition($expected, $cached_definitions, $get_definitio }); } else { $trait->expects($this->never()) ->method('getDefinitions'); // Put $cached_definitions into our mocked ::$definitions. $reflection_definitions->setValue($trait, $cached_definitions); } Loading Loading
core/tests/Drupal/Tests/Component/Datetime/TimeTest.php +7 −7 Original line number Diff line number Diff line Loading @@ -9,8 +9,10 @@ use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\PreserveGlobalState; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; /** * Tests the Time class. Loading @@ -24,11 +26,9 @@ class TimeTest extends TestCase { /** * The mocked request stack. * * @var \Symfony\Component\HttpFoundation\RequestStack|\PHPUnit\Framework\MockObject\MockObject * The request stack stub. */ protected $requestStack; protected RequestStack&Stub $requestStack; /** * The mocked time class. Loading @@ -43,7 +43,7 @@ class TimeTest extends TestCase { protected function setUp(): void { parent::setUp(); $this->requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock(); $this->requestStack = $this->createStub(RequestStack::class); $this->time = new Time($this->requestStack); } Loading @@ -57,7 +57,7 @@ public function testGetRequestTime(): void { $request->server->set('REQUEST_TIME', $expected); // Mocks a the request stack getting the current request. $this->requestStack->expects($this->any()) $this->requestStack ->method('getCurrentRequest') ->willReturn($request); Loading @@ -74,7 +74,7 @@ public function testGetRequestMicroTime(): void { $request->server->set('REQUEST_TIME_FLOAT', $expected); // Mocks a the request stack getting the current request. $this->requestStack->expects($this->any()) $this->requestStack ->method('getCurrentRequest') ->willReturn($request); Loading
core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php +3 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,9 @@ public function testGetContextValue($expected, $context_value, $is_required, $da $ref_context_value = new \ReflectionProperty($mock_context, 'contextValue'); // Set contextValue to a testable state. $ref_context_value->setValue($mock_context, $context_value); // Set expectation for getContextDefinition(). $mock_context->expects($this->never()) ->method('getContextDefinition'); // Exercise getContextValue(). $this->assertEquals($context_value, $mock_context->getContextValue()); } Loading
core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php +1 −3 Original line number Diff line number Diff line Loading @@ -58,11 +58,9 @@ public function testGetPluginClassWithMissingClassWithArrayPluginDefinition(): v * Tests getPluginClass() with a missing class definition. */ public function testGetPluginClassWithMissingClassWithObjectPluginDefinition(): void { $plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class) ->getMock(); $this->expectException(PluginException::class); $this->expectExceptionMessage('The plugin (corn) did not specify an instance class.'); DefaultFactory::getPluginClass('corn', $plugin_definition); DefaultFactory::getPluginClass('corn', $this->createStub(PluginDefinitionInterface::class)); } /** Loading
core/tests/Drupal/Tests/Component/Plugin/Discovery/AttributeBridgeDecoratorTest.php +2 −2 Original line number Diff line number Diff line Loading @@ -34,8 +34,8 @@ public function testGetDefinitions(): void { 'id' => 'bar', 'class' => 'com\example\PluginNamespace\AttributeDiscoveryTest1', ]; $discovery = $this->createMock(DiscoveryInterface::class); $discovery->expects($this->any()) $discovery = $this->createStub(DiscoveryInterface::class); $discovery ->method('getDefinitions') ->willReturn($definitions); Loading
core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryCachedTraitTest.php +2 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,8 @@ public function testGetDefinition($expected, $cached_definitions, $get_definitio }); } else { $trait->expects($this->never()) ->method('getDefinitions'); // Put $cached_definitions into our mocked ::$definitions. $reflection_definitions->setValue($trait, $cached_definitions); } Loading