-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from event-engine/feature/from-json-schema-file
Add fromJsonSchemaFile() and fromJsonSchema() method
- Loading branch information
Showing
8 changed files
with
141 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.idea | ||
composer.lock | ||
vendor | ||
vendor | ||
.php_cs.cache | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
$config = new Prooph\CS\Config\Prooph(); | ||
$config->getFinder()->in(__DIR__); | ||
|
||
$cacheDir = getenv('TRAVIS') ? getenv('HOME') . '/.php-cs-fixer' : __DIR__; | ||
|
||
$config->setCacheFile($cacheDir . '/.php_cs.cache'); | ||
|
||
return $config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of event-engine/php-json-schema. | ||
* (c) 2018-2021 prooph software GmbH <contact@prooph.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EventEngine\JsonSchema\Exception; | ||
|
||
final class CouldNotReadFileException extends RuntimeException | ||
{ | ||
public static function forFile(string $file): self | ||
{ | ||
return new self( | ||
\sprintf('Could not read "%s" file.', $file) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of event-engine/php-json-schema. | ||
* (c) 2018-2021 prooph software GmbH <contact@prooph.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EventEngine\JsonSchema\Exception; | ||
|
||
use RuntimeException as PhpRuntimeException; | ||
|
||
class RuntimeException extends PhpRuntimeException implements JsonSchemaException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of event-engine/php-json-schema. | ||
* (c) 2018-2021 prooph software GmbH <contact@prooph.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EventEngineTest\JsonSchema; | ||
|
||
use EventEngine\JsonSchema\Exception\CouldNotReadFileException; | ||
use EventEngine\JsonSchema\JsonSchemaArray; | ||
|
||
final class JsonSchemaArrayTest extends BasicTestCase | ||
{ | ||
private const FILE = __DIR__ . DIRECTORY_SEPARATOR . '_files/schema.json'; | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_creates_json_schema_from_file(): void | ||
{ | ||
$cut = JsonSchemaArray::fromFile(self::FILE); | ||
$this->assertArrayHasKey('properties', $cut->toArray()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_creates_json_schema_from_string(): void | ||
{ | ||
$cut = JsonSchemaArray::fromString(\file_get_contents(self::FILE)); | ||
$this->assertArrayHasKey('properties', $cut->toArray()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_throws_exception_if_file_is_not_found(): void | ||
{ | ||
$this->expectException(CouldNotReadFileException::class); | ||
JsonSchemaArray::fromFile('unknown.json'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "string" | ||
}, | ||
"name": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"id", | ||
"name" | ||
], | ||
"additionalProperties": false | ||
} |