Skip to content

Commit 619ceca

Browse files
authored
Enhancement: Extract fixtures into separate classes (#234)
1 parent 14657fa commit 619ceca

File tree

4 files changed

+44
-37
lines changed

4 files changed

+44
-37
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
},
3131
"autoload-dev": {
3232
"psr-4": {
33-
"Faker\\Test\\": "test/Faker/"
33+
"Faker\\Test\\": "test/Faker/",
34+
"Faker\\Test\\Fixture\\": "test/Fixture/"
3435
}
3536
},
3637
"conflict": {

test/Faker/GeneratorTest.php

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,29 @@ public function testMimeType(): void
5656

5757
public function testAddProviderGivesPriorityToNewlyAddedProvider()
5858
{
59-
$this->faker->addProvider(new FooProvider());
60-
$this->faker->addProvider(new BarProvider());
59+
$this->faker->addProvider(new Fixture\Provider\FooProvider());
60+
$this->faker->addProvider(new Fixture\Provider\BarProvider());
6161
self::assertEquals('barfoo', $this->faker->format('fooFormatter'));
6262
}
6363

6464
public function testGetProvidersReturnsCorrectProviders()
6565
{
66-
$this->faker->addProvider(new FooProvider());
67-
$this->faker->addProvider(new BarProvider());
68-
self::assertInstanceOf(FooProvider::class, $this->faker->getProviders()[1]);
69-
self::assertInstanceOf(BarProvider::class, $this->faker->getProviders()[0]);
66+
$this->faker->addProvider(new Fixture\Provider\FooProvider());
67+
$this->faker->addProvider(new Fixture\Provider\BarProvider());
68+
self::assertInstanceOf(Fixture\Provider\FooProvider::class, $this->faker->getProviders()[1]);
69+
self::assertInstanceOf(Fixture\Provider\BarProvider::class, $this->faker->getProviders()[0]);
7070
self::assertCount(2, $this->faker->getProviders());
7171
}
7272

7373
public function testGetFormatterReturnsCallable()
7474
{
75-
$this->faker->addProvider(new FooProvider());
75+
$this->faker->addProvider(new Fixture\Provider\FooProvider());
7676
self::assertIsCallable($this->faker->getFormatter('fooFormatter'));
7777
}
7878

7979
public function testGetFormatterReturnsCorrectFormatter()
8080
{
81-
$provider = new FooProvider();
81+
$provider = new Fixture\Provider\FooProvider();
8282
$this->faker->addProvider($provider);
8383
$expected = [$provider, 'fooFormatter'];
8484
self::assertEquals($expected, $this->faker->getFormatter('fooFormatter'));
@@ -93,20 +93,20 @@ public function testGetFormatterThrowsExceptionOnIncorrectProvider()
9393
public function testGetFormatterThrowsExceptionOnIncorrectFormatter()
9494
{
9595
$this->expectException(\InvalidArgumentException::class);
96-
$this->faker->addProvider(new FooProvider());
96+
$this->faker->addProvider(new Fixture\Provider\FooProvider());
9797
$this->faker->getFormatter('barFormatter');
9898
}
9999

100100
public function testFormatCallsFormatterOnProvider()
101101
{
102-
$this->faker->addProvider(new FooProvider());
102+
$this->faker->addProvider(new Fixture\Provider\FooProvider());
103103
self::assertEquals('foobar', $this->faker->format('fooFormatter'));
104104
}
105105

106106
public function testFormatTransfersArgumentsToFormatter()
107107
{
108108
$this->faker = new Generator();
109-
$provider = new FooProvider();
109+
$provider = new Fixture\Provider\FooProvider();
110110
$this->faker->addProvider($provider);
111111
self::assertEquals('bazfoo', $this->faker->format('fooFormatterWithArguments', ['foo']));
112112
}
@@ -118,7 +118,7 @@ public function testParseReturnsSameStringWhenItContainsNoCurlyBraces()
118118

119119
public function testParseReturnsStringWithTokensReplacedByFormatters()
120120
{
121-
$this->faker->addProvider(new FooProvider());
121+
$this->faker->addProvider(new Fixture\Provider\FooProvider());
122122
self::assertEquals('This is foobar a text with foobar', $this->faker->parse('This is {{fooFormatter}} a text with {{ fooFormatter }}'));
123123
}
124124

@@ -127,19 +127,19 @@ public function testParseReturnsStringWithTokensReplacedByFormatters()
127127
*/
128128
public function testMagicGetCallsFormat()
129129
{
130-
$this->faker->addProvider(new FooProvider());
130+
$this->faker->addProvider(new Fixture\Provider\FooProvider());
131131
self::assertEquals('foobar', $this->faker->fooFormatter);
132132
}
133133

134134
public function testMagicCallCallsFormat()
135135
{
136-
$this->faker->addProvider(new FooProvider());
136+
$this->faker->addProvider(new Fixture\Provider\FooProvider());
137137
self::assertEquals('foobar', $this->faker->fooFormatter());
138138
}
139139

140140
public function testMagicCallCallsFormatWithArguments()
141141
{
142-
$this->faker->addProvider(new FooProvider());
142+
$this->faker->addProvider(new Fixture\Provider\FooProvider());
143143
self::assertEquals('bazfoo', $this->faker->fooFormatterWithArguments('foo'));
144144
}
145145

@@ -285,24 +285,3 @@ public function word(): string
285285
$uniqueGenerator->word();
286286
}
287287
}
288-
289-
final class FooProvider
290-
{
291-
public function fooFormatter()
292-
{
293-
return 'foobar';
294-
}
295-
296-
public function fooFormatterWithArguments($value = '')
297-
{
298-
return 'baz' . $value;
299-
}
300-
}
301-
302-
final class BarProvider
303-
{
304-
public function fooFormatter()
305-
{
306-
return 'barfoo';
307-
}
308-
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Faker\Test\Fixture\Provider;
4+
5+
final class BarProvider
6+
{
7+
public function fooFormatter()
8+
{
9+
return 'barfoo';
10+
}
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Faker\Test\Fixture\Provider;
4+
5+
final class FooProvider
6+
{
7+
public function fooFormatter()
8+
{
9+
return 'foobar';
10+
}
11+
12+
public function fooFormatterWithArguments($value = '')
13+
{
14+
return 'baz' . $value;
15+
}
16+
}

0 commit comments

Comments
 (0)