1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Zenstruck\Foundry\Tests\Functional\Bundle\Maker; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
6
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @author Kevin Bond <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
final class MakeStoryTest extends MakerTestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @test |
15
|
|
|
* @dataProvider storyNameProvider |
16
|
|
|
*/ |
17
|
|
|
public function can_create_story($name): void |
18
|
|
|
{ |
19
|
|
|
$tester = new CommandTester((new Application(self::bootKernel()))->find('make:story')); |
20
|
|
|
|
21
|
|
|
$this->assertFileNotExists(self::tempFile('src/Story/FooBarStory.php')); |
22
|
|
|
|
23
|
|
|
$tester->execute(['name' => $name]); |
24
|
|
|
|
25
|
|
|
$this->assertFileExists(self::tempFile('src/Story/FooBarStory.php')); |
26
|
|
|
$this->assertSame(<<<EOF |
27
|
|
|
<?php |
28
|
|
|
|
29
|
|
|
namespace App\\Story; |
30
|
|
|
|
31
|
|
|
use Zenstruck\\Foundry\\Story; |
32
|
|
|
|
33
|
|
|
final class FooBarStory extends Story |
34
|
|
|
{ |
35
|
|
|
public function build(): void |
36
|
|
|
{ |
37
|
|
|
// TODO build your story here (https://github.com/zenstruck/foundry#stories) |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
EOF |
42
|
|
|
, \file_get_contents(self::tempFile('src/Story/FooBarStory.php')) |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @test |
48
|
|
|
* @dataProvider storyNameProvider |
49
|
|
|
*/ |
50
|
|
|
public function can_create_story_interactively($name): void |
51
|
|
|
{ |
52
|
|
|
$tester = new CommandTester((new Application(self::bootKernel()))->find('make:story')); |
53
|
|
|
|
54
|
|
|
$this->assertFileNotExists(self::tempFile('src/Story/FooBarStory.php')); |
55
|
|
|
|
56
|
|
|
$tester->setInputs([$name]); |
57
|
|
|
$tester->execute([]); |
58
|
|
|
$output = $tester->getDisplay(); |
59
|
|
|
|
60
|
|
|
$this->assertFileExists(self::tempFile('src/Story/FooBarStory.php')); |
61
|
|
|
$this->assertStringContainsString('Note: pass --test if you want to generate stories in your tests/ directory', $output); |
62
|
|
|
$this->assertSame(<<<EOF |
63
|
|
|
<?php |
64
|
|
|
|
65
|
|
|
namespace App\\Story; |
66
|
|
|
|
67
|
|
|
use Zenstruck\\Foundry\\Story; |
68
|
|
|
|
69
|
|
|
final class FooBarStory extends Story |
70
|
|
|
{ |
71
|
|
|
public function build(): void |
72
|
|
|
{ |
73
|
|
|
// TODO build your story here (https://github.com/zenstruck/foundry#stories) |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
EOF |
78
|
|
|
, \file_get_contents(self::tempFile('src/Story/FooBarStory.php')) |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @test |
84
|
|
|
* @dataProvider storyNameProvider |
85
|
|
|
*/ |
86
|
|
|
public function can_create_story_in_test_dir($name): void |
87
|
|
|
{ |
88
|
|
|
$tester = new CommandTester((new Application(self::bootKernel()))->find('make:story')); |
89
|
|
|
|
90
|
|
|
$this->assertFileNotExists(self::tempFile('tests/Story/FooBarStory.php')); |
91
|
|
|
|
92
|
|
|
$tester->execute(['name' => $name, '--test' => true]); |
93
|
|
|
|
94
|
|
|
$this->assertFileExists(self::tempFile('tests/Story/FooBarStory.php')); |
95
|
|
|
$this->assertSame(<<<EOF |
96
|
|
|
<?php |
97
|
|
|
|
98
|
|
|
namespace App\\Tests\\Story; |
99
|
|
|
|
100
|
|
|
use Zenstruck\\Foundry\\Story; |
101
|
|
|
|
102
|
|
|
final class FooBarStory extends Story |
103
|
|
|
{ |
104
|
|
|
public function build(): void |
105
|
|
|
{ |
106
|
|
|
// TODO build your story here (https://github.com/zenstruck/foundry#stories) |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
EOF |
111
|
|
|
, \file_get_contents(self::tempFile('tests/Story/FooBarStory.php')) |
112
|
|
|
); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @test |
117
|
|
|
* @dataProvider storyNameProvider |
118
|
|
|
*/ |
119
|
|
|
public function can_create_story_in_test_dir_interactively($name): void |
120
|
|
|
{ |
121
|
|
|
$tester = new CommandTester((new Application(self::bootKernel()))->find('make:story')); |
122
|
|
|
|
123
|
|
|
$this->assertFileNotExists(self::tempFile('tests/Story/FooBarStory.php')); |
124
|
|
|
|
125
|
|
|
$tester->setInputs([$name]); |
126
|
|
|
$tester->execute(['--test' => true]); |
127
|
|
|
$output = $tester->getDisplay(); |
128
|
|
|
|
129
|
|
|
$this->assertFileExists(self::tempFile('tests/Story/FooBarStory.php')); |
130
|
|
|
$this->assertStringNotContainsString('Note: pass --test if you want to generate stories in your tests/ directory', $output); |
131
|
|
|
$this->assertSame(<<<EOF |
132
|
|
|
<?php |
133
|
|
|
|
134
|
|
|
namespace App\\Tests\\Story; |
135
|
|
|
|
136
|
|
|
use Zenstruck\\Foundry\\Story; |
137
|
|
|
|
138
|
|
|
final class FooBarStory extends Story |
139
|
|
|
{ |
140
|
|
|
public function build(): void |
141
|
|
|
{ |
142
|
|
|
// TODO build your story here (https://github.com/zenstruck/foundry#stories) |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
EOF |
147
|
|
|
, \file_get_contents(self::tempFile('tests/Story/FooBarStory.php')) |
148
|
|
|
); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public static function storyNameProvider(): iterable |
152
|
|
|
{ |
153
|
|
|
yield ['FooBar']; |
154
|
|
|
yield ['FooBarStory']; |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|