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
7ca96f77
Unverified
Commit
7ca96f77
authored
Sep 12, 2017
by
Mateu Aguiló Bosch
Browse files
test(Misc): Add test coverage to the JsonPathReplacer
parent
86a3a050
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/src/Unit/JsonPathReplacerTest.php
0 → 100644
View file @
7ca96f77
<?php
namespace
Drupal\Tests\subrequests\Unit
;
use
Drupal\subrequests\JsonPathReplacer
;
use
Drupal\subrequests\Subrequest
;
use
Drupal\Tests\UnitTestCase
;
use
Symfony\Component\HttpFoundation\Response
;
/**
* @coversDefaultClass \Drupal\subrequests\JsonPathReplacer
* @group subrequests
*/
class
JsonPathReplacerTest
extends
UnitTestCase
{
/**
* @var \Drupal\subrequests\JsonPathReplacer
*/
protected
$sut
;
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
sut
=
new
JsonPathReplacer
();
}
/**
* @covers ::replaceBatch
*/
public
function
testReplaceBatch
()
{
$batch
=
$responses
=
[];
$batch
[]
=
new
Subrequest
([
'uri'
=>
'/ipsum/{{foo.body@$.things[*]}}'
,
'action'
=>
'sing'
,
'requestId'
=>
'oop'
,
'headers'
=>
[],
'_resolved'
=>
FALSE
,
'body'
=>
[
'answer'
=>
'{{foo.body@$.stuff}}'
],
'waitFor'
=>
'foo'
,
]);
$batch
[]
=
new
Subrequest
([
'uri'
=>
'/dolor/{{foo.body@$.stuff}}'
,
'action'
=>
'create'
,
'requestId'
=>
'oof'
,
'headers'
=>
[],
'_resolved'
=>
FALSE
,
'body'
=>
'bar'
,
'waitFor'
=>
'foo'
,
]);
$response
=
Response
::
create
(
'{"things":["what","keep","talking"],"stuff":42}'
);
$response
->
headers
->
set
(
'Content-ID'
,
'<foo>'
);
$responses
[]
=
$response
;
$actual
=
$this
->
sut
->
replaceBatch
(
$batch
,
$responses
);
$this
->
assertCount
(
4
,
$actual
);
$paths
=
array_map
(
function
(
Subrequest
$subrequest
)
{
return
$subrequest
->
uri
;
},
$actual
);
$this
->
assertEquals
([
'/ipsum/what'
,
'/ipsum/keep'
,
'/ipsum/talking'
,
'/dolor/42'
],
$paths
);
$this
->
assertEquals
([
'answer'
=>
42
],
$actual
[
0
]
->
body
);
}
}
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