6
6
use eCamp \LibTest \PHPUnit \AbstractConsoleControllerTestCase ;
7
7
use PHPUnit \Framework \Constraint \IsEqual ;
8
8
use PHPUnit \Framework \Constraint \StringContains ;
9
+ use PHPUnit \Framework \Constraint \StringEndsWith ;
9
10
use Symfony \Component \Console \Input \StringInput ;
10
11
use Symfony \Component \Console \Output \BufferedOutput ;
11
12
use Symfony \Component \Console \Output \OutputInterface ;
13
+ use Symfony \Component \Filesystem \Filesystem ;
12
14
13
15
/**
14
16
* @internal
@@ -17,12 +19,17 @@ class LoadDataFixturesCommandTest extends AbstractConsoleControllerTestCase {
17
19
public function testLoadsFilesFromGivenPath () {
18
20
// given
19
21
$ services = $ this ->getApplicationServiceLocator ();
20
- /** @var LoadDataFixturesCommand $command */
21
- $ command = $ services ->get (LoadDataFixturesCommand::class);
22
+
22
23
$ input = new StringInput ('load-data-fixtures --path= ' .__DIR__ .'/../data/fixtures ' );
23
24
$ output = new BufferedOutput ();
24
25
$ services ->setService (OutputInterface::class, $ output );
25
26
27
+ $ mockFilesystem = $ this ->createMock (Filesystem::class);
28
+ $ services ->setService (Filesystem::class, $ mockFilesystem );
29
+
30
+ /** @var LoadDataFixturesCommand $command */
31
+ $ command = $ services ->get (LoadDataFixturesCommand::class);
32
+
26
33
// when
27
34
$ result = $ this ->runCommand ($ command , $ input , $ output );
28
35
@@ -36,12 +43,20 @@ public function testLoadsFilesFromGivenPath() {
36
43
public function testDoesNotCrashWhenGivenNonexistentLocation () {
37
44
// given
38
45
$ services = $ this ->getApplicationServiceLocator ();
39
- /** @var LoadDataFixturesCommand $command */
40
- $ command = $ services ->get (LoadDataFixturesCommand::class);
46
+
41
47
$ input = new StringInput ('load-data-fixtures --path= ' .__DIR__ .'/../data/some-dir-that-does-not-exist ' );
42
48
$ output = new BufferedOutput ();
43
49
$ services ->setService (OutputInterface::class, $ output );
44
50
51
+ $ mockFilesystem = $ this ->createMock (Filesystem::class);
52
+ $ services ->setService (Filesystem::class, $ mockFilesystem );
53
+
54
+ /** @var LoadDataFixturesCommand $command */
55
+ $ command = $ services ->get (LoadDataFixturesCommand::class);
56
+
57
+ // then
58
+ $ mockFilesystem ->expects ($ this ->never ())->method ('remove ' );
59
+
45
60
// when
46
61
$ result = $ this ->runCommand ($ command , $ input , $ output );
47
62
@@ -50,4 +65,24 @@ public function testDoesNotCrashWhenGivenNonexistentLocation() {
50
65
$ consoleOutput = $ output ->fetch ();
51
66
$ this ->assertThat ($ consoleOutput , new IsEqual ('' ));
52
67
}
68
+
69
+ public function testCleansUpDoctrineProxies () {
70
+ // given
71
+ $ services = $ this ->getApplicationServiceLocator ();
72
+ $ input = new StringInput ('load-data-fixtures --path= ' .__DIR__ .'/../data/fixtures ' );
73
+ $ output = new BufferedOutput ();
74
+ $ services ->setService (OutputInterface::class, $ output );
75
+
76
+ $ mockFilesystem = $ this ->createMock (Filesystem::class);
77
+ $ services ->setService (Filesystem::class, $ mockFilesystem );
78
+
79
+ /** @var LoadDataFixturesCommand $command */
80
+ $ command = $ services ->get (LoadDataFixturesCommand::class);
81
+
82
+ // then
83
+ $ mockFilesystem ->expects ($ this ->once ())->method ('remove ' )->with (new StringEndsWith ('DoctrineORMModule ' ));
84
+
85
+ // when
86
+ $ this ->runCommand ($ command , $ input , $ output );
87
+ }
53
88
}
0 commit comments