Skip to content

Commit 8afe4bd

Browse files
authored
Add FT (#3)
1 parent 0b932c2 commit 8afe4bd

File tree

17 files changed

+520
-14
lines changed

17 files changed

+520
-14
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ vendor
22
build
33
#A library must not provide a composer.lock file
44
composer.lock
5+
6+
features/demo_app/var

behat.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ default:
22
suites:
33
default:
44
contexts:
5-
- Tests\Functional\BehatContext\FeatureContext: ~
5+
- Tests\Functional\BehatContext\DemoAppContext: ~

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"autoload-dev": {
2323
"psr-4": {
2424
"Tests\\": "tests",
25-
"Tests\\Functional\\BehatContext\\": "features/bootstrap"
25+
"Tests\\Functional\\BehatContext\\": "features/bootstrap",
26+
"DemoApp\\": "features/demo_app/src"
2627
}
2728
},
2829
"require": {
@@ -40,6 +41,7 @@
4041
"phpunit/phpunit": "^6.0 || ^7.0",
4142
"matthiasnoback/symfony-dependency-injection-test": "^2.0 || ^3.0",
4243
"matthiasnoback/symfony-config-test": "^3.0 || ^4.0",
44+
"symfony/framework-bundle": "^3.0 || ^4.0",
4345
"yoanm/php-unit-extended": "~1.0"
4446
}
4547
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
namespace Tests\Functional\BehatContext;
3+
4+
use Behat\Behat\Context\Context;
5+
6+
class AbstractContext implements Context
7+
{
8+
protected function jsonDecode($encodedData)
9+
{
10+
$decoded = json_decode($encodedData, true);
11+
12+
if (JSON_ERROR_NONE != json_last_error()) {
13+
throw new \Exception(
14+
json_last_error_msg(),
15+
json_last_error()
16+
);
17+
}
18+
19+
return $decoded;
20+
}
21+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
namespace Tests\Functional\BehatContext;
3+
4+
use Behat\Gherkin\Node\PyStringNode;
5+
use DemoApp\AbstractKernel;
6+
use DemoApp\DefaultKernel;
7+
use PHPUnit\Framework\Assert;
8+
use Symfony\Component\HttpFoundation\Request;
9+
use Symfony\Component\HttpFoundation\Response;
10+
11+
/**
12+
* Defines application features from the specific context.
13+
*/
14+
class DemoAppContext extends AbstractContext
15+
{
16+
/** @var Response|null */
17+
private $lastResponse;
18+
19+
/**
20+
* @When I send a :httpMethod request on :uri demoApp kernel endpoint
21+
* @When I send following :httpMethod input on :uri demoApp kernel endpoint:
22+
*/
23+
public function whenISendFollowingPayloadToDemoApp($httpMethod, $uri, PyStringNode $payload = null)
24+
{
25+
$this->lastResponse = null;
26+
27+
$kernel = $this->getDemoAppKernel();
28+
$kernel->boot();
29+
$request = Request::create($uri, $httpMethod, [], [], [], [], $payload ? $payload->getRaw() : null);
30+
$this->lastResponse = $kernel->handle($request);
31+
$kernel->terminate($request, $this->lastResponse);
32+
$kernel->shutdown();
33+
}
34+
35+
/**
36+
* @Then I should have a :httpCode response from demoApp with following content:
37+
*/
38+
public function thenIShouldHaveAResponseFromDemoAppWithFollowingContent($httpCode, PyStringNode $payload)
39+
{
40+
Assert::assertInstanceOf(Response::class, $this->lastResponse);
41+
// Decode payload to get ride of indentation, spacing, etc
42+
Assert::assertEquals(
43+
$this->jsonDecode($payload->getRaw()),
44+
$this->jsonDecode($this->lastResponse->getContent())
45+
);
46+
Assert::assertSame((int) $httpCode, $this->lastResponse->getStatusCode());
47+
}
48+
49+
/**
50+
* @return AbstractKernel
51+
*/
52+
protected function getDemoAppKernel()
53+
{
54+
$env = 'prod';
55+
$debug = true;
56+
$kernelClass = DefaultKernel::class;
57+
58+
return new $kernelClass($env, $debug);
59+
}
60+
}

features/bootstrap/FeatureContext.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

features/bundle.feature

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
Feature: demo symfony application
2+
3+
Scenario: Check that all methods are available
4+
# Ensure params doc is present
5+
When I send a "GET" request on "/my-custom-doc-endpoint" demoApp kernel endpoint
6+
Then I should have a "200" response from demoApp with following content:
7+
"""
8+
{
9+
"methods": [
10+
{
11+
"identifier": "BundledMethodA",
12+
"name": "bundledMethodA",
13+
"params": {
14+
"type": "object",
15+
"nullable": false,
16+
"required": true,
17+
"siblings": {
18+
"a": {
19+
"type": "string",
20+
"nullable": true,
21+
"required": true
22+
},
23+
"b": {
24+
"type": "integer",
25+
"nullable": true,
26+
"required": true
27+
}
28+
}
29+
}
30+
},
31+
{
32+
"identifier": "BundledMethodB",
33+
"name": "bundledMethodB"
34+
},
35+
{
36+
"identifier": "BundledMethodC",
37+
"name": "bundledMethodC",
38+
"params": {
39+
"type": "object",
40+
"nullable": false,
41+
"required": true,
42+
"siblings": {
43+
"a": {
44+
"type": "array",
45+
"nullable": true,
46+
"required": true,
47+
"item_validation": {
48+
"type": "integer",
49+
"nullable": true,
50+
"required": false
51+
}
52+
}
53+
}
54+
}
55+
}
56+
],
57+
"errors": [
58+
{
59+
"id": "ParseError-32700",
60+
"title": "Parse error",
61+
"type": "object",
62+
"properties": {
63+
"code": -32700
64+
}
65+
},
66+
{
67+
"id": "InvalidRequest-32600",
68+
"title": "Invalid request",
69+
"type": "object",
70+
"properties": {
71+
"code": -32600
72+
}
73+
},
74+
{
75+
"id": "MethodNotFound-32601",
76+
"title": "Method not found",
77+
"type": "object",
78+
"properties": {
79+
"code": -32601
80+
}
81+
},
82+
{
83+
"id": "ParamsValidationsError-32602",
84+
"title": "Params validations error",
85+
"type": "object",
86+
"properties": {
87+
"code": -32602,
88+
"data": {
89+
"type": "object",
90+
"nullable": true,
91+
"required": true,
92+
"siblings": {
93+
"violations": {
94+
"type": "array",
95+
"nullable": true,
96+
"required": false,
97+
"item_validation": {
98+
"type": "object",
99+
"nullable": true,
100+
"required": true,
101+
"siblings": {
102+
"path": {
103+
"type": "string",
104+
"nullable": true,
105+
"required": true,
106+
"example": "[key]"
107+
},
108+
"message": {
109+
"type": "string",
110+
"nullable": true,
111+
"required": true
112+
},
113+
"code": {
114+
"type": "string",
115+
"nullable": true,
116+
"required": false
117+
}
118+
}
119+
}
120+
}
121+
}
122+
}
123+
}
124+
},
125+
{
126+
"id": "InternalError-32603",
127+
"title": "Internal error",
128+
"type": "object",
129+
"properties": {
130+
"code": -32603,
131+
"data": {
132+
"type": "object",
133+
"nullable": true,
134+
"required": false,
135+
"siblings": {
136+
"previous": {
137+
"type": "string",
138+
"nullable": true,
139+
"required": false,
140+
"description": "Previous error message"
141+
}
142+
}
143+
}
144+
}
145+
}
146+
],
147+
"http": {
148+
"host": "localhost"
149+
}
150+
}
151+
"""
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
return [
3+
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
4+
Yoanm\SymfonyJsonRpcHttpServer\JsonRpcHttpServerBundle::class => ['all' => true],
5+
Yoanm\SymfonyJsonRpcHttpServerDoc\JsonRpcHttpServerDocBundle::class => ['all' => true],
6+
Yoanm\SymfonyJsonRpcParamsSfConstraintsDoc\JsonRpcParamsSfConstraintsDocBundle::class => ['all' => true],
7+
];
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
framework:
2+
secret: '%env(APP_SECRET)%'
3+
4+
json_rpc_http_server:
5+
endpoint: '/my-custom-endpoint'
6+
7+
json_rpc_http_server_doc:
8+
endpoint: '/my-custom-doc-endpoint'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Import default configuration or write your own
2+
json-rpc-endpoint:
3+
resource: '@JsonRpcHttpServerBundle/Resources/config/routing/endpoint.xml'
4+
5+
json-rpc-endpoint-doc:
6+
resource: '@JsonRpcHttpServerDocBundle/Resources/config/routing/endpoint.xml'

0 commit comments

Comments
 (0)