Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Pull in Helper from ergebnis/test-util #839

Merged
merged 1 commit into from Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions test/DataProvider/Command/NormalizeCommandProvider.php
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
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
@@ -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];
}
}