Skip to content

Commit

Permalink
Merge pull request #580 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 28, 2021
2 parents 05645bd + f893bfe commit 2daf23a
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 16 deletions.
4 changes: 2 additions & 2 deletions test/Unit/AbstractNormalizerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@

namespace Ergebnis\Json\Normalizer\Test\Unit;

use Ergebnis\Json\Normalizer\Test;
use Ergebnis\Json\Printer;
use Ergebnis\Test\Util\Helper;
use PHPUnit\Framework;

/**
* @internal
*/
abstract class AbstractNormalizerTestCase extends Framework\TestCase
{
use Helper;
use Test\Util\Helper;

final protected function className(): string
{
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Exception/AbstractExceptionTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

namespace Ergebnis\Json\Normalizer\Test\Unit\Exception;

use Ergebnis\Test\Util\Helper;
use Ergebnis\Json\Normalizer\Test;
use PHPUnit\Framework;

/**
* @internal
*/
abstract class AbstractExceptionTestCase extends Framework\TestCase
{
use Helper;
use Test\Util\Helper;

final protected function className(): string
{
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Format/FormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
use Ergebnis\Json\Normalizer\Format\JsonEncodeOptions;
use Ergebnis\Json\Normalizer\Format\NewLine;
use Ergebnis\Json\Normalizer\Json;
use Ergebnis\Json\Normalizer\Test;
use Ergebnis\Json\Printer;
use Ergebnis\Test\Util\Helper;
use PHPUnit\Framework;

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

/**
* @dataProvider \Ergebnis\Json\Normalizer\Test\DataProvider\Boolean::provideBoolean()
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Format/IndentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Ergebnis\Json\Normalizer\Exception;
use Ergebnis\Json\Normalizer\Format\Indent;
use Ergebnis\Json\Normalizer\Json;
use Ergebnis\Test\Util\Helper;
use Ergebnis\Json\Normalizer\Test;
use PHPUnit\Framework;

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

public function testConstants(): void
{
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Format/JsonEncodeOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Ergebnis\Json\Normalizer\Exception;
use Ergebnis\Json\Normalizer\Format\JsonEncodeOptions;
use Ergebnis\Json\Normalizer\Json;
use Ergebnis\Test\Util\Helper;
use Ergebnis\Json\Normalizer\Test;
use PHPUnit\Framework;

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

/**
* @dataProvider provideInvalidValue
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Ergebnis\Json\Normalizer\Exception;
use Ergebnis\Json\Normalizer\Format\Format;
use Ergebnis\Json\Normalizer\Json;
use Ergebnis\Test\Util\Helper;
use Ergebnis\Json\Normalizer\Test;
use PHPUnit\Framework;

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

public function testFromEncodedRejectsInvalidEncoded(): void
{
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Validator/ResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace Ergebnis\Json\Normalizer\Test\Unit\Validator;

use Ergebnis\Json\Normalizer\Test;
use Ergebnis\Json\Normalizer\Validator\Result;
use Ergebnis\Test\Util\Helper;
use PHPUnit\Framework;

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

public function testCreateReturnsResultWithoutErrors(): void
{
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Validator/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace Ergebnis\Json\Normalizer\Test\Unit\Validator;

use Ergebnis\Json\Normalizer\Test;
use Ergebnis\Json\Normalizer\Validator\SchemaValidator;
use Ergebnis\Test\Util\Helper;
use JsonSchema\Validator;
use PHPUnit\Framework;

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

/**
* @dataProvider \Ergebnis\Json\Normalizer\Test\DataProvider\Boolean::provideBoolean()
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) 2018-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-normalizer
*/

namespace Ergebnis\Json\Normalizer\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 2daf23a

Please sign in to comment.