From 3b2b0e3aea82d480c29d23adb0ca540e3a970c89 Mon Sep 17 00:00:00 2001 From: Ion Bazan Date: Fri, 11 Dec 2020 15:25:48 +0800 Subject: [PATCH] test seeding and repeat --- .github/workflows/continuous-integration.yml | 8 ++++++-- phpunit.xml.dist | 1 - test/Faker/Provider/BaseTest.php | 13 ++++++++++--- test/Faker/Provider/BiasedTest.php | 3 +++ test/Faker/Provider/ImageTest.php | 5 ++++- test/Faker/Provider/ja_JP/InternetTest.php | 3 +++ test/Faker/Provider/ja_JP/PersonTest.php | 3 +++ test/Faker/Provider/mn_MN/PersonTest.php | 4 ++-- test/Faker/Provider/uk_UA/PersonTest.php | 3 +++ test/Faker/TestCase.php | 5 ++++- 10 files changed, 38 insertions(+), 10 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 9d2beaf141..f37ca87c41 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -11,10 +11,11 @@ name: Continuous Integration jobs: tests: - name: CI on ${{ matrix.operating-system }} with PHP ${{ matrix.php-version }} + name: CI on ${{ matrix.operating-system }} with PHP ${{ matrix.php-version }} ${{ matrix.phpunit-flags }} strategy: matrix: + phpunit-flags: ['-v'] operating-system: - 'ubuntu-latest' php-version: @@ -26,6 +27,9 @@ jobs: include: - operating-system: 'windows-latest' php-version: '7.1' + phpunit-flags: '-v' + - php-version: '8.0' + phpunit-flags: '--repeat 100 --exclude-group external,seed' runs-on: ${{ matrix.operating-system }} @@ -59,4 +63,4 @@ jobs: - name: Run tests with PHPUnit run: | - vendor/bin/phpunit + vendor/bin/phpunit ${{ matrix.phpunit-flags }} diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 87cc94a819..151e7a27fb 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -6,7 +6,6 @@ bootstrap="vendor/autoload.php" colors="true" columns="max" - verbose="true" cacheResultFile=".build/.phpunit.result.cache" > diff --git a/test/Faker/Provider/BaseTest.php b/test/Faker/Provider/BaseTest.php index 5ccd6d9f45..3e40fbd7be 100644 --- a/test/Faker/Provider/BaseTest.php +++ b/test/Faker/Provider/BaseTest.php @@ -191,6 +191,9 @@ public function testShuffleArrayReturnsAnArrayWithSameElements() self::assertContains(10, $shuffleArray); } + /** + * @group seed + */ public function testShuffleArrayReturnsADifferentArrayThanTheOriginal() { $arr = [1, 2, 3, 4, 5]; @@ -227,6 +230,9 @@ public function testShuffleStringReturnsAnStringWithSameElements() self::assertStringContainsString('i', $shuffleString); } + /** + * @group seed + */ public function testShuffleStringReturnsADifferentStringThanTheOriginal() { $string = 'abcdef'; @@ -337,12 +343,13 @@ public function regexifyDataProvider() ['[a-z]{2,3}', 'brackets quantifiers on character class range'], ['(a|b){2,3}', 'brackets quantifiers on alternation'], ['\.\*\?\+', 'escaped characters'], - ['[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}', 'complex regex'] + ['[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}', 'complex regex'], // @todo fix dot support ]; } /** * @dataProvider regexifyDataProvider + * @group seed */ public function testRegexifySupportedRegexSyntax($pattern, $message) { @@ -416,8 +423,8 @@ public function testOptionalPercentageAndWeight() } self::assertEquals( - round(array_sum($valuesOld) / 10000, 2), - round(array_sum($valuesNew) / 10000, 2) + round(array_sum($valuesOld) / 10000, 1), + round(array_sum($valuesNew) / 10000, 1) ); } diff --git a/test/Faker/Provider/BiasedTest.php b/test/Faker/Provider/BiasedTest.php index b6d56647f9..80ad6e97a8 100644 --- a/test/Faker/Provider/BiasedTest.php +++ b/test/Faker/Provider/BiasedTest.php @@ -5,6 +5,9 @@ use Faker\Provider\Biased; use Faker\Test\TestCase; +/** + * @group seed + */ final class BiasedTest extends TestCase { public const MAX = 10; diff --git a/test/Faker/Provider/ImageTest.php b/test/Faker/Provider/ImageTest.php index bc3a05316b..092964ac30 100644 --- a/test/Faker/Provider/ImageTest.php +++ b/test/Faker/Provider/ImageTest.php @@ -82,6 +82,9 @@ public function testImageUrlAddsARandomGetParameterByDefault() self::assertMatchesRegularExpression('#\w*#', $splitUrl[1]); } + /** + * @group external + */ public function testDownloadWithDefaults() { $curlPing = curl_init(Image::BASE_URL); @@ -100,7 +103,7 @@ public function testDownloadWithDefaults() $file = Image::image(sys_get_temp_dir()); self::assertFileExists($file); if (function_exists('getimagesize')) { - list($width, $height, $type, $attr) = getimagesize($file); + [$width, $height, $type, $attr] = getimagesize($file); self::assertEquals(640, $width); self::assertEquals(480, $height); self::assertEquals(constant('IMAGETYPE_PNG'), $type); diff --git a/test/Faker/Provider/ja_JP/InternetTest.php b/test/Faker/Provider/ja_JP/InternetTest.php index 51b80d2c2b..d9229bfe19 100644 --- a/test/Faker/Provider/ja_JP/InternetTest.php +++ b/test/Faker/Provider/ja_JP/InternetTest.php @@ -5,6 +5,9 @@ use Faker\Provider\ja_JP\Internet; use Faker\Test\TestCase; +/** + * @group seed + */ final class InternetTest extends TestCase { public function testUserName() diff --git a/test/Faker/Provider/ja_JP/PersonTest.php b/test/Faker/Provider/ja_JP/PersonTest.php index bfb2169ed7..c896bd8a9c 100644 --- a/test/Faker/Provider/ja_JP/PersonTest.php +++ b/test/Faker/Provider/ja_JP/PersonTest.php @@ -5,6 +5,9 @@ use Faker\Provider\ja_JP\Person; use Faker\Test\TestCase; +/** + * @group seed + */ final class PersonTest extends TestCase { public function testKanaNameMaleReturns() diff --git a/test/Faker/Provider/mn_MN/PersonTest.php b/test/Faker/Provider/mn_MN/PersonTest.php index f3feadbd5d..73e3e3b68b 100644 --- a/test/Faker/Provider/mn_MN/PersonTest.php +++ b/test/Faker/Provider/mn_MN/PersonTest.php @@ -9,12 +9,12 @@ final class PersonTest extends TestCase { public function testName() { - self::assertMatchesRegularExpression('/^[А-Я]{1}\.[\w\W]+$/u', $this->faker->name); + self::assertMatchesRegularExpression('/^[\p{Cyrillic}]\.[\w\W]+$/u', $this->faker->name); } public function testIdNumber() { - self::assertMatchesRegularExpression('/^[А-Я]{2}\d{8}$/u', $this->faker->idNumber); + self::assertMatchesRegularExpression('/^[\p{Cyrillic}]{2}\d{8}$/u', $this->faker->idNumber); } diff --git a/test/Faker/Provider/uk_UA/PersonTest.php b/test/Faker/Provider/uk_UA/PersonTest.php index d6ba1b1a78..1de39cafff 100644 --- a/test/Faker/Provider/uk_UA/PersonTest.php +++ b/test/Faker/Provider/uk_UA/PersonTest.php @@ -5,6 +5,9 @@ use Faker\Provider\uk_UA\Person; use Faker\Test\TestCase; +/** + * @group seed + */ final class PersonTest extends TestCase { public function testFirstNameMaleReturns() diff --git a/test/Faker/TestCase.php b/test/Faker/TestCase.php index a5d300d934..57d5eced1f 100644 --- a/test/Faker/TestCase.php +++ b/test/Faker/TestCase.php @@ -17,7 +17,10 @@ abstract class TestCase extends BaseTestCase protected function setUp(): void { $this->faker = new Generator(); - $this->faker->seed(1); + + if (in_array('seed', $this->getGroups(), true)) { + $this->faker->seed(1); + } foreach ($this->getProviders() as $provider) { $this->faker->addProvider($provider);