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
0aff30b5
Unverified
Commit
0aff30b5
authored
Sep 12, 2017
by
Mateu Aguiló Bosch
Browse files
test(Misc): Add test coverage to the JsonBlueprintDenormalizer
parent
7ca96f77
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/src/Unit/Normalizer/JsonBlueprintDenormalizerTest.php
0 → 100644
View file @
0aff30b5
<?php
namespace
Drupal\Tests\subrequests\Normalizer
;
use
Drupal\subrequests\Normalizer\JsonBlueprintDenormalizer
;
use
Drupal\subrequests\Subrequest
;
use
Drupal\subrequests\SubrequestsTree
;
use
Drupal\Tests\UnitTestCase
;
use
Psr\Log\LoggerInterface
;
/**
* @coversDefaultClass \Drupal\subrequests\Normalizer\JsonBlueprintDenormalizer
* @group subrequests
*/
class
JsonBlueprintDenormalizerTest
extends
UnitTestCase
{
/**
* @var \Drupal\subrequests\Normalizer\JsonBlueprintDenormalizer
*/
protected
$sut
;
protected
function
setUp
()
{
parent
::
setUp
();
$logger
=
$this
->
prophesize
(
LoggerInterface
::
class
);
$this
->
sut
=
new
JsonBlueprintDenormalizer
(
$logger
->
reveal
());
}
/**
* @dataProvider dataProviderSupportsNormalization
* @covers ::supportsDenormalization
*/
public
function
testSupportsDenormalization
(
$data
,
$type
,
$format
,
$is_supported
)
{
$actual
=
$this
->
sut
->
supportsDenormalization
(
$data
,
$type
,
$format
);
$this
->
assertSame
(
$is_supported
,
$actual
);
}
public
function
dataProviderSupportsNormalization
()
{
return
[
[[
'a'
,
'b'
],
SubrequestsTree
::
class
,
'json'
,
TRUE
],
[
'fail'
,
SubrequestsTree
::
class
,
'json'
,
FALSE
],
[[
'a'
,
'b'
],
SubrequestsTree
::
class
,
'fail'
,
FALSE
],
[[
'fail'
=>
'a'
,
'b'
],
SubrequestsTree
::
class
,
'json'
,
FALSE
],
];
}
public
function
testDenormalize
()
{
$subrequests
[]
=
[
'uri'
=>
'lorem'
,
'action'
=>
'view'
,
'requestId'
=>
'foo'
,
'body'
=>
'"bar"'
,
'headers'
=>
[],
];
$subrequests
[]
=
[
'uri'
=>
'ipsum'
,
'action'
=>
'sing'
,
'requestId'
=>
'oop'
,
'body'
=>
'[]'
,
'waitFor'
=>
'foo'
,
];
$subrequests
[]
=
[
'uri'
=>
'lorem'
,
'action'
=>
'create'
,
'requestId'
=>
'oof'
,
'body'
=>
'"bar"'
,
'waitFor'
=>
'foo'
,
];
$actual
=
$this
->
sut
->
denormalize
(
$subrequests
,
SubrequestsTree
::
class
,
'json'
,
[]);
$tree
=
new
SubrequestsTree
();
$tree
->
stack
([
new
Subrequest
([
'waitFor'
=>
'<ROOT>'
,
'_resolved'
=>
FALSE
,
'body'
=>
'bar'
]
+
$subrequests
[
0
])]);
$tree
->
stack
([
new
Subrequest
([
'headers'
=>
[],
'_resolved'
=>
FALSE
,
'body'
=>
[]]
+
$subrequests
[
1
]),
new
Subrequest
([
'headers'
=>
[],
'_resolved'
=>
FALSE
,
'body'
=>
'bar'
]
+
$subrequests
[
2
])
]);
$this
->
assertEquals
(
$tree
,
$actual
);
}
}
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