Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
subrequests
Commits
b9c94653
Unverified
Commit
b9c94653
authored
Sep 12, 2017
by
Mateu Aguiló Bosch
Browse files
test(Misc): Add test coverage to the SubrequestsManager
parent
71e3b0d7
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/src/Unit/SubrequestsManagerTest.php
0 → 100644
View file @
b9c94653
<?php
namespace
Drupal\Tests\subrequests\Unit
;
use
Drupal\subrequests\JsonPathReplacer
;
use
Drupal\subrequests\Normalizer\JsonSubrequestDenormalizer
;
use
Drupal\subrequests\Subrequest
;
use
Drupal\subrequests\SubrequestsManager
;
use
Drupal\subrequests\SubrequestsTree
;
use
Drupal\Tests\UnitTestCase
;
use
Prophecy\Argument
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\HttpKernel\HttpKernelInterface
;
use
Symfony\Component\Serializer\Encoder\JsonDecode
;
use
Symfony\Component\Serializer\Serializer
;
/**
* @coversDefaultClass \Drupal\subrequests\SubrequestsManager
* @group subrequests
*/
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
);
$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
]]);
$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
());
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment