Skip to content

Commit

Permalink
Merge pull request #462 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 30, 2021
2 parents c260c33 + ba2413b commit 9b9af4e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 8 deletions.
4 changes: 2 additions & 2 deletions test/Unit/ConstructTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Ergebnis\Classy\Test\Unit;

use Ergebnis\Classy\Construct;
use Ergebnis\Test\Util\Helper;
use Ergebnis\Classy\Test;
use PHPUnit\Framework;

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

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

use Ergebnis\Classy\Exception\DirectoryDoesNotExist;
use Ergebnis\Classy\Exception\ExceptionInterface;
use Ergebnis\Test\Util\Helper;
use Ergebnis\Classy\Test;
use PHPUnit\Framework;

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

public function testFromDirectoryReturnsException(): void
{
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Exception/MultipleDefinitionsFoundTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Ergebnis\Classy\Construct;
use Ergebnis\Classy\Exception\ExceptionInterface;
use Ergebnis\Classy\Exception\MultipleDefinitionsFound;
use Ergebnis\Test\Util\Helper;
use Ergebnis\Classy\Test;
use PHPUnit\Framework;

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

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

use Ergebnis\Classy\Exception\ExceptionInterface;
use Ergebnis\Classy\Exception\ParseError;
use Ergebnis\Test\Util\Helper;
use Ergebnis\Classy\Test;
use PHPUnit\Framework;

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

public function testFromParseErrorReturnsException(): 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) 2017-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/classy
*/

namespace Ergebnis\Classy\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 9b9af4e

Please sign in to comment.