File: TestCase.php

package info (click to toggle)
php-faker 1.20.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 12,412 kB
  • sloc: php: 115,671; xml: 213; makefile: 49
file content (66 lines) | stat: -rw-r--r-- 1,493 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php

namespace Faker\Test;

use Faker\Generator;
use PHPUnit\Framework\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    /**
     * @var Generator
     */
    protected $faker;

    protected function setUp(): void
    {
        $this->faker = new Generator();
        $this->faker->seed(1);

        foreach ($this->getProviders() as $provider) {
            $this->faker->addProvider($provider);
        }
    }

    public static function localeDataProvider(): array
    {
        $locales = [];

        foreach (self::getAllLocales() as $locale) {
            $locales[$locale] = [$locale];
        }

        return $locales;
    }

    protected static function getAllLocales(): array
    {
        return array_map('basename', glob(__DIR__ . '/../../src/Faker/Provider/*_*', GLOB_ONLYDIR));
    }

    protected function loadLocalProvider(string $locale, string $provider): void
    {
        $providerClass = "\\Faker\\Provider\\$locale\\$provider";

        if (class_exists($providerClass)) {
            $this->faker->addProvider(new $providerClass($this->faker));
        }
    }

    protected function getProviders(): iterable
    {
        return [];
    }

    protected function is32bitSystem(): bool
    {
        return PHP_INT_SIZE === 4;
    }

    protected function skipOn32bitSystem(): void
    {
        if ($this->is32bitSystem()) {
            self::markTestSkipped('Test case is incompatible with 32-bit systems.');
        }
    }
}