Skip to content

Commit

Permalink
Merge pull request #150 from ergebnis/feature/helper
Browse files Browse the repository at this point in the history
Enhancement: Pull in `Helper` from `ergebnis/test-util`
  • Loading branch information
localheinz authored Dec 13, 2021
2 parents 54f68a1 + fdf6417 commit ca2b3da
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 14 deletions.
4 changes: 2 additions & 2 deletions test/Unit/DecoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use Ergebnis\Json\SchemaValidator\Decoder;
use Ergebnis\Json\SchemaValidator\Exception;
use Ergebnis\Test\Util;
use Ergebnis\Json\SchemaValidator\Test;
use PHPUnit\Framework;

/**
Expand All @@ -27,7 +27,7 @@
*/
final class DecoderTest extends Framework\TestCase
{
use Util\Helper;
use Test\Util\Helper;

public function testDecodeAssociativeThrowsExceptionWhenValueCanNotBeDecoded(): void
{
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Exception/CanNotBeReadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Ergebnis\Json\SchemaValidator\Test\Unit\Exception;

use Ergebnis\Json\SchemaValidator\Exception;
use Ergebnis\Test\Util;
use Ergebnis\Json\SchemaValidator\Test;
use PHPUnit\Framework;

/**
Expand All @@ -24,7 +24,7 @@
*/
final class CanNotBeReadTest extends Framework\TestCase
{
use Util\Helper;
use Test\Util\Helper;

public function testFileReturnsException(): void
{
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Exception/DoesNotExistTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Ergebnis\Json\SchemaValidator\Test\Unit\Exception;

use Ergebnis\Json\SchemaValidator\Exception;
use Ergebnis\Test\Util;
use Ergebnis\Json\SchemaValidator\Test;
use PHPUnit\Framework;

/**
Expand All @@ -24,7 +24,7 @@
*/
final class DoesNotExistTest extends Framework\TestCase
{
use Util\Helper;
use Test\Util\Helper;

public function testFileReturnsException(): void
{
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Exception/InvalidJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Ergebnis\Json\SchemaValidator\Test\Unit\Exception;

use Ergebnis\Json\SchemaValidator\Exception;
use Ergebnis\Test\Util;
use Ergebnis\Json\SchemaValidator\Test;
use PHPUnit\Framework;

/**
Expand All @@ -24,7 +24,7 @@
*/
final class InvalidJsonTest extends Framework\TestCase
{
use Util\Helper;
use Test\Util\Helper;

public function testStringReturnsException(): void
{
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use Ergebnis\Json\SchemaValidator\Exception;
use Ergebnis\Json\SchemaValidator\Json;
use Ergebnis\Test\Util;
use Ergebnis\Json\SchemaValidator\Test;
use PHPUnit\Framework;

/**
Expand All @@ -28,7 +28,7 @@
*/
final class JsonTest extends Framework\TestCase
{
use Util\Helper;
use Test\Util\Helper;

public function testFromStringThrowsWhenValueIsNotJson(): void
{
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/ResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Ergebnis\Json\SchemaValidator\Test\Unit;

use Ergebnis\Json\SchemaValidator\Result;
use Ergebnis\Test\Util;
use Ergebnis\Json\SchemaValidator\Test;
use PHPUnit\Framework;

/**
Expand All @@ -24,7 +24,7 @@
*/
final class ResultTest extends Framework\TestCase
{
use Util\Helper;
use Test\Util\Helper;

public function testCreateReturnsResultWithoutErrors(): void
{
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Ergebnis\Json\SchemaValidator\Json;
use Ergebnis\Json\SchemaValidator\Schema;
use Ergebnis\Json\SchemaValidator\SchemaValidator;
use Ergebnis\Test\Util;
use Ergebnis\Json\SchemaValidator\Test;
use JsonSchema\Validator;
use PHPUnit\Framework;

Expand All @@ -33,7 +33,7 @@
*/
final class SchemaValidatorTest extends Framework\TestCase
{
use Util\Helper;
use Test\Util\Helper;

public function testValidateReturnsResultWhenDataIsNotValidAccordingToSchema(): void
{
Expand Down
38 changes: 38 additions & 0 deletions test/Util/Helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2021 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/json-schema-validator
*/

namespace Ergebnis\Json\SchemaValidator\Test\Util;

use Faker\Factory;
use Faker\Generator;

trait Helper
{
final protected static function faker(string $locale = 'en_US'): Generator
{
/**
* @var array<string, Generator>
*/
static $fakers = [];

if (!\array_key_exists($locale, $fakers)) {
$faker = Factory::create($locale);

$faker->seed(9001);

$fakers[$locale] = $faker;
}

return $fakers[$locale];
}
}

0 comments on commit ca2b3da

Please sign in to comment.