File: ProviderOverrideTest.php

package info (click to toggle)
php-faker 1.20.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,704 kB
  • sloc: php: 115,692; xml: 213; makefile: 49
file content (130 lines) | stat: -rw-r--r-- 4,096 bytes parent folder | download
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php

namespace Faker\Test\Provider;

use Faker;
use Faker\Test\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;

/**
 * Class ProviderOverrideTest
 */
/**
 * @group legacy
 */
final class ProviderOverrideTest extends TestCase
{
    /**
     * Constants with regular expression patterns for testing the output.
     *
     * Regular expressions are sensitive for malformed strings (e.g.: strings with incorrect encodings) so by using
     * PCRE for the tests, even though they seem fairly pointless, we test for incorrect encodings also.
     */
    public const TEST_STRING_REGEX = '/.+/u';

    /**
     * Slightly more specific for e-mail, the point isn't to properly validate e-mails.
     */
    public const TEST_EMAIL_REGEX = '/^(.+)@(.+)$/ui';

    /**
     * @param string $locale
     */
    #[DataProvider('localeDataProvider')]
    public function testAddress($locale = null)
    {
        $faker = Faker\Factory::create($locale);

        self::assertMatchesRegularExpression(static::TEST_STRING_REGEX, $faker->city);
        self::assertMatchesRegularExpression(static::TEST_STRING_REGEX, $faker->postcode);
        self::assertMatchesRegularExpression(static::TEST_STRING_REGEX, $faker->address);
        self::assertMatchesRegularExpression(static::TEST_STRING_REGEX, $faker->country);
    }

    /**
     * @param string $locale
     */
    #[DataProvider('localeDataProvider')]
    public function testCompany($locale = null)
    {
        $faker = Faker\Factory::create($locale);

        self::assertMatchesRegularExpression(static::TEST_STRING_REGEX, $faker->company);
    }

    /**
     * @param string $locale
     */
    #[DataProvider('localeDataProvider')]
    public function testDateTime($locale = null)
    {
        $faker = Faker\Factory::create($locale);

        self::assertMatchesRegularExpression(static::TEST_STRING_REGEX, $faker->century);
        self::assertMatchesRegularExpression(static::TEST_STRING_REGEX, $faker->timezone);
    }

    /**
     * @param string $locale
     */
    #[DataProvider('localeDataProvider')]
    public function testInternet($locale = null)
    {
        $faker = Faker\Factory::create($locale);

        self::assertMatchesRegularExpression(static::TEST_STRING_REGEX, $faker->userName);

        self::assertMatchesRegularExpression(static::TEST_EMAIL_REGEX, $faker->email);
        self::assertMatchesRegularExpression(static::TEST_EMAIL_REGEX, $faker->safeEmail);
        self::assertMatchesRegularExpression(static::TEST_EMAIL_REGEX, $faker->freeEmail);
        self::assertMatchesRegularExpression(static::TEST_EMAIL_REGEX, $faker->companyEmail);
    }

    /**
     * @param string $locale
     */
    #[DataProvider('localeDataProvider')]
    public function testPerson($locale = null)
    {
        $faker = Faker\Factory::create($locale);

        self::assertMatchesRegularExpression(static::TEST_STRING_REGEX, $faker->name);
        self::assertMatchesRegularExpression(static::TEST_STRING_REGEX, $faker->title);
        self::assertMatchesRegularExpression(static::TEST_STRING_REGEX, $faker->firstName);
        self::assertMatchesRegularExpression(static::TEST_STRING_REGEX, $faker->lastName);
    }

    /**
     * @param string $locale
     */
    #[DataProvider('localeDataProvider')]
    public function testPhoneNumber($locale = null)
    {
        $faker = Faker\Factory::create($locale);

        self::assertMatchesRegularExpression(static::TEST_STRING_REGEX, $faker->phoneNumber);
    }

    /**
     * @param string $locale
     */
    #[DataProvider('localeDataProvider')]
    public function testUserAgent($locale = null)
    {
        $faker = Faker\Factory::create($locale);

        self::assertMatchesRegularExpression(static::TEST_STRING_REGEX, $faker->userAgent);
    }

    /**
     * @param null   $locale
     * @param string $locale
     */
    #[DataProvider('localeDataProvider')]
    public function testUuid($locale = null)
    {
        $faker = Faker\Factory::create($locale);

        self::assertMatchesRegularExpression(static::TEST_STRING_REGEX, $faker->uuid);
    }
}