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
86a3a050
Unverified
Commit
86a3a050
authored
Sep 12, 2017
by
Mateu Aguiló Bosch
Browse files
test(Misc): Add test coverage to the BlueprintManager
parent
8f959d2a
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/phpunit.xml
0 → 100644
View file @
86a3a050
<!--?xml version="1.0" encoding="UTF-8"?-->
<phpunit
colors=
"true"
>
<testsuites>
<testsuite
name=
"subrequests"
>
<directory>
./src/
</directory>
</testsuite>
</testsuites>
<!-- Filter for coverage reports. -->
<filter>
<blacklist>
<directory>
./vendor
</directory>
</blacklist>
<whitelist>
<directory>
../src
</directory>
</whitelist>
</filter>
</phpunit>
tests/src/Unit/Blueprint/BlueprintManagerTest.php
0 → 100644
View file @
86a3a050
<?php
namespace
Drupal\Tests\subrequests\Unit\Blueprint
;
use
Drupal\Core\Cache\CacheableResponse
;
use
Drupal\subrequests\Blueprint\BlueprintManager
;
use
Drupal\subrequests\Normalizer\JsonBlueprintDenormalizer
;
use
Drupal\subrequests\Normalizer\MultiresponseNormalizer
;
use
Drupal\subrequests\SubrequestsTree
;
use
Drupal\Tests\UnitTestCase
;
use
Prophecy\Argument
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\Serializer\Encoder\JsonDecode
;
use
Symfony\Component\Serializer\Serializer
;
/**
* @coversDefaultClass \Drupal\subrequests\Blueprint\BlueprintManager
* @group subrequests
*/
class
BlueprintManagerTest
extends
UnitTestCase
{
/**
* @var \Drupal\subrequests\Blueprint\BlueprintManager
*/
protected
$sut
;
protected
function
setUp
()
{
parent
::
setUp
();
$denormalizer
=
$this
->
prophesize
(
JsonBlueprintDenormalizer
::
class
);
$denormalizer
->
denormalize
(
Argument
::
type
(
'array'
),
SubrequestsTree
::
class
,
'json'
,
[])
->
willReturn
(
new
SubrequestsTree
());
$denormalizer
->
supportsDenormalization
(
Argument
::
type
(
'array'
),
SubrequestsTree
::
class
,
'json'
)
->
willReturn
([])
->
willReturn
(
TRUE
);
$denormalizer
->
setSerializer
(
Argument
::
any
())
->
willReturn
(
NULL
);
$normalizer
=
$this
->
prophesize
(
MultiresponseNormalizer
::
class
);
$normalizer
->
normalize
(
Argument
::
type
(
'array'
),
'multipart-related'
,
Argument
::
type
(
'array'
))
->
willReturn
(
'Booh!'
);
$normalizer
->
supportsNormalization
(
Argument
::
type
(
'array'
),
'multipart-related'
)
->
willReturn
([])
->
willReturn
(
TRUE
);
$serializer
=
new
Serializer
(
[
$denormalizer
->
reveal
(),
$normalizer
->
reveal
()],
[
new
JsonDecode
()]
);
$this
->
sut
=
new
BlueprintManager
(
$serializer
);
}
/**
* @covers ::parse
*/
public
function
testParse
()
{
$parsed
=
$this
->
sut
->
parse
(
'[]'
,
Request
::
create
(
'foo'
));
$this
->
assertInstanceOf
(
SubrequestsTree
::
class
,
$parsed
);
$this
->
assertSame
(
'/foo'
,
$parsed
->
getMasterRequest
()
->
getPathInfo
());
}
/**
* @covers ::combineResponses
*/
public
function
testCombineResponses
()
{
$responses
=
[
Response
::
create
(
'foo'
,
200
,
[
'lorem'
=>
'ipsum'
,
'Content-Type'
=>
'sparrow'
]),
Response
::
create
(
'bar'
,
201
,
[
'dolor'
=>
'sid'
,
'Content-Type'
=>
'sparrow'
]),
];
$combined
=
$this
->
sut
->
combineResponses
(
$responses
);
$this
->
assertInstanceOf
(
CacheableResponse
::
class
,
$combined
);
$content_type
=
$combined
->
headers
->
get
(
'Content-Type'
);
$this
->
assertStringStartsWith
(
'multipart/related; boundary="'
,
$content_type
);
$this
->
assertStringEndsWith
(
'", type=sparrow'
,
$content_type
);
$this
->
assertSame
(
'Booh!'
,
$combined
->
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