Skip to content

Commit c5aaf1b

Browse files
author
abluchet
committed
debug
1 parent 32c69f2 commit c5aaf1b

File tree

8 files changed

+83
-18
lines changed

8 files changed

+83
-18
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ install:
4949

5050
script:
5151
- if [[ $coverage = 1 ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-php build/cov/coverage-phpunit.cov; else vendor/bin/phpunit; fi
52-
- if [[ $coverage = 1 ]]; then for f in $(find features -name '*.feature'); do FEATURE=${f//\//_} phpdbg -qrr vendor/bin/behat --format=progress --profile coverage $f || exit $?; done; else vendor/bin/behat --format=progress; fi
52+
- if [[ $coverage = 1 ]]; then for f in $(find features -name '*.feature'); do FEATURE=${f//\//_} phpdbg -qrr vendor/bin/behat --format=progress --profile coverage $f || exit $?; done; elif [[ $postgres = 1 ]]; then vendor/bin/behat --stop-on-failure; else vendor/bin/behat --format=progress; fi
5353
- if [[ $coverage = 1 ]]; then phpdbg -qrr phpcov.phar merge --clover build/logs/clover.xml build/cov; fi
5454
- tests/Fixtures/app/console api:swagger:export > swagger.json && swagger validate swagger.json && rm swagger.json
5555
- if [[ $lint = 1 ]]; then php php-cs-fixer.phar fix --dry-run --diff --no-ansi; fi

behat.yml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ default:
33
default:
44
contexts:
55
- 'FeatureContext': { doctrine: '@doctrine' }
6+
- 'JsonContext'
67
- 'HydraContext'
78
- 'SwaggerContext'
89
- 'HttpCacheContext'
910
- 'Behat\MinkExtension\Context\MinkContext'
1011
- 'Behatch\Context\RestContext'
11-
- 'Behatch\Context\JsonContext'
1212
extensions:
1313
'Behat\Symfony2Extension':
1414
kernel:

features/bootstrap/JsonContext.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
use Behat\Gherkin\Node\PyStringNode;
15+
use Behatch\Context\JsonContext as BaseJsonContext;
16+
use Behatch\HttpCall\HttpCallResultPool;
17+
use Behatch\Json\Json;
18+
19+
final class JsonContext extends BaseJsonContext
20+
{
21+
public function __construct(HttpCallResultPool $httpCallResultPool)
22+
{
23+
parent::__construct($httpCallResultPool);
24+
}
25+
26+
private function sortArrays(&$obj) {
27+
foreach ($obj as $key => &$value) {
28+
if (is_scalar($value)) {
29+
continue;
30+
}
31+
32+
if (is_array($value)) {
33+
sort($value);
34+
}
35+
36+
$this->sortArrays($value);
37+
}
38+
}
39+
40+
/**
41+
* @Then /^the JSON should be deep equal to:$/
42+
*/
43+
public function theJsonShouldBeDeepEqualTo(PyStringNode $content)
44+
{
45+
$actual = $this->getJson();
46+
try {
47+
$expected = new Json($content);
48+
}
49+
catch (\Exception $e) {
50+
throw new \Exception('The expected JSON is not a valid');
51+
}
52+
53+
$this->sortArrays($actual->getContent());
54+
$this->sortArrays($expected->getContent());
55+
56+
$this->assertSame(
57+
(string) $expected,
58+
(string) $actual,
59+
"The json is equal to:\n". $actual->encode()
60+
);
61+
}
62+
}

features/doctrine/numeric_filter.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Feature: Numeric filter on collections
77
Scenario: Get collection by id equals 9.99 which is not possible
88
Given there is "30" dummy objects
99
When I send a "GET" request to "/dummies?id=9.99"
10-
Then the response status code should be 200
10+
Then print last JSON response
11+
And the response status code should be 200
1112
And the response should be in JSON
1213
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
1314
And the JSON should be valid according to this schema:

features/doctrine/search_filter.feature

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ Feature: Search filter on collections
1818
Scenario: Test #944
1919
Given there is a DummyCar entity with related colors
2020
When I send a "GET" request to "/dummy_cars?colors.prop=red"
21-
Then the response status code should be 200
22-
And the JSON should be equal to:
21+
And the response status code should be 200
22+
And the JSON should be deep equal to:
2323
"""
2424
{
2525
"@context": "/contexts/DummyCar",
@@ -213,7 +213,8 @@ Feature: Search filter on collections
213213

214214
Scenario: Search collection by description (word_start)
215215
When I send a "GET" request to "/dummies?description=smart"
216-
Then the response status code should be 200
216+
Then print last JSON response
217+
And the response status code should be 200
217218
And the response should be in JSON
218219
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
219220
And the JSON should be valid according to this schema:

features/integration/fos_user.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Feature: FOSUser integration
1515
"plainPassword": "azerty"
1616
}
1717
"""
18-
Then the response status code should be 201
18+
Then print last JSON response
19+
And the response status code should be 201
1920
And the response should be in JSON
2021
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
2122
And the JSON should be equal to:

features/main/composite.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Feature: Retrieve data with Composite identifiers
1111
Then the response status code should be 200
1212
And the response should be in JSON
1313
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
14-
And the JSON should be equal to:
14+
And the JSON should be deep equal to:
1515
"""
1616
{
1717
"@context": "/contexts/CompositeItem",

features/main/uuid.feature

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ Feature: Using uuid identifier on resource
1010
"""
1111
{
1212
"name": "My Dummy",
13-
"uuid": "41B29566-144B-11E6-A148-3E1D05DEFE78"
13+
"uuid": "41b29566-144b-11e6-a148-3e1d05defe78"
1414
}
1515
"""
1616
Then the response status code should be 201
1717
And the response should be in JSON
1818
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
1919

2020
Scenario: Get a resource
21-
When I send a "GET" request to "/uuid_identifier_dummies/41B29566-144B-11E6-A148-3E1D05DEFE78"
21+
When I send a "GET" request to "/uuid_identifier_dummies/41b29566-144b-11e6-a148-3e1d05defe78"
2222
Then the response status code should be 200
2323
And the response should be in JSON
2424
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
2525
And the JSON should be equal to:
2626
"""
2727
{
2828
"@context": "/contexts/UuidIdentifierDummy",
29-
"@id": "/uuid_identifier_dummies/41B29566-144B-11E6-A148-3E1D05DEFE78",
29+
"@id": "/uuid_identifier_dummies/41b29566-144b-11e6-a148-3e1d05defe78",
3030
"@type": "UuidIdentifierDummy",
31-
"uuid": "41B29566-144B-11E6-A148-3E1D05DEFE78",
31+
"uuid": "41b29566-144b-11e6-a148-3e1d05defe78",
3232
"name": "My Dummy"
3333
}
3434
"""
@@ -46,9 +46,9 @@ Feature: Using uuid identifier on resource
4646
"@type": "hydra:Collection",
4747
"hydra:member": [
4848
{
49-
"@id": "/uuid_identifier_dummies/41B29566-144B-11E6-A148-3E1D05DEFE78",
49+
"@id": "/uuid_identifier_dummies/41b29566-144b-11e6-a148-3e1d05defe78",
5050
"@type": "UuidIdentifierDummy",
51-
"uuid": "41B29566-144B-11E6-A148-3E1D05DEFE78",
51+
"uuid": "41b29566-144b-11e6-a148-3e1d05defe78",
5252
"name": "My Dummy"
5353
}
5454
],
@@ -58,7 +58,7 @@ Feature: Using uuid identifier on resource
5858

5959
Scenario: Update a resource
6060
When I add "Content-Type" header equal to "application/ld+json"
61-
And I send a "PUT" request to "/uuid_identifier_dummies/41B29566-144B-11E6-A148-3E1D05DEFE78" with body:
61+
And I send a "PUT" request to "/uuid_identifier_dummies/41b29566-144b-11e6-a148-3e1d05defe78" with body:
6262
"""
6363
{
6464
"name": "My Dummy modified"
@@ -71,9 +71,9 @@ Feature: Using uuid identifier on resource
7171
"""
7272
{
7373
"@context": "/contexts/UuidIdentifierDummy",
74-
"@id": "/uuid_identifier_dummies/41B29566-144B-11E6-A148-3E1D05DEFE78",
74+
"@id": "/uuid_identifier_dummies/41b29566-144b-11e6-a148-3e1d05defe78",
7575
"@type": "UuidIdentifierDummy",
76-
"uuid": "41B29566-144B-11E6-A148-3E1D05DEFE78",
76+
"uuid": "41b29566-144b-11e6-a148-3e1d05defe78",
7777
"name": "My Dummy modified"
7878
}
7979
"""
@@ -99,6 +99,6 @@ Feature: Using uuid identifier on resource
9999

100100
@dropSchema
101101
Scenario: Delete a resource
102-
When I send a "DELETE" request to "/uuid_identifier_dummies/41B29566-144B-11E6-A148-3E1D05DEFE78"
102+
When I send a "DELETE" request to "/uuid_identifier_dummies/41b29566-144b-11e6-a148-3e1d05defe78"
103103
Then the response status code should be 204
104104
And the response should be empty

0 commit comments

Comments
 (0)