class BrowserTestBaseTest in Drupal 8
Same name in this branch
- 8 core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest
- 8 core/tests/Drupal/Tests/Core/Test/BrowserTestBaseTest.php \Drupal\Tests\Core\Test\BrowserTestBaseTest
- 8 core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php \Drupal\KernelTests\Core\Test\BrowserTestBaseTest
Same name and namespace in other branches
- 9 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 PhpunitCompatibilityTrait
- class \Drupal\Tests\Core\Test\BrowserTestBaseTest
Expanded class hierarchy of BrowserTestBaseTest
File
- core/
tests/ Drupal/ Tests/ Core/ Test/ BrowserTestBaseTest.php, line 15
Namespace
Drupal\Tests\Core\TestView source
class BrowserTestBaseTest extends UnitTestCase {
protected function mockBrowserTestBaseWithDriver($driver) {
$session = $this
->getMockBuilder(Session::class)
->disableOriginalConstructor()
->setMethods([
'getDriver',
])
->getMock();
$session
->expects($this
->once())
->method('getDriver')
->willReturn($driver);
$btb = $this
->getMockBuilder(BrowserTestBase::class)
->disableOriginalConstructor()
->setMethods([
'getSession',
])
->getMockForAbstractClass();
$btb
->expects($this
->once())
->method('getSession')
->willReturn($session);
return $btb;
}
/**
* @covers ::getHttpClient
*/
public function testGetHttpClient() {
// Our stand-in for the Guzzle client object.
$expected = new \stdClass();
$browserkit_client = $this
->getMockBuilder(Client::class)
->setMethods([
'getClient',
])
->getMockForAbstractClass();
$browserkit_client
->expects($this
->once())
->method('getClient')
->willReturn($expected);
// Because the driver is a GoutteDriver, we'll get back a client.
$driver = $this
->getMockBuilder(GoutteDriver::class)
->setMethods([
'getClient',
])
->getMock();
$driver
->expects($this
->once())
->method('getClient')
->willReturn($browserkit_client);
$btb = $this
->mockBrowserTestBaseWithDriver($driver);
$ref_gethttpclient = new \ReflectionMethod($btb, 'getHttpClient');
$ref_gethttpclient
->setAccessible(TRUE);
$this
->assertSame(get_class($expected), get_class($ref_gethttpclient
->invoke($btb)));
}
/**
* @covers ::getHttpClient
*/
public function testGetHttpClientException() {
// A driver type that isn't GoutteDriver. This should cause a
// RuntimeException.
$btb = $this
->mockBrowserTestBaseWithDriver(new \stdClass());
$ref_gethttpclient = new \ReflectionMethod($btb, 'getHttpClient');
$ref_gethttpclient
->setAccessible(TRUE);
$this
->expectException(\RuntimeException::class);
$this
->expectExceptionMessage('The Mink client type stdClass does not support getHttpClient().');
$ref_gethttpclient
->invoke($btb);
}
/**
* Test that tearDown doesn't call cleanupEnvironment if setUp is not called.
*
* @covers ::tearDown
*/
public function testTearDownWithoutSetUp() {
$method = 'cleanupEnvironment';
$this
->assertTrue(method_exists(BrowserTestBase::class, $method));
$btb = $this
->getMockBuilder(BrowserTestBase::class)
->disableOriginalConstructor()
->setMethods([
$method,
])
->getMockForAbstractClass();
$btb
->expects($this
->never())
->method($method);
$ref_tearDown = new \ReflectionMethod($btb, 'tearDown');
$ref_tearDown
->setAccessible(TRUE);
$ref_tearDown
->invoke($btb);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BrowserTestBaseTest:: |
protected | function | ||
BrowserTestBaseTest:: |
public | function | @covers ::getHttpClient | |
BrowserTestBaseTest:: |
public | function | @covers ::getHttpClient | |
BrowserTestBaseTest:: |
public | function | Test that tearDown doesn't call cleanupEnvironment if setUp is not called. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |