Skip to content

Commit bd72ef1

Browse files
feat(MPK-83): Add validation command (#1)
* feat(MPK-83): Add validation command * Create LICENSE * feat(MPK-83): Add docker and phpspec * feat(MPK-83): Add basic tests, phpcs and static analysis * feat(MPK-83): Fix static analysis * feat(MPK-83): Coverage is 100.00% - OK! * feat(MPK-83): Add command note to readme * feat(MPK-83): Fix interpreter line Signed-off-by: TiMESPLiNTER <github@timesplinter.ch> * feat(MPK-83): Better namespace for bin file Signed-off-by: TiMESPLiNTER <github@timesplinter.ch> * feat(MPK-83): Add infection testing Signed-off-by: TiMESPLiNTER <github@timesplinter.ch> * add circle config * Apply suggestions from code review * add shadow * fix circle * fix docker * feat(MPK-83): Add some more types Signed-off-by: TiMESPLiNTER <github@timesplinter.ch> * feat(MPK-83): Fix static analysis and coverage Signed-off-by: TiMESPLiNTER <github@timesplinter.ch> * feat(MPK-83): Fix coverage Signed-off-by: TiMESPLiNTER <github@timesplinter.ch> * feat(MPK-83): Added test for union type with sub schemas Signed-off-by: TiMESPLiNTER <github@timesplinter.ch> * feat(MPK-83): Added support for union type with sub schemas Signed-off-by: TiMESPLiNTER <github@timesplinter.ch> * feat(MPK-83): Improved handling of inlined schemas Signed-off-by: TiMESPLiNTER <github@timesplinter.ch> * feat(MPK-83): Make Stan happy Signed-off-by: TiMESPLiNTER <github@timesplinter.ch> * feat(MPK-83): Adjust MSIs 😏 Signed-off-by: TiMESPLiNTER <github@timesplinter.ch> * feat(MPK-83): Fix type determination Signed-off-by: TiMESPLiNTER <github@timesplinter.ch> * feat(MPK-83): Make Stan happy again Signed-off-by: TiMESPLiNTER <github@timesplinter.ch> Co-authored-by: Nick <nickjobszh@gmail.com>
1 parent 7fc496d commit bd72ef1

36 files changed

Lines changed: 5194 additions & 60 deletions

.circleci/config.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: 2.1
2+
3+
orbs:
4+
ci-caching: jobcloud/ci-caching@1.0.2
5+
ci-php: jobcloud/ci-php@0.29
6+
7+
workflows:
8+
test-avro-validator:
9+
jobs:
10+
- ci-caching/build-docker-images:
11+
dockerComposeFile: "./docker/docker-compose.yml"
12+
- ci-php/install-dependencies:
13+
dockerComposeFile: "./docker/docker-compose.yml"
14+
dependencyCheckSumFile: "./composer.json"
15+
requires:
16+
- ci-caching/build-docker-images
17+
- ci-php/coverage:
18+
dockerComposeFile: "./docker/docker-compose.yml"
19+
dependencyCheckSumFile: "./composer.json"
20+
requires:
21+
- ci-php/install-dependencies
22+
- ci-php/code-style:
23+
dockerComposeFile: "./docker/docker-compose.yml"
24+
dependencyCheckSumFile: "./composer.json"
25+
requires:
26+
- ci-php/install-dependencies
27+
- ci-php/static-analysis:
28+
dockerComposeFile: "./docker/docker-compose.yml"
29+
dependencyCheckSumFile: "./composer.json"
30+
requires:
31+
- ci-php/install-dependencies
32+
- ci-php/infection-testing:
33+
dockerComposeFile: "./docker/docker-compose.yml"
34+
dependencyCheckSumFile: "./composer.json"
35+
requires:
36+
- ci-php/install-dependencies

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea/
22
vendor/
3+
build/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 JobCloud AG
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
.PHONY: clean code-style coverage help test test-unit test-integration static-analysis infection-testing install-dependencies update-dependencies
2+
.DEFAULT_GOAL := help
3+
4+
PHPSPEC = ./vendor/bin/phpspec run --format dot -vvv -c phpspec.yml
5+
PHPSTAN = ./vendor/bin/phpstan
6+
PHPCS = ./vendor/bin/phpcs --extensions=php
7+
INFECTION = ./vendor/bin/infection
8+
CONSOLE = ./bin/console
9+
10+
clean:
11+
rm -rf ./build ./vendor
12+
13+
fix-code-style:
14+
${PHPCBF}
15+
16+
code-style:
17+
mkdir -p build/logs/phpcs
18+
${PHPCS}
19+
20+
coverage:
21+
mkdir -p build/logs/phpspec/coverage
22+
php -dpcov.enabled=1 -dpcov.directory=./src ${PHPSPEC}
23+
./vendor/bin/coverage-check build/logs/phpspec/coverage/coverage.xml 98
24+
25+
test: test-unit test-integration
26+
27+
test-unit:
28+
${PHPSPEC} --no-coverage
29+
30+
infection-testing:
31+
make coverage
32+
cp -f build/logs/phpspec/coverage/xml/index.xml build/logs/phpspec/coverage/junit.xml
33+
${INFECTION} --test-framework=phpspec --only-covered --coverage=build/logs/phpspec/coverage --min-msi=88 --threads=`nproc`
34+
35+
static-analysis:
36+
${PHPSTAN} analyse src --no-progress
37+
38+
install-dependencies:
39+
composer install
40+
41+
update-dependencies:
42+
composer update
43+
44+
help:
45+
# Usage:
46+
# make <target> [OPTION=value]
47+
#
48+
# Targets:
49+
# clean Cleans the coverage and the vendor directory
50+
# code-style Check code style using phpcs
51+
# coverage Generate code coverage (html, clover)
52+
# help You're looking at it!
53+
# test (default) Run all the tests
54+
# test-unit Run the unit tests with phpspec
55+
# static-analysis Run static analysis using phpstan
56+
# install-dependencies Run composer install
57+
# update-dependencies Run composer update

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,32 @@ var_dump($validator->validate(
1717
'marketplace.ecommerce.entity.order'
1818
));
1919
```
20+
21+
## Command
22+
There's a command making use of the validator shipped with this package:
23+
24+
```
25+
$ bin/avro-validator validate
26+
27+
Description:
28+
Validates a payload against a schema
29+
30+
Usage:
31+
validate [options] [--] <schema> <namespace> [<payload>]
32+
33+
Arguments:
34+
schema Path to the schema file
35+
namespace Schema namespace
36+
payload Path to the payload file
37+
38+
Options:
39+
-f, --format=FORMAT Output format of the result [default: "pretty"]
40+
-h, --help Display this help message
41+
-q, --quiet Do not output any message
42+
-V, --version Display this application version
43+
--ansi Force ANSI output
44+
--no-ansi Disable ANSI output
45+
-n, --no-interaction Do not ask any interactive question
46+
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
47+
```
48+

bin/avro-validator

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
declare(strict_types=1);
5+
6+
namespace Jobcloud\Avro\Validator\Bin;
7+
8+
use Jobcloud\Avro\Validator\Command\ValidateCommand;
9+
use Symfony\Component\Console\Application;
10+
use Symfony\Component\Console\Input\ArgvInput;
11+
use Symfony\Component\Console\Output\ConsoleOutput;
12+
13+
require __DIR__ . '/../vendor/autoload.php';
14+
15+
$app = new Application('Avro validator', '1.0');
16+
17+
$app->add(new ValidateCommand());
18+
19+
$app->run(new ArgvInput(), new ConsoleOutput());

composer.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
{
22
"name": "jobcloud/avro-validator",
3+
"license": "MIT",
4+
"require": {
5+
"php": ">=7.3",
6+
"ext-json": "*",
7+
"symfony/console": "^5.1.5"
8+
},
9+
"require-dev": {
10+
"ergebnis/phpstan-rules": "^0.14.3",
11+
"friends-of-phpspec/phpspec-code-coverage": "dev-master@dev",
12+
"phpspec/phpspec": "^6.2.1",
13+
"phpstan/phpstan": "^0.12.11",
14+
"phpstan/phpstan-deprecation-rules": "^0.12.2",
15+
"phpstan/phpstan-strict-rules": "^0.12.2",
16+
"rregeer/phpunit-coverage-check": "^0.3.1",
17+
"squizlabs/php_codesniffer": "^3.4.2",
18+
"infection/infection": "^0.17",
19+
"infection/phpspec-adapter": "^0.1.1"
20+
},
321
"autoload": {
422
"psr-4": {
523
"Jobcloud\\Avro\\Validator\\": "src/"
624
}
7-
}
25+
},
26+
"bin": ["bin/avro-validator"]
827
}

0 commit comments

Comments
 (0)