Skip to content

Commit

Permalink
Merge pull request #839 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 committed Dec 28, 2021
2 parents f09e2b6 + 0360ad0 commit 7a94c83
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
3 changes: 1 addition & 2 deletions test/DataProvider/Command/NormalizeCommandProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@

use Ergebnis\Composer\Normalize\Test;
use Ergebnis\Json\Normalizer\Format;
use Ergebnis\Test\Util;

final class NormalizeCommandProvider
{
use Util\Helper;
use Test\Util\Helper;

/**
* @return \Generator<string, array{0: Test\Util\CommandInvocation}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Ergebnis\Composer\Normalize\Command\NormalizeCommand;
use Ergebnis\Composer\Normalize\NormalizePlugin;
use Ergebnis\Composer\Normalize\Test;
use Ergebnis\Test\Util;
use PHPUnit\Framework;
use Symfony\Component\Console;
use Symfony\Component\Filesystem;
Expand All @@ -29,7 +28,7 @@
*/
abstract class AbstractTestCase extends Framework\TestCase
{
use Util\Helper;
use Test\Util\Helper;

/**
* @var string
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/composer-normalize
*/

namespace Ergebnis\Composer\Normalize\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 7a94c83

Please sign in to comment.