Skip to content

Commit

Permalink
Enhancement: Pull in Helper from ergebnis/test-util
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Nov 28, 2021
1 parent d1aeb50 commit 8cb78fe
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 28 deletions.
4 changes: 2 additions & 2 deletions test/Example/SleeperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Example;

use Ergebnis\Test\Util;
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Framework;

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

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

use Ergebnis\PHPUnit\SlowTestDetector\Collector\DefaultCollector;
use Ergebnis\PHPUnit\SlowTestDetector\SlowTest;
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use Ergebnis\PHPUnit\SlowTestDetector\Test\Example;
use Ergebnis\Test\Util;
use PHPUnit\Event;
use PHPUnit\Framework;

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

public function testDefaults(): void
{
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Comparator/DurationComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Unit\Comparator;

use Ergebnis\PHPUnit\SlowTestDetector\Comparator\DurationComparator;
use Ergebnis\Test\Util;
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Event;
use PHPUnit\Framework;

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

public function testReturnsMinusOneWhenOneIsLessThanTwo(): void
{
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Console/ColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Unit\Console;

use Ergebnis\PHPUnit\SlowTestDetector\Console\Color;
use Ergebnis\Test\Util;
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Framework;

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

/**
* @dataProvider \Ergebnis\Test\Util\DataProvider\StringProvider::blank()
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Exception/InvalidMaximumCountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Unit\Exception;

use Ergebnis\PHPUnit\SlowTestDetector\Exception\InvalidMaximumCount;
use Ergebnis\Test\Util;
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Framework;

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

public function testNotGreaterThanZeroReturnsException(): void
{
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Exception/InvalidMaximumDurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Unit\Exception;

use Ergebnis\PHPUnit\SlowTestDetector\Exception\InvalidMaximumDuration;
use Ergebnis\Test\Util;
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Framework;

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

public function testNotGreaterThanReturnsException(): void
{
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Formatter/ToMillisecondsDurationFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Unit\Formatter;

use Ergebnis\PHPUnit\SlowTestDetector\Formatter\ToMillisecondsDurationFormatter;
use Ergebnis\Test\Util;
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Event;
use PHPUnit\Framework;

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

/**
* @dataProvider provideDurationAndFormattedDuration
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/MaximumDurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use Ergebnis\PHPUnit\SlowTestDetector\Exception;
use Ergebnis\PHPUnit\SlowTestDetector\MaximumDuration;
use Ergebnis\Test\Util;
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Event;
use PHPUnit\Framework;

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

/**
* @dataProvider \Ergebnis\Test\Util\DataProvider\IntProvider::lessThanZero()
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Reporter/DefaultReporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
use Ergebnis\PHPUnit\SlowTestDetector\MaximumDuration;
use Ergebnis\PHPUnit\SlowTestDetector\Reporter\DefaultReporter;
use Ergebnis\PHPUnit\SlowTestDetector\SlowTest;
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use Ergebnis\PHPUnit\SlowTestDetector\Test\Example;
use Ergebnis\Test\Util;
use PHPUnit\Event;
use PHPUnit\Framework;

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

public function testReportReturnsEmptyStringWhenNoSlowTestsHaveBeenSpecified(): void
{
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/SlowTestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Unit;

use Ergebnis\PHPUnit\SlowTestDetector\SlowTest;
use Ergebnis\Test\Util;
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Event;
use PHPUnit\Framework;

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

public function testFromTestDurationAndMaximumDurationReturnsSlowTest(): void
{
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Subscriber/TestPassedSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
use Ergebnis\PHPUnit\SlowTestDetector\MaximumDuration;
use Ergebnis\PHPUnit\SlowTestDetector\SlowTest;
use Ergebnis\PHPUnit\SlowTestDetector\Subscriber\TestPassedSubscriber;
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use Ergebnis\PHPUnit\SlowTestDetector\Test\Double;
use Ergebnis\PHPUnit\SlowTestDetector\Test\Example;
use Ergebnis\PHPUnit\SlowTestDetector\TimeKeeper;
use Ergebnis\Test\Util;
use PHPUnit\Event;
use PHPUnit\Framework;

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

public function testNotifyDoesNotCollectSlowTestWhenDurationIsLessThanMaximumDuration(): void
{
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Subscriber/TestPreparedSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Unit\Subscriber;

use Ergebnis\PHPUnit\SlowTestDetector\Subscriber\TestPreparedSubscriber;
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use Ergebnis\PHPUnit\SlowTestDetector\Test\Example;
use Ergebnis\PHPUnit\SlowTestDetector\TimeKeeper;
use Ergebnis\Test\Util;
use PHPUnit\Event;
use PHPUnit\Framework;

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

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

use Ergebnis\PHPUnit\SlowTestDetector\SlowTest;
use Ergebnis\PHPUnit\SlowTestDetector\Subscriber\TestSuiteFinishedSubscriber;
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use Ergebnis\PHPUnit\SlowTestDetector\Test\Double;
use Ergebnis\PHPUnit\SlowTestDetector\Test\Example;
use Ergebnis\Test\Util;
use PHPUnit\Event;
use PHPUnit\Framework;

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

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

namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Unit;

use Ergebnis\PHPUnit\SlowTestDetector\Test;
use Ergebnis\PHPUnit\SlowTestDetector\Test\Example;
use Ergebnis\PHPUnit\SlowTestDetector\TimeKeeper;
use Ergebnis\Test\Util;
use PHPUnit\Event;
use PHPUnit\Framework;

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

public function testStopReturnsZeroDurationWhenTestHasNotBeenStoppedButNotStarted(): 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) 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/phpunit-slow-test-detector
*/

namespace Ergebnis\PHPUnit\SlowTestDetector\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 8cb78fe

Please sign in to comment.