Skip to content

Commit f2eb242

Browse files
authored
v0.1.0
2 parents 254c297 + 0815d4f commit f2eb242

File tree

75 files changed

+6934
-30
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+6934
-30
lines changed

.scrutinizer.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ build:
1515
tests:
1616
stop_on_failure: true
1717
override:
18-
- php-scrutinizer-run --enable-security-analysis
19-
- make codestyle
2018
-
2119
command: make coverage
2220
idle_timeout: 1200
2321
coverage:
2422
file: 'build/coverage/clover.xml'
2523
format: 'php-clover'
24+
- php-scrutinizer-run --enable-security-analysis
25+
- make codestyle
2626
cache:
2727
directories:
2828
- ~/.composer

.travis.yml

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
language: php
22

33
php:
4-
- '7.0'
54
- '7.1'
65
- '7.2'
6+
- '7.3'
77

88
env:
99
global:
1010
CI: 'true'
1111
TEST_OUTPUT_STYLE: 'pretty'
1212
PHPCS_REPORT_STYLE: 'full'
1313
COMPOSER_OPTIONS: '--optimize-autoloader'
14+
matrix:
15+
- SYMFONY_VERSION: '~3.0'
16+
- SYMFONY_VERSION: '~4.0'
1417

1518
sudo: false
1619

@@ -19,9 +22,10 @@ matrix:
1922

2023
before_install:
2124
# remove xdebug to speed up build
22-
- phpenv config-rm xdebug.ini
25+
- phpenv config-rm xdebug.ini || true
2326

2427
install:
28+
- composer require symfony/validator:$SYMFONY_VERSION
2529
- make build
2630
script:
2731
- make test-technical
@@ -31,3 +35,7 @@ cache:
3135
directories:
3236
- $HOME/.composer
3337
- vendor
38+
39+
branches:
40+
except:
41+
- /.*\-dev$/

Makefile

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ COVERAGE_OUTPUT_STYLE ?= html
66
BUILD_DIRECTORY ?= build
77
REPORTS_DIRECTORY ?= ${BUILD_DIRECTORY}/reports
88
COVERAGE_DIRECTORY ?= ${BUILD_DIRECTORY}/coverage
9+
BEHAT_COVERAGE_DIRECTORY ?= ${BUILD_DIRECTORY}/behat-coverage
910
COVERAGE_CLOVER_FILE_PATH ?= ${COVERAGE_DIRECTORY}/clover.xml
1011

1112
## Commands options
@@ -88,15 +89,21 @@ codestyle: create-reports-directory
8889
coverage: create-coverage-directory
8990
./vendor/bin/phpunit ${PHPUNIT_COLOR_OPTION} ${PHPUNIT_OUTPUT_STYLE_OPTION} ${PHPUNIT_COVERAGE_OPTION}
9091

92+
behat-coverage: create-behat-coverage-directory
93+
composer required leanphp/behat-code-coverage
94+
./vendor/bin/behat ${BEHAT_COLOR_OPTION} ${BEHAT_OUTPUT_STYLE_OPTION} --no-snippets --profile coverage
9195

9296

9397
# Internal commands
9498
create-coverage-directory:
9599
mkdir -p ${COVERAGE_DIRECTORY}
96100

101+
create-behat-coverage-directory:
102+
mkdir -p ${BEHAT_COVERAGE_DIRECTORY}
103+
97104
create-reports-directory:
98105
mkdir -p ${REPORTS_DIRECTORY}
99106

100107

101-
.PHONY: build install configure test test-technical test-functional codestyle coverage create-coverage-directory create-reports-directory
108+
.PHONY: build install configure test test-technical test-functional codestyle coverage behat-coverage create-coverage-directory create-behat-coverage-directory create-reports-directory
102109
.DEFAULT: build

README.md

+48-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,61 @@
11
# JSON-RPC params symfony constraint doc
2-
[![License](https://img.shields.io/github/license/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk.svg)](https://github.com/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk) [![Code size](https://img.shields.io/github/languages/code-size/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk.svg)](https://github.com/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk) [![PHP Versions](https://img.shields.io/badge/php-7.0%20%2F%207.1%20%2F%207.2-8892BF.svg)](https://php.net/)
2+
[![License](https://img.shields.io/github/license/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk.svg)](https://github.com/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk) [![Code size](https://img.shields.io/github/languages/code-size/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk.svg)](https://github.com/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk) [![Dependencies](https://img.shields.io/librariesio/github/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk.svg)](https://libraries.io/packagist/yoanm%2Fjsonrpc-params-symfony-constraint-doc-sdk)
33

4-
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk/?branch=master) [![Build Status](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk/badges/build.png?b=master)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk/build-status/master) [![Code Coverage](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk/?branch=master)
4+
[![Scrutinizer Build Status](https://img.shields.io/scrutinizer/build/g/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk.svg?label=Scrutinizer&logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk/build-status/master) [![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk/master.svg?logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk/?branch=master) [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk/master.svg?logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk/?branch=master)
55

6-
[![Travis Build Status](https://img.shields.io/travis/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk/master.svg?label=travis)](https://travis-ci.org/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk) [![Travis PHP versions](https://img.shields.io/travis/php-v/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk.svg)](https://travis-ci.org/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk)
6+
[![Travis Build Status](https://img.shields.io/travis/com/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk/master.svg?label=Travis&logo=travis)](https://travis-ci.com/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk) [![Travis PHP versions](https://img.shields.io/travis/php-v/yoanm/php-jsonrpc-params-symfony-constraint-doc-sdk.svg?logo=travis)](https://php.net/) [![Travis Symfony Versions](https://img.shields.io/badge/Symfony-v3%20%2F%20v4-8892BF.svg?logo=travis)](https://symfony.com/)
77

88
[![Latest Stable Version](https://img.shields.io/packagist/v/yoanm/jsonrpc-params-symfony-constraint-doc-sdk.svg)](https://packagist.org/packages/yoanm/jsonrpc-params-symfony-constraint-doc-sdk) [![Packagist PHP version](https://img.shields.io/packagist/php-v/yoanm/jsonrpc-params-symfony-constraint-doc-sdk.svg)](https://packagist.org/packages/yoanm/jsonrpc-params-symfony-constraint-doc-sdk)
99

1010
PHP SDK to generate JSON-RPC documentation from symfony constraint
1111

12+
See [yoanm/symfony-jsonrpc-params-sf-constraints-doc](https://github.com/yoanm/symfony-jsonrpc-params-sf-constraints-doc) for automatic dependency injection.
13+
1214
## How to use
1315

16+
Create the transformer :
17+
```php
18+
use Yoanm\JsonRpcParamsSymfonyConstraintDoc\App\Helper\ConstraintPayloadDocHelper;
19+
use Yoanm\JsonRpcParamsSymfonyConstraintDoc\App\Helper\DocTypeHelper;
20+
use Yoanm\JsonRpcParamsSymfonyConstraintDoc\App\Helper\MinMaxHelper;
21+
use Yoanm\JsonRpcParamsSymfonyConstraintDoc\App\Helper\StringDocHelper;
22+
use Yoanm\JsonRpcParamsSymfonyConstraintDoc\App\Helper\TypeGuesser;
23+
use Yoanm\JsonRpcParamsSymfonyConstraintDoc\Infra\Transformer\ConstraintToParamsDocTransformer;
24+
25+
$constraintPayloadDocHelper = new ConstraintPayloadDocHelper();
26+
27+
$transformer = new ConstraintToParamsDocTransformer(
28+
new DocTypeHelper(
29+
$constraintPayloadDocHelper,
30+
new TypeGuesser()
31+
),
32+
new StringDocHelper(),
33+
new MinMaxHelper(),
34+
$constraintPayloadDocHelper
35+
);
36+
```
37+
38+
Then use it with single constraint or a list of :
39+
```php
40+
use Symfony\Component\Validator\Constraints as ConstraintNS;
41+
use Yoanm\JsonRpcServerDoc\Domain\Model\Type\ObjectDoc;
42+
use Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc;
43+
44+
$constraint = new ConstraintNS\Collection([
45+
'a' => new ConstraintNS\Type('string'),
46+
'b' => new ConstraintNS\Type('integer'),
47+
'c' => new ConstraintNS\Type('bool')
48+
]);
49+
50+
/** @var ObjectDoc $constraintDoc */
51+
$constraintDoc = $transformer->transform($constraint);
52+
53+
/** @var StringDoc $constraintDoc2 */
54+
$constraintDoc2 = $transformer->transformList([
55+
new ConstraintNS\Type('string'),
56+
new ConstraintNS\NotNull()
57+
]);
58+
```
1459

1560
## Contributing
1661
See [contributing note](./CONTRIBUTING.md)

behat.yml

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,18 @@ default:
22
suites:
33
default:
44
contexts:
5-
- Tests\Functional\BehatContext\FeatureContext: ~
5+
- Tests\Functional\BehatContext\ConstraintTransformerContext: ~
6+
coverage:
7+
extensions:
8+
LeanPHP\Behat\CodeCoverage\Extension:
9+
drivers:
10+
- local
11+
filter:
12+
whitelist:
13+
include:
14+
directories:
15+
'src': ~
16+
report:
17+
format: html
18+
options:
19+
target: build/behat-coverage

composer.json

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "yoanm/jsonrpc-params-symfony-constraint-doc-sdk",
3-
"description": "Simple JSON-RPC params validator that use Symfony validator component",
3+
"description": "SDK to generate JSON-RPC documentation from symfony constraint",
44
"license": "MIT",
55
"type": "library",
66
"support": {
@@ -24,16 +24,20 @@
2424
"Tests\\Functional\\BehatContext\\": "features/bootstrap"
2525
}
2626
},
27+
"suggest": {
28+
"yoanm/symfony-jsonrpc-params-sf-constraints-doc": "Symfony bundle for easy Symfony constraints to JSON-RPC documentation transformation",
29+
"yoanm/symfony-jsonrpc-http-server-doc": "Symfony bundle for easy JSON-RPC server documentation",
30+
"yoanm/symfony-jsonrpc-http-server": "Symfony Bundle to convert an HTTP json-rpc request into HTTP json-rpc response"
31+
},
2732
"require": {
28-
"php": ">=7.0",
29-
"yoanm/jsonrpc-server-doc-sdk": "dev-release/1.0.0",
33+
"php": ">=7.1",
34+
"yoanm/jsonrpc-server-doc-sdk": "v0.1.0",
3035
"symfony/validator": "^3.0 || ^4.0"
3136
},
3237
"require-dev": {
3338
"behat/behat": "~3.0",
3439
"squizlabs/php_codesniffer": "3.*",
3540
"phpunit/phpunit": "^6.0 || ^7.0",
3641
"yoanm/php-unit-extended": "^1.0"
37-
},
38-
"minimum-stability": "dev"
42+
}
3943
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
Feature: ConstraintToParamsDocTransformer - NotBlank & Blank constraints
2+
3+
Scenario: Simple NotBlank constraint
4+
Given I have the following Constraint:
5+
"""
6+
use Symfony\Component\Validator\Constraints as ConstraintNS;
7+
return new ConstraintNS\NotBlank();
8+
"""
9+
When I transform constraint
10+
Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\TypeDoc"
11+
## Check others properties
12+
And constraint doc "getName" should return null
13+
And constraint doc "getDescription" should return null
14+
And constraint doc "getDefault" should return null
15+
And constraint doc "getExample" should return null
16+
And constraint doc "isRequired" should return false
17+
And constraint doc "isNullable" should return true
18+
19+
Scenario: Simple NotBlank constraint with string type specified
20+
Given I have the following Constraint:
21+
"""
22+
use Symfony\Component\Validator\Constraints as ConstraintNS;
23+
return new ConstraintNS\NotBlank([
24+
'payload' => [
25+
'documentation' => [
26+
'type' => 'string'
27+
]
28+
]
29+
]);
30+
"""
31+
When I transform constraint
32+
Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc"
33+
And constraint doc "getMinLength" should return the number 1
34+
## Check others properties
35+
And constraint doc "getName" should return null
36+
And constraint doc "getDescription" should return null
37+
And constraint doc "getDefault" should return null
38+
And constraint doc "getExample" should return null
39+
And constraint doc "isRequired" should return false
40+
And constraint doc "isNullable" should return true
41+
And constraint doc "getAllowedValueList" should return an empty array
42+
And constraint doc "getFormat" should return null
43+
And constraint doc "getMaxLength" should return null
44+
45+
Scenario: Simple NotBlank constraint with array type specified
46+
Given I have the following Constraint:
47+
"""
48+
use Symfony\Component\Validator\Constraints as ConstraintNS;
49+
return new ConstraintNS\NotBlank([
50+
'payload' => [
51+
'documentation' => [
52+
'type' => 'array'
53+
]
54+
]
55+
]);
56+
"""
57+
When I transform constraint
58+
Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\ArrayDoc"
59+
And constraint doc "getMinItem" should return the number 1
60+
## Check others properties
61+
And constraint doc "getName" should return null
62+
And constraint doc "getDescription" should return null
63+
And constraint doc "getDefault" should return null
64+
And constraint doc "getExample" should return null
65+
And constraint doc "isRequired" should return false
66+
And constraint doc "isNullable" should return true
67+
And constraint doc "getAllowedValueList" should return an empty array
68+
And constraint doc "getSiblingList" should return an empty array
69+
And constraint doc "getMaxItem" should return null
70+
And constraint doc "isAllowExtraSibling" should return false
71+
And constraint doc "isAllowMissingSibling" should return false
72+
And constraint doc "getItemValidation" should return null
73+
74+
Scenario: Simple Blank constraint with string type specified
75+
Given I have the following Constraint:
76+
"""
77+
use Symfony\Component\Validator\Constraints as ConstraintNS;
78+
return new ConstraintNS\Blank([
79+
'payload' => [
80+
'documentation' => [
81+
'type' => 'string'
82+
]
83+
]
84+
]);
85+
"""
86+
When I transform constraint
87+
Then I should have a constraint doc of class "Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc"
88+
And constraint doc "getMaxLength" should return the number 0
89+
## Check others properties
90+
And constraint doc "getName" should return null
91+
And constraint doc "getDescription" should return null
92+
And constraint doc "getDefault" should return null
93+
And constraint doc "getExample" should return null
94+
And constraint doc "isRequired" should return false
95+
And constraint doc "isNullable" should return true
96+
And constraint doc "getAllowedValueList" should return an empty array
97+
And constraint doc "getFormat" should return null
98+
And constraint doc "getMinLength" should return null

0 commit comments

Comments
 (0)