diff --git a/composer.json b/composer.json index bc0fbfc9f3..04a8a4a652 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ }, "autoload-dev": { "psr-4": { - "Faker\\Test\\": "test/Faker/" + "Faker\\Test\\": "test/Faker/", + "Faker\\Test\\Fixture\\": "test/Fixture/" } }, "conflict": { diff --git a/test/Faker/GeneratorTest.php b/test/Faker/GeneratorTest.php index c31fcf2112..a442a1f147 100644 --- a/test/Faker/GeneratorTest.php +++ b/test/Faker/GeneratorTest.php @@ -56,29 +56,29 @@ public function testMimeType(): void public function testAddProviderGivesPriorityToNewlyAddedProvider() { - $this->faker->addProvider(new FooProvider()); - $this->faker->addProvider(new BarProvider()); + $this->faker->addProvider(new Fixture\Provider\FooProvider()); + $this->faker->addProvider(new Fixture\Provider\BarProvider()); self::assertEquals('barfoo', $this->faker->format('fooFormatter')); } public function testGetProvidersReturnsCorrectProviders() { - $this->faker->addProvider(new FooProvider()); - $this->faker->addProvider(new BarProvider()); - self::assertInstanceOf(FooProvider::class, $this->faker->getProviders()[1]); - self::assertInstanceOf(BarProvider::class, $this->faker->getProviders()[0]); + $this->faker->addProvider(new Fixture\Provider\FooProvider()); + $this->faker->addProvider(new Fixture\Provider\BarProvider()); + self::assertInstanceOf(Fixture\Provider\FooProvider::class, $this->faker->getProviders()[1]); + self::assertInstanceOf(Fixture\Provider\BarProvider::class, $this->faker->getProviders()[0]); self::assertCount(2, $this->faker->getProviders()); } public function testGetFormatterReturnsCallable() { - $this->faker->addProvider(new FooProvider()); + $this->faker->addProvider(new Fixture\Provider\FooProvider()); self::assertIsCallable($this->faker->getFormatter('fooFormatter')); } public function testGetFormatterReturnsCorrectFormatter() { - $provider = new FooProvider(); + $provider = new Fixture\Provider\FooProvider(); $this->faker->addProvider($provider); $expected = [$provider, 'fooFormatter']; self::assertEquals($expected, $this->faker->getFormatter('fooFormatter')); @@ -93,20 +93,20 @@ public function testGetFormatterThrowsExceptionOnIncorrectProvider() public function testGetFormatterThrowsExceptionOnIncorrectFormatter() { $this->expectException(\InvalidArgumentException::class); - $this->faker->addProvider(new FooProvider()); + $this->faker->addProvider(new Fixture\Provider\FooProvider()); $this->faker->getFormatter('barFormatter'); } public function testFormatCallsFormatterOnProvider() { - $this->faker->addProvider(new FooProvider()); + $this->faker->addProvider(new Fixture\Provider\FooProvider()); self::assertEquals('foobar', $this->faker->format('fooFormatter')); } public function testFormatTransfersArgumentsToFormatter() { $this->faker = new Generator(); - $provider = new FooProvider(); + $provider = new Fixture\Provider\FooProvider(); $this->faker->addProvider($provider); self::assertEquals('bazfoo', $this->faker->format('fooFormatterWithArguments', ['foo'])); } @@ -118,7 +118,7 @@ public function testParseReturnsSameStringWhenItContainsNoCurlyBraces() public function testParseReturnsStringWithTokensReplacedByFormatters() { - $this->faker->addProvider(new FooProvider()); + $this->faker->addProvider(new Fixture\Provider\FooProvider()); self::assertEquals('This is foobar a text with foobar', $this->faker->parse('This is {{fooFormatter}} a text with {{ fooFormatter }}')); } @@ -127,19 +127,19 @@ public function testParseReturnsStringWithTokensReplacedByFormatters() */ public function testMagicGetCallsFormat() { - $this->faker->addProvider(new FooProvider()); + $this->faker->addProvider(new Fixture\Provider\FooProvider()); self::assertEquals('foobar', $this->faker->fooFormatter); } public function testMagicCallCallsFormat() { - $this->faker->addProvider(new FooProvider()); + $this->faker->addProvider(new Fixture\Provider\FooProvider()); self::assertEquals('foobar', $this->faker->fooFormatter()); } public function testMagicCallCallsFormatWithArguments() { - $this->faker->addProvider(new FooProvider()); + $this->faker->addProvider(new Fixture\Provider\FooProvider()); self::assertEquals('bazfoo', $this->faker->fooFormatterWithArguments('foo')); } @@ -285,24 +285,3 @@ public function word(): string $uniqueGenerator->word(); } } - -final class FooProvider -{ - public function fooFormatter() - { - return 'foobar'; - } - - public function fooFormatterWithArguments($value = '') - { - return 'baz' . $value; - } -} - -final class BarProvider -{ - public function fooFormatter() - { - return 'barfoo'; - } -} diff --git a/test/Fixture/Provider/BarProvider.php b/test/Fixture/Provider/BarProvider.php new file mode 100644 index 0000000000..0b2e97bfd3 --- /dev/null +++ b/test/Fixture/Provider/BarProvider.php @@ -0,0 +1,11 @@ +