Skip to content

Commit 5fb5f24

Browse files
committed
Add exceptions
1 parent 8d28de0 commit 5fb5f24

14 files changed

+312
-1
lines changed

.codeclimate.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
plugins:
2+
phpmd:
3+
enabled: true
4+
config:
5+
file_extensions: "php"
6+
rulesets: "phpmd.xml"
7+
phpcodesniffer:
8+
enabled: true
9+
phan:
10+
enabled: true
11+
config:
12+
file_extensions: "php"
13+
ignore-undeclared: true
14+
sonar-php:
15+
enabled: true
16+
config:
17+
tests_patterns:
18+
- test/**

.coveralls.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
service_name: travis-ci
2+
coverage_clover: build/logs/clover.xml
3+
json_path: build/logs/coveralls-upload.json

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/
2+
.idea

.travis.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
language: php
2+
3+
sudo: false
4+
5+
env:
6+
global:
7+
- CC_TEST_REPORTER_ID=2b80bd2ec5f490c696587eee4700043e73733cf9bca1ff61dade1eb0b96e6e9c
8+
9+
php:
10+
- 7.2
11+
- 7.3
12+
- 7.4snapshot
13+
14+
install:
15+
# Install coveralls.phar
16+
- wget -c -nc --retry-connrefused --tries=0 https://github.com/php-coveralls/php-coveralls/releases/download/v2.0.0/php-coveralls.phar -O coveralls.phar
17+
- chmod +x coveralls.phar
18+
- php coveralls.phar --version
19+
# install codeclimate test reporter
20+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
21+
- chmod +x ./cc-test-reporter
22+
- ./cc-test-reporter before-build
23+
24+
before_script:
25+
- composer self-update || true
26+
- composer install
27+
- mkdir -p build/logs
28+
29+
script:
30+
- ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml --testdox
31+
32+
after_script:
33+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
34+
- travis_retry php coveralls.phar -v
35+
- vendor/bin/test-reporter
36+
37+
cache:
38+
directories:
39+
- vendor
40+
- $COMPOSER_CACHE_DIR

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) 2019 wol-soft
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.

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1+
[![Latest Version](https://img.shields.io/packagist/v/wol-soft/php-json-schema-model-generator-exception.svg)](https://packagist.org/packages/wol-soft/php-json-schema-model-generator-exception)
2+
[![Maintainability](https://api.codeclimate.com/v1/badges/9e3c565c528edb3d58d5/maintainability)](https://codeclimate.com/github/wol-soft/php-json-schema-model-generator-exception/maintainability)
3+
[![Test Coverage](https://api.codeclimate.com/v1/badges/7eb29e7366dc3d6a5f44/test_coverage)](https://codeclimate.com/github/wol-soft/php-json-schema-model-generator-exception/test_coverage)
4+
[![Build Status](https://travis-ci.org/wol-soft/php-micro-template.svg?branch=master)](https://travis-ci.org/wol-soft/php-json-schema-model-generator-exception)
5+
[![Coverage Status](https://coveralls.io/repos/github/wol-soft/php-json-schema-model-generator-exception/badge.svg?branch=master)](https://coveralls.io/github/wol-soft/php-json-schema-model-generator-exception?branch=master)
6+
[![MIT License](https://img.shields.io/packagist/l/wol-soft/php-micro-template.svg)](https://github.com/wol-soft/php-json-schema-model-generator-exception/blob/master/LICENSE)
7+
18
# php-json-schema-model-generator-interface
2-
Provides interfaces to use php-json-schema-model-generator as dev dependency
9+
Provides exceptions and interfaces to use [php-json-schema-model-generator](https://github.com/wol-soft/php-json-schema-model-generator) as dev dependency (recommended workflow)

composer.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "wol-soft/php-json-schema-model-generator-exception",
3+
"homepage": "https://github.com/wol-soft/php-json-schema-model-generator-exception",
4+
"description": "Provides exceptions to use php-json-schema-model-generator as dev dependency\n\n",
5+
"type": "library",
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Enno Woortmann",
10+
"email": "[email protected]"
11+
}
12+
],
13+
"require": {
14+
"php": ">=7.2"
15+
},
16+
"require-dev": {
17+
"phpunit/phpunit": "^8.0"
18+
},
19+
"autoload": {
20+
"psr-4": {
21+
"PHPModelGeneratorException\\": "src"
22+
}
23+
},
24+
"autoload-dev": {
25+
"psr-4": {
26+
"PHPModelGeneratorException\\Tests\\": "tests"
27+
}
28+
}
29+
}

phpmd.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<ruleset>
3+
<description>Custom ruleset for code standards</description>
4+
5+
<rule ref="rulesets/cleancode.xml" />
6+
<rule ref="rulesets/codesize.xml" />
7+
<rule ref="rulesets/controversial.xml" />
8+
<rule ref="rulesets/design.xml" />
9+
<rule ref="rulesets/naming.xml">
10+
<exclude name="LongVariable" />
11+
</rule>
12+
<rule ref="rulesets/unusedcode.xml" />
13+
14+
</ruleset>

phpunit.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false">
11+
12+
<testsuite name="PHPModelGeneratorException">
13+
<directory>tests</directory>
14+
</testsuite>
15+
16+
<filter>
17+
<whitelist>
18+
<directory>src</directory>
19+
</whitelist>
20+
</filter>
21+
</phpunit>

src/ErrorRegistryException.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace PHPModelGeneratorException;
6+
7+
use Exception;
8+
9+
/**
10+
* Class ErrorRegistryException
11+
*
12+
* @package PHPModelGeneratorException
13+
*/
14+
class ErrorRegistryException extends Exception implements ErrorRegistryExceptionInterface
15+
{
16+
protected $errors = [];
17+
18+
/**
19+
* @inheritdoc
20+
*/
21+
public function addError(string $message): ErrorRegistryExceptionInterface
22+
{
23+
$this->errors[] = $message;
24+
25+
$this->message = join("\n", $this->errors);
26+
27+
return $this;
28+
}
29+
30+
/**
31+
* @inheritdoc
32+
*/
33+
public function getErrors(): array
34+
{
35+
return $this->errors;
36+
}
37+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace PHPModelGeneratorException;
6+
7+
use Throwable;
8+
9+
/**
10+
* Interface ErrorRegistryExceptionInterface
11+
*
12+
* @package PHPModelGeneratorException
13+
*/
14+
interface ErrorRegistryExceptionInterface extends Throwable
15+
{
16+
/**
17+
* Add an error to the error registry
18+
*
19+
* @param string $message
20+
*
21+
* @return $this
22+
*/
23+
public function addError(string $message): self;
24+
25+
/**
26+
* Get all errors
27+
*
28+
* @return array
29+
*/
30+
public function getErrors(): array;
31+
}

src/ValidationException.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace PHPModelGeneratorException;
6+
7+
use Exception;
8+
9+
/**
10+
* Class ValidationException
11+
*
12+
* @package PHPModelGeneratorException
13+
*/
14+
class ValidationException extends Exception
15+
{
16+
}

tests/ErrorRegistryExceptionTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace PHPModelGeneratorException\Tests;
4+
5+
use PHPModelGeneratorException\ErrorRegistryException;
6+
use PHPUnit\Framework\TestCase;
7+
8+
/**
9+
* Class ErrorRegistryExceptionTest
10+
*
11+
* @package PHPModelGeneratorException\Tests
12+
*/
13+
class ErrorRegistryExceptionTest extends TestCase
14+
{
15+
/**
16+
* @throws ErrorRegistryException
17+
*/
18+
public function testErrorRegistryExceptionIsThrowable(): void
19+
{
20+
$this->expectException(ErrorRegistryException::class);
21+
22+
throw new ErrorRegistryException();
23+
}
24+
25+
/**
26+
* @throws ErrorRegistryException
27+
*/
28+
public function testErrorRegistryExceptionCollectsMessages(): void
29+
{
30+
$messages = [
31+
'Error Message 1',
32+
'Error Message 2',
33+
];
34+
35+
$this->expectException(ErrorRegistryException::class);
36+
$this->expectExceptionMessage(join("\n", $messages));
37+
38+
$errorRegistry = new ErrorRegistryException();
39+
40+
foreach ($messages as $message) {
41+
$errorRegistry->addError($message);
42+
}
43+
44+
$this->assertSame($messages, $errorRegistry->getErrors());
45+
46+
throw $errorRegistry;
47+
}
48+
}

tests/ValidationExceptionTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace PHPModelGeneratorException\Tests;
4+
5+
use PHPModelGeneratorException\ValidationException;
6+
use PHPUnit\Framework\TestCase;
7+
8+
/**
9+
* Class ValidationExceptionTest
10+
*
11+
* @package PHPModelGeneratorException\Tests
12+
*/
13+
class ValidationExceptionTest extends TestCase
14+
{
15+
/**
16+
* @throws ValidationException
17+
*/
18+
public function testValidationExceptionIsThrowable(): void
19+
{
20+
$this->expectException(ValidationException::class);
21+
22+
throw new ValidationException();
23+
}
24+
}

0 commit comments

Comments
 (0)