Skip to content

Commit

Permalink
feat(MPK-83): Add validation command (#1)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* feat(MPK-83): Better namespace for bin file

Signed-off-by: TiMESPLiNTER <[email protected]>

* feat(MPK-83): Add infection testing

Signed-off-by: TiMESPLiNTER <[email protected]>

* 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 <[email protected]>

* feat(MPK-83): Fix static analysis and coverage

Signed-off-by: TiMESPLiNTER <[email protected]>

* feat(MPK-83): Fix coverage

Signed-off-by: TiMESPLiNTER <[email protected]>

* feat(MPK-83): Added test for union type with sub schemas

Signed-off-by: TiMESPLiNTER <[email protected]>

* feat(MPK-83): Added support for union type with sub schemas

Signed-off-by: TiMESPLiNTER <[email protected]>

* feat(MPK-83): Improved handling of inlined schemas

Signed-off-by: TiMESPLiNTER <[email protected]>

* feat(MPK-83): Make Stan happy

Signed-off-by: TiMESPLiNTER <[email protected]>

* feat(MPK-83): Adjust MSIs 😏

Signed-off-by: TiMESPLiNTER <[email protected]>

* feat(MPK-83): Fix type determination

Signed-off-by: TiMESPLiNTER <[email protected]>

* feat(MPK-83): Make Stan happy again

Signed-off-by: TiMESPLiNTER <[email protected]>

Co-authored-by: Nick <[email protected]>
  • Loading branch information
TiMESPLiNTER and nick-zh authored Oct 22, 2020
1 parent 7fc496d commit bd72ef1
Show file tree
Hide file tree
Showing 36 changed files with 5,194 additions and 60 deletions.
36 changes: 36 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: 2.1

orbs:
ci-caching: jobcloud/[email protected]
ci-php: jobcloud/[email protected]

workflows:
test-avro-validator:
jobs:
- ci-caching/build-docker-images:
dockerComposeFile: "./docker/docker-compose.yml"
- ci-php/install-dependencies:
dockerComposeFile: "./docker/docker-compose.yml"
dependencyCheckSumFile: "./composer.json"
requires:
- ci-caching/build-docker-images
- ci-php/coverage:
dockerComposeFile: "./docker/docker-compose.yml"
dependencyCheckSumFile: "./composer.json"
requires:
- ci-php/install-dependencies
- ci-php/code-style:
dockerComposeFile: "./docker/docker-compose.yml"
dependencyCheckSumFile: "./composer.json"
requires:
- ci-php/install-dependencies
- ci-php/static-analysis:
dockerComposeFile: "./docker/docker-compose.yml"
dependencyCheckSumFile: "./composer.json"
requires:
- ci-php/install-dependencies
- ci-php/infection-testing:
dockerComposeFile: "./docker/docker-compose.yml"
dependencyCheckSumFile: "./composer.json"
requires:
- ci-php/install-dependencies
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea/
vendor/
build/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 JobCloud AG

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
57 changes: 57 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.PHONY: clean code-style coverage help test test-unit test-integration static-analysis infection-testing install-dependencies update-dependencies
.DEFAULT_GOAL := help

PHPSPEC = ./vendor/bin/phpspec run --format dot -vvv -c phpspec.yml
PHPSTAN = ./vendor/bin/phpstan
PHPCS = ./vendor/bin/phpcs --extensions=php
INFECTION = ./vendor/bin/infection
CONSOLE = ./bin/console

clean:
rm -rf ./build ./vendor

fix-code-style:
${PHPCBF}

code-style:
mkdir -p build/logs/phpcs
${PHPCS}

coverage:
mkdir -p build/logs/phpspec/coverage
php -dpcov.enabled=1 -dpcov.directory=./src ${PHPSPEC}
./vendor/bin/coverage-check build/logs/phpspec/coverage/coverage.xml 98

test: test-unit test-integration

test-unit:
${PHPSPEC} --no-coverage

infection-testing:
make coverage
cp -f build/logs/phpspec/coverage/xml/index.xml build/logs/phpspec/coverage/junit.xml
${INFECTION} --test-framework=phpspec --only-covered --coverage=build/logs/phpspec/coverage --min-msi=88 --threads=`nproc`

static-analysis:
${PHPSTAN} analyse src --no-progress

install-dependencies:
composer install

update-dependencies:
composer update

help:
# Usage:
# make <target> [OPTION=value]
#
# Targets:
# clean Cleans the coverage and the vendor directory
# code-style Check code style using phpcs
# coverage Generate code coverage (html, clover)
# help You're looking at it!
# test (default) Run all the tests
# test-unit Run the unit tests with phpspec
# static-analysis Run static analysis using phpstan
# install-dependencies Run composer install
# update-dependencies Run composer update
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,32 @@ var_dump($validator->validate(
'marketplace.ecommerce.entity.order'
));
```

## Command
There's a command making use of the validator shipped with this package:

```
$ bin/avro-validator validate
Description:
Validates a payload against a schema
Usage:
validate [options] [--] <schema> <namespace> [<payload>]
Arguments:
schema Path to the schema file
namespace Schema namespace
payload Path to the payload file
Options:
-f, --format=FORMAT Output format of the result [default: "pretty"]
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
```

19 changes: 19 additions & 0 deletions bin/avro-validator
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

namespace Jobcloud\Avro\Validator\Bin;

use Jobcloud\Avro\Validator\Command\ValidateCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;

require __DIR__ . '/../vendor/autoload.php';

$app = new Application('Avro validator', '1.0');

$app->add(new ValidateCommand());

$app->run(new ArgvInput(), new ConsoleOutput());
21 changes: 20 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
{
"name": "jobcloud/avro-validator",
"license": "MIT",
"require": {
"php": ">=7.3",
"ext-json": "*",
"symfony/console": "^5.1.5"
},
"require-dev": {
"ergebnis/phpstan-rules": "^0.14.3",
"friends-of-phpspec/phpspec-code-coverage": "dev-master@dev",
"phpspec/phpspec": "^6.2.1",
"phpstan/phpstan": "^0.12.11",
"phpstan/phpstan-deprecation-rules": "^0.12.2",
"phpstan/phpstan-strict-rules": "^0.12.2",
"rregeer/phpunit-coverage-check": "^0.3.1",
"squizlabs/php_codesniffer": "^3.4.2",
"infection/infection": "^0.17",
"infection/phpspec-adapter": "^0.1.1"
},
"autoload": {
"psr-4": {
"Jobcloud\\Avro\\Validator\\": "src/"
}
}
},
"bin": ["bin/avro-validator"]
}
Loading

0 comments on commit bd72ef1

Please sign in to comment.