class SubrequestsManagerTest in Subrequests 8.2
Same name and namespace in other branches
- 3.x tests/src/Unit/SubrequestsManagerTest.php \Drupal\Tests\subrequests\Unit\SubrequestsManagerTest
@coversDefaultClass \Drupal\subrequests\SubrequestsManager @group subrequests
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\subrequests\Unit\SubrequestsManagerTest
Expanded class hierarchy of SubrequestsManagerTest
File
- tests/
src/ Unit/ SubrequestsManagerTest.php, line 22
Namespace
Drupal\Tests\subrequests\UnitView source
class SubrequestsManagerTest extends UnitTestCase {
/**
* @var \Drupal\subrequests\SubrequestsManager
*/
protected $sut;
protected function setUp() {
parent::setUp();
$http_kernel = $this
->prophesize(HttpKernelInterface::class);
$http_kernel
->handle(Argument::type(Request::class), HttpKernelInterface::MASTER_REQUEST)
->will(function ($args) {
return Response::create($args[0]
->getPathInfo());
});
$denormalizer = $this
->prophesize(JsonSubrequestDenormalizer::class);
$denormalizer
->denormalize(Argument::type(Subrequest::class), Request::class, NULL, Argument::type('array'))
->will(function ($args) {
return Request::create($args[0]->uri);
});
$denormalizer
->supportsDenormalization(Argument::type(Subrequest::class), Request::class, NULL)
->willReturn([])
->willReturn(TRUE);
$denormalizer
->supportsDenormalization(Argument::type(Subrequest::class), Request::class, NULL, Argument::type('array'))
->willReturn([])
->willReturn(TRUE);
$serializer = new Serializer([
$denormalizer
->reveal(),
], [
new JsonDecode(),
]);
$this->sut = new SubrequestsManager($http_kernel
->reveal(), $serializer, new JsonPathReplacer());
}
/**
* @covers ::request
*/
public function testRequest() {
// Create and populate a tree.
$tree = new SubrequestsTree();
$subrequests[] = new Subrequest([
'uri' => 'lorem',
'action' => 'view',
'requestId' => 'foo',
'headers' => [],
'waitFor' => [
'<ROOT>',
],
'_resolved' => FALSE,
'body' => 'bar',
]);
$subrequests[] = new Subrequest([
'uri' => 'ipsum',
'action' => 'sing',
'requestId' => 'oop',
'headers' => [],
'_resolved' => FALSE,
'body' => [],
'waitFor' => [
'foo',
],
]);
$subrequests[] = new Subrequest([
'uri' => 'dolor',
'action' => 'create',
'requestId' => 'oof',
'headers' => [],
'_resolved' => FALSE,
'body' => 'bar',
'waitFor' => [
'foo',
],
]);
$tree
->stack([
$subrequests[0],
]);
$tree
->stack([
$subrequests[1],
$subrequests[2],
]);
$tree
->setMasterRequest(new Request());
$actual = $this->sut
->request($tree);
$this
->assertSame('<foo>', $actual[0]->headers
->get('Content-ID'));
$this
->assertSame('<oop>', $actual[1]->headers
->get('Content-ID'));
$this
->assertSame('<oof>', $actual[2]->headers
->get('Content-ID'));
$this
->assertSame('/lorem', $actual[0]
->getContent());
$this
->assertSame('/ipsum', $actual[1]
->getContent());
$this
->assertSame('/dolor', $actual[2]
->getContent());
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
SubrequestsManagerTest:: |
protected | property | ||
SubrequestsManagerTest:: |
protected | function |
Overrides UnitTestCase:: |
|
SubrequestsManagerTest:: |
public | function | @covers ::request | |
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. |