7
7
8
8
namespace ZendTest \ServiceManager \Tool ;
9
9
10
+ use org \bovigo \vfs \vfsStream ;
11
+ use org \bovigo \vfs \vfsStreamDirectory ;
10
12
use PHPUnit_Framework_TestCase as TestCase ;
11
13
use Prophecy \Argument ;
14
+ use Zend \ServiceManager \AbstractFactory \ConfigAbstractFactory ;
12
15
use Zend \ServiceManager \Tool \ConfigDumperCommand ;
13
16
use Zend \Stdlib \ConsoleHelper ;
14
17
use ZendTest \ServiceManager \TestAsset \InvokableObject ;
@@ -19,6 +22,7 @@ class ConfigDumperCommandTest extends TestCase
19
22
{
20
23
public function setUp ()
21
24
{
25
+ $ this ->configDir = vfsStream::setup ('project ' );
22
26
$ this ->helper = $ this ->prophesize (ConsoleHelper::class);
23
27
$ this ->command = new ConfigDumperCommand (ConfigDumperCommand::class, $ this ->helper ->reveal ());
24
28
}
@@ -84,7 +88,10 @@ public function testEmitsErrorWhenConfigurationFileNotFound()
84
88
public function testEmitsErrorWhenConfigurationFileDoesNotReturnArray ()
85
89
{
86
90
$ command = $ this ->command ;
87
- $ config = realpath (__DIR__ . '/../TestAsset/config/invalid.config.php ' );
91
+ vfsStream::newFile ('config/invalid.config.php ' )
92
+ ->at ($ this ->configDir )
93
+ ->setContent (file_get_contents (realpath (__DIR__ . '/../TestAsset/config/invalid.config.php ' )));
94
+ $ config = vfsStream::url ('project/config/invalid.config.php ' );
88
95
$ this ->assertErrorRaised ('Configuration at path " ' . $ config . '" does not return an array. ' );
89
96
$ this ->assertHelp (STDERR );
90
97
$ this ->assertEquals (1 , $ command ([$ config , 'Not\A\Real\Class ' ]));
@@ -93,7 +100,10 @@ public function testEmitsErrorWhenConfigurationFileDoesNotReturnArray()
93
100
public function testEmitsErrorWhenClassDoesNotExist ()
94
101
{
95
102
$ command = $ this ->command ;
96
- $ config = realpath (__DIR__ . '/../TestAsset/config/test.config.php ' );
103
+ vfsStream::newFile ('config/test.config.php ' )
104
+ ->at ($ this ->configDir )
105
+ ->setContent (file_get_contents (realpath (__DIR__ . '/../TestAsset/config/test.config.php ' )));
106
+ $ config = vfsStream::url ('project/config/test.config.php ' );
97
107
$ this ->assertErrorRaised ('Class "Not \\A \\Real \\Class" does not exist or could not be autoloaded. ' );
98
108
$ this ->assertHelp (STDERR );
99
109
$ this ->assertEquals (1 , $ command ([$ config , 'Not\A\Real\Class ' ]));
@@ -102,7 +112,10 @@ public function testEmitsErrorWhenClassDoesNotExist()
102
112
public function testEmitsErrorWhenUnableToCreateConfiguration ()
103
113
{
104
114
$ command = $ this ->command ;
105
- $ config = realpath (__DIR__ . '/../TestAsset/config/test.config.php ' );
115
+ vfsStream::newFile ('config/test.config.php ' )
116
+ ->at ($ this ->configDir )
117
+ ->setContent (file_get_contents (realpath (__DIR__ . '/../TestAsset/config/test.config.php ' )));
118
+ $ config = vfsStream::url ('project/config/test.config.php ' );
106
119
$ this ->assertErrorRaised ('Unable to create config for " ' . ObjectWithScalarDependency::class . '": ' );
107
120
$ this ->assertHelp (STDERR );
108
121
$ this ->assertEquals (1 , $ command ([$ config , ObjectWithScalarDependency::class]));
@@ -111,24 +124,23 @@ public function testEmitsErrorWhenUnableToCreateConfiguration()
111
124
public function testEmitsConfigFileToStdoutWhenSuccessful ()
112
125
{
113
126
$ command = $ this ->command ;
114
- $ config = realpath (__DIR__ . '/../TestAsset/config/test.config.php ' );
127
+ vfsStream::newFile ('config/test.config.php ' )
128
+ ->at ($ this ->configDir )
129
+ ->setContent (file_get_contents (realpath (__DIR__ . '/../TestAsset/config/test.config.php ' )));
130
+ $ config = vfsStream::url ('project/config/test.config.php ' );
115
131
116
- $ this ->helper ->write (Argument::that (function ($ config ) {
117
- if (! strstr ($ config , 'return [ ' )) {
118
- return false ;
119
- }
120
-
121
- if (! strstr ($ config , SimpleDependencyObject::class . '::class => [ ' )) {
122
- return false ;
123
- }
124
-
125
- if (! strstr ($ config , InvokableObject::class . '::class => [ ' )) {
126
- return false ;
127
- }
128
-
129
- return true ;
130
- }), false )->shouldBeCalled ();
132
+ $ this ->helper ->writeLine ('<info>[DONE]</info> Changes written to ' . $ config )->shouldBeCalled ();
131
133
132
134
$ this ->assertEquals (0 , $ command ([$ config , SimpleDependencyObject::class]));
135
+
136
+ $ generated = include $ config ;
137
+ $ this ->assertInternalType ('array ' , $ generated );
138
+ $ this ->assertArrayHasKey (ConfigAbstractFactory::class, $ generated );
139
+ $ factoryConfig = $ generated [ConfigAbstractFactory::class];
140
+ $ this ->assertInternalType ('array ' , $ factoryConfig );
141
+ $ this ->assertArrayHasKey (SimpleDependencyObject::class, $ factoryConfig );
142
+ $ this ->assertArrayHasKey (InvokableObject::class, $ factoryConfig );
143
+ $ this ->assertContains (InvokableObject::class, $ factoryConfig [SimpleDependencyObject::class]);
144
+ $ this ->assertEquals ([], $ factoryConfig [InvokableObject::class]);
133
145
}
134
146
}
0 commit comments