Skip to content

Commit

Permalink
Merge pull request #551 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 Jan 14, 2022
2 parents 98ae5b0 + 2427b2f commit 801a4e0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
3 changes: 1 addition & 2 deletions test/Unit/FactoryTest.php
Expand Up @@ -15,7 +15,6 @@

use Ergebnis\PhpCsFixer\Config\Factory;
use Ergebnis\PhpCsFixer\Config\Test;
use Ergebnis\Test\Util;
use PHPUnit\Framework;

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

public function testFromRuleSetThrowsRuntimeExceptionIfCurrentPhpVersionIsLessThanTargetPhpVersion(): void
{
Expand Down
38 changes: 38 additions & 0 deletions test/Util/Helper.php
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2019-2022 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/php-cs-fixer-config
*/

namespace Ergebnis\PhpCsFixer\Config\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 801a4e0

Please sign in to comment.