16
16
require_once __DIR__ . '/GeneratorTest/SourceClassWithNamespace.php ' ;
17
17
require_once __DIR__ . '/GeneratorTest/ParentClassWithNamespace.php ' ;
18
18
require_once __DIR__ . '/GeneratorTest/SourceClassWithNamespaceExtension.php ' ;
19
+ require_once __DIR__ . '/GeneratorTest/NestedNamespace/SourceClassWithNestedNamespace.php ' ;
20
+ require_once __DIR__ . '/GeneratorTest/NestedNamespace/SourceClassWithNestedNamespaceExtension.php ' ;
19
21
20
22
/**
21
23
* @magentoAppIsolation enabled
24
26
class GeneratorTest extends TestCase
25
27
{
26
28
const CLASS_NAME_WITH_NAMESPACE = GeneratorTest \SourceClassWithNamespace::class;
29
+ const CLASS_NAME_WITH_NESTED_NAMESPACE = GeneratorTest \NestedNamespace \SourceClassWithNestedNamespace::class;
30
+ const EXTENSION_CLASS_NAME_WITH_NAMESPACE = GeneratorTest \SourceClassWithNamespaceExtension::class;
31
+ const EXTENSION_CLASS_NAME_WITH_NESTED_NAMESPACE =
32
+ GeneratorTest \NestedNamespace \SourceClassWithNestedNamespaceExtension::class;
27
33
28
34
/**
29
35
* @var Generator
@@ -59,6 +65,7 @@ protected function setUp(): void
59
65
/** @var Filesystem $filesystem */
60
66
$ filesystem = $ objectManager ->get (Filesystem::class);
61
67
$ this ->generatedDirectory = $ filesystem ->getDirectoryWrite (DirectoryList::GENERATED_CODE );
68
+ $ this ->generatedDirectory ->create ($ this ->testRelativePath );
62
69
$ this ->logDirectory = $ filesystem ->getDirectoryRead (DirectoryList::LOG );
63
70
$ generatedDirectoryAbsolutePath = $ this ->generatedDirectory ->getAbsolutePath ();
64
71
$ this ->_ioObject = new Generator \Io (new Filesystem \Driver \File (), $ generatedDirectoryAbsolutePath );
@@ -98,78 +105,99 @@ protected function _clearDocBlock($classBody)
98
105
}
99
106
100
107
/**
101
- * Generates a new file with Factory class and compares with the sample from the
102
- * SourceClassWithNamespaceFactory.php.sample file.
108
+ * Generates a new class Factory file and compares with the sample.
109
+ *
110
+ * @param $className
111
+ * @param $generateType
112
+ * @param $expectedDataPath
113
+ * @dataProvider generateClassFactoryDataProvider
103
114
*/
104
- public function testGenerateClassFactoryWithNamespace ( )
115
+ public function testGenerateClassFactory ( $ className , $ generateType , $ expectedDataPath )
105
116
{
106
- $ factoryClassName = self :: CLASS_NAME_WITH_NAMESPACE . ' Factory ' ;
117
+ $ factoryClassName = $ className . $ generateType ;
107
118
$ this ->assertEquals (Generator::GENERATION_SUCCESS , $ this ->_generator ->generateClass ($ factoryClassName ));
108
119
$ factory = Bootstrap::getObjectManager ()->create ($ factoryClassName );
109
- $ this ->assertInstanceOf (self :: CLASS_NAME_WITH_NAMESPACE , $ factory ->create ());
120
+ $ this ->assertInstanceOf ($ className , $ factory ->create ());
110
121
$ content = $ this ->_clearDocBlock (
111
122
file_get_contents ($ this ->_ioObject ->generateResultFileName ($ factoryClassName ))
112
123
);
113
124
$ expectedContent = $ this ->_clearDocBlock (
114
- file_get_contents (__DIR__ . ' /_expected/SourceClassWithNamespaceFactory.php.sample ' )
125
+ file_get_contents (__DIR__ . $ expectedDataPath )
115
126
);
116
127
$ this ->assertEquals ($ expectedContent , $ content );
117
128
}
118
129
119
130
/**
120
- * Generates a new file with Proxy class and compares with the sample from the
121
- * SourceClassWithNamespaceProxy.php.sample file.
131
+ * DataProvider for testGenerateClassFactory
132
+ *
133
+ * @return array
122
134
*/
123
- public function testGenerateClassProxyWithNamespace ()
135
+ public function generateClassFactoryDataProvider ()
124
136
{
125
- $ proxyClassName = self ::CLASS_NAME_WITH_NAMESPACE . '\Proxy ' ;
126
- $ this ->assertEquals (Generator::GENERATION_SUCCESS , $ this ->_generator ->generateClass ($ proxyClassName ));
127
- $ proxy = Bootstrap::getObjectManager ()->create ($ proxyClassName );
128
- $ this ->assertInstanceOf (self ::CLASS_NAME_WITH_NAMESPACE , $ proxy );
129
- $ content = $ this ->_clearDocBlock (
130
- file_get_contents ($ this ->_ioObject ->generateResultFileName ($ proxyClassName ))
131
- );
132
- $ expectedContent = $ this ->_clearDocBlock (
133
- file_get_contents (__DIR__ . '/_expected/SourceClassWithNamespaceProxy.php.sample ' )
134
- );
135
- $ this ->assertEquals ($ expectedContent , $ content );
137
+ return [
138
+ 'factory_with_namespace ' => [
139
+ 'className ' => self ::CLASS_NAME_WITH_NAMESPACE ,
140
+ 'generateType ' => 'Factory ' ,
141
+ 'expectedDataPath ' => '/_expected/SourceClassWithNamespaceFactory.php.sample '
142
+ ],
143
+ 'factory_with_nested_namespace ' => [
144
+ 'classToGenerate ' => self ::CLASS_NAME_WITH_NESTED_NAMESPACE ,
145
+ 'generateType ' => 'Factory ' ,
146
+ 'expectedDataPath ' => '/_expected/SourceClassWithNestedNamespaceFactory.php.sample '
147
+ ],
148
+ 'ext_interface_factory_with_namespace ' => [
149
+ 'classToGenerate ' => self ::EXTENSION_CLASS_NAME_WITH_NAMESPACE ,
150
+ 'generateType ' => 'InterfaceFactory ' ,
151
+ 'expectedDataPath ' => '/_expected/SourceClassWithNamespaceExtensionInterfaceFactory.php.sample '
152
+ ],
153
+ 'ext_interface_factory_with_nested_namespace ' => [
154
+ 'classToGenerate ' => self ::EXTENSION_CLASS_NAME_WITH_NESTED_NAMESPACE ,
155
+ 'generateType ' => 'InterfaceFactory ' ,
156
+ 'expectedDataPath ' => '/_expected/SourceClassWithNestedNamespaceExtensionInterfaceFactory.php.sample '
157
+ ],
158
+ ];
136
159
}
137
160
138
161
/**
139
- * Generates a new file with Interceptor class and compares with the sample from the
140
- * SourceClassWithNamespaceInterceptor.php.sample file.
162
+ * @param $className
163
+ * @param $generateType
164
+ * @param $expectedDataPath
165
+ * @dataProvider generateClassDataProvider
141
166
*/
142
- public function testGenerateClassInterceptorWithNamespace ( )
167
+ public function testGenerateClass ( $ className , $ generateType , $ expectedDataPath )
143
168
{
144
- $ interceptorClassName = self ::CLASS_NAME_WITH_NAMESPACE . '\Interceptor ' ;
145
- $ this ->assertEquals (Generator::GENERATION_SUCCESS , $ this ->_generator ->generateClass ($ interceptorClassName ));
169
+ $ generateClassName = $ className . $ generateType ;
170
+ $ this ->assertEquals (Generator::GENERATION_SUCCESS , $ this ->_generator ->generateClass ($ generateClassName ));
171
+ $ instance = Bootstrap::getObjectManager ()->create ($ generateClassName );
172
+ $ this ->assertInstanceOf ($ className , $ instance );
146
173
$ content = $ this ->_clearDocBlock (
147
- file_get_contents ($ this ->_ioObject ->generateResultFileName ($ interceptorClassName ))
174
+ file_get_contents ($ this ->_ioObject ->generateResultFileName ($ generateClassName ))
148
175
);
149
176
$ expectedContent = $ this ->_clearDocBlock (
150
- file_get_contents (__DIR__ . ' /_expected/SourceClassWithNamespaceInterceptor.php.sample ' )
177
+ file_get_contents (__DIR__ . $ expectedDataPath )
151
178
);
152
179
$ this ->assertEquals ($ expectedContent , $ content );
153
180
}
154
181
155
182
/**
156
- * Generates a new file with ExtensionInterfaceFactory class and compares with the sample from the
157
- * SourceClassWithNamespaceExtensionInterfaceFactory.php.sample file.
183
+ * DataProvider for testGenerateClass
184
+ *
185
+ * @return array
158
186
*/
159
- public function testGenerateClassExtensionAttributesInterfaceFactoryWithNamespace ()
187
+ public function generateClassDataProvider ()
160
188
{
161
- $ factoryClassName = self :: CLASS_NAME_WITH_NAMESPACE . ' ExtensionInterfaceFactory ' ;
162
- $ this -> generatedDirectory -> create ( $ this -> testRelativePath );
163
- $ this -> assertEquals (Generator:: GENERATION_SUCCESS , $ this -> _generator -> generateClass ( $ factoryClassName ));
164
- $ factory = Bootstrap:: getObjectManager ()-> create ( $ factoryClassName );
165
- $ this -> assertInstanceOf ( self :: CLASS_NAME_WITH_NAMESPACE . ' Extension ' , $ factory -> create ());
166
- $ content = $ this -> _clearDocBlock (
167
- file_get_contents ( $ this -> _ioObject -> generateResultFileName ( $ factoryClassName ))
168
- );
169
- $ expectedContent = $ this -> _clearDocBlock (
170
- file_get_contents ( __DIR__ . ' /_expected/SourceClassWithNamespaceExtensionInterfaceFactory .php.sample ')
171
- );
172
- $ this -> assertEquals ( $ expectedContent , $ content ) ;
189
+ return [
190
+ ' proxy ' => [
191
+ ' className ' => self :: CLASS_NAME_WITH_NAMESPACE ,
192
+ ' generateType ' => ' \Proxy ' ,
193
+ ' expectedDataPath ' => ' /_expected/SourceClassWithNamespaceProxy.php.sample '
194
+ ],
195
+ ' interceptor ' => [
196
+ ' className ' => self :: CLASS_NAME_WITH_NAMESPACE ,
197
+ ' generateType ' => ' \Interceptor ' ,
198
+ ' expectedDataPath ' => ' /_expected/SourceClassWithNamespaceInterceptor .php.sample '
199
+ ]
200
+ ] ;
173
201
}
174
202
175
203
/**
@@ -183,7 +211,6 @@ public function testGeneratorClassWithErrorSaveClassFile()
183
211
$ regexpMsgPart = preg_quote ($ msgPart );
184
212
$ this ->expectException (\RuntimeException::class);
185
213
$ this ->expectExceptionMessageMatches ("/.* $ regexpMsgPart.*/ " );
186
- $ this ->generatedDirectory ->create ($ this ->testRelativePath );
187
214
$ this ->generatedDirectory ->changePermissionsRecursively ($ this ->testRelativePath , 0555 , 0444 );
188
215
$ generatorResult = $ this ->_generator ->generateClass ($ factoryClassName );
189
216
$ this ->assertFalse ($ generatorResult );
0 commit comments