class BrowserTestBaseTest
Same name in this branch
- 11.x core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php \Drupal\KernelTests\Core\Test\BrowserTestBaseTest
- 9 core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest
- 9 core/tests/Drupal/Tests/Core/Test/BrowserTestBaseTest.php \Drupal\Tests\Core\Test\BrowserTestBaseTest
- 8.9.x core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php \Drupal\KernelTests\Core\Test\BrowserTestBaseTest
- 8.9.x core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest
- 8.9.x core/tests/Drupal/Tests/Core/Test/BrowserTestBaseTest.php \Drupal\Tests\Core\Test\BrowserTestBaseTest
- 10 core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php \Drupal\KernelTests\Core\Test\BrowserTestBaseTest
- 10 core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest
- 10 core/tests/Drupal/Tests/Core/Test/BrowserTestBaseTest.php \Drupal\Tests\Core\Test\BrowserTestBaseTest
@coversDefaultClass \Drupal\Tests\BrowserTestBase @group Test
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\Core\Test\BrowserTestBaseTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of BrowserTestBaseTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Test/ BrowserTestBaseTest.php, line 17
Namespace
Drupal\Tests\Core\TestView source
class BrowserTestBaseTest extends UnitTestCase {
protected function mockBrowserTestBaseWithDriver($driver) {
$session = $this->getMockBuilder(Session::class)
->disableOriginalConstructor()
->onlyMethods([
'getDriver',
])
->getMock();
$session->expects($this->any())
->method('getDriver')
->willReturn($driver);
$btb = $this->getMockBuilder(BrowserTestBaseMockableClass::class)
->disableOriginalConstructor()
->onlyMethods([
'getSession',
])
->getMock();
$btb->expects($this->any())
->method('getSession')
->willReturn($session);
return $btb;
}
/**
* @covers ::getHttpClient
*/
public function testGetHttpClient() : void {
// Our stand-in for the Guzzle client object.
$expected = new \stdClass();
$browserkit_client = $this->getMockBuilder(DrupalTestBrowser::class)
->onlyMethods([
'getClient',
])
->getMock();
$browserkit_client->expects($this->once())
->method('getClient')
->willReturn($expected);
// Because the driver is a BrowserKitDriver, we'll get back a client.
$driver = new BrowserKitDriver($browserkit_client);
$btb = $this->mockBrowserTestBaseWithDriver($driver);
$reflected_get_http_client = new \ReflectionMethod($btb, 'getHttpClient');
$this->assertSame(get_class($expected), get_class($reflected_get_http_client->invoke($btb)));
}
/**
* @covers ::getHttpClient
*/
public function testGetHttpClientException() : void {
// A driver type that isn't BrowserKitDriver. This should cause a
// RuntimeException.
$btb = $this->mockBrowserTestBaseWithDriver(new \stdClass());
$reflected_get_http_client = new \ReflectionMethod($btb, 'getHttpClient');
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('The Mink client type stdClass does not support getHttpClient().');
$reflected_get_http_client->invoke($btb);
}
/**
* Tests that tearDown doesn't call cleanupEnvironment if setUp is not called.
*
* @covers ::tearDown
*/
public function testTearDownWithoutSetUp() : void {
$method = 'cleanupEnvironment';
$this->assertTrue(method_exists(BrowserTestBase::class, $method));
$btb = $this->getMockBuilder(BrowserTestBaseMockableClass::class)
->disableOriginalConstructor()
->onlyMethods([
$method,
])
->getMock();
$btb->expects($this->never())
->method($method);
$ref_tearDown = new \ReflectionMethod($btb, 'tearDown');
$ref_tearDown->invoke($btb);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
BrowserTestBaseTest::mockBrowserTestBaseWithDriver | protected | function | ||
BrowserTestBaseTest::testGetHttpClient | public | function | @covers ::getHttpClient | |
BrowserTestBaseTest::testGetHttpClientException | public | function | @covers ::getHttpClient | |
BrowserTestBaseTest::testTearDownWithoutSetUp | public | function | Tests that tearDown doesn't call cleanupEnvironment if setUp is not called. | |
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::getCallableName | private static | function | Returns a callable as a string suitable for inclusion in a message. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
UnitTestCase::$root | protected | property | The app root. | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setUp | protected | function | 367 | |
UnitTestCase::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.