Passed
Push — master ( e23bc1...ee0f92 )
by Kevin
03:07
created

MakeStoryTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 144
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 93
dl 0
loc 144
rs 10
c 2
b 0
f 1
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A storyNameProvider() 0 4 1
A can_create_story() 0 26 1
A can_create_story_interactively() 0 29 1
A can_create_story_in_test_dir() 0 26 1
A can_create_story_in_test_dir_interactively() 0 29 1
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