Skip to content

Commit

Permalink
test seeding and repeat
Browse files Browse the repository at this point in the history
  • Loading branch information
IonBazan committed Dec 11, 2020
1 parent 7dea0d7 commit 1f1bdd8
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 10 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -26,6 +27,10 @@ jobs:
include:
- operating-system: 'windows-latest'
php-version: '7.1'
phpunit-flags: '-v'
- php-version: '8.0'
operating-system: 'ubuntu-latest'
phpunit-flags: '--repeat 100 --exclude-group external,seed'

runs-on: ${{ matrix.operating-system }}

Expand Down Expand Up @@ -59,4 +64,4 @@ jobs:
- name: Run tests with PHPUnit
run: |
vendor/bin/phpunit
vendor/bin/phpunit ${{ matrix.phpunit-flags }}
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
bootstrap="vendor/autoload.php"
colors="true"
columns="max"
verbose="true"
cacheResultFile=".build/.phpunit.result.cache"
>
<testsuites>
Expand Down
13 changes: 10 additions & 3 deletions test/Faker/Provider/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ public function testShuffleArrayReturnsAnArrayWithSameElements()
self::assertContains(10, $shuffleArray);
}

/**
* @group seed
*/
public function testShuffleArrayReturnsADifferentArrayThanTheOriginal()
{
$arr = [1, 2, 3, 4, 5];
Expand Down Expand Up @@ -227,6 +230,9 @@ public function testShuffleStringReturnsAnStringWithSameElements()
self::assertStringContainsString('i', $shuffleString);
}

/**
* @group seed
*/
public function testShuffleStringReturnsADifferentStringThanTheOriginal()
{
$string = 'abcdef';
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
);
}

Expand Down
3 changes: 3 additions & 0 deletions test/Faker/Provider/BiasedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Faker\Provider\Biased;
use Faker\Test\TestCase;

/**
* @group seed
*/
final class BiasedTest extends TestCase
{
public const MAX = 10;
Expand Down
5 changes: 4 additions & 1 deletion test/Faker/Provider/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public function testImageUrlAddsARandomGetParameterByDefault()
self::assertMatchesRegularExpression('#\w*#', $splitUrl[1]);
}

/**
* @group external
*/
public function testDownloadWithDefaults()
{
$curlPing = curl_init(Image::BASE_URL);
Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions test/Faker/Provider/ja_JP/InternetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Faker\Provider\ja_JP\Internet;
use Faker\Test\TestCase;

/**
* @group seed
*/
final class InternetTest extends TestCase
{
public function testUserName()
Expand Down
3 changes: 3 additions & 0 deletions test/Faker/Provider/ja_JP/PersonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Faker\Provider\ja_JP\Person;
use Faker\Test\TestCase;

/**
* @group seed
*/
final class PersonTest extends TestCase
{
public function testKanaNameMaleReturns()
Expand Down
4 changes: 2 additions & 2 deletions test/Faker/Provider/mn_MN/PersonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
3 changes: 3 additions & 0 deletions test/Faker/Provider/uk_UA/PersonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Faker\Provider\uk_UA\Person;
use Faker\Test\TestCase;

/**
* @group seed
*/
final class PersonTest extends TestCase
{
public function testFirstNameMaleReturns()
Expand Down
5 changes: 4 additions & 1 deletion test/Faker/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1f1bdd8

Please sign in to comment.