5
5
*/
6
6
namespace Magento \Framework \Code \Test \Unit \Generator ;
7
7
8
- use Magento \Framework \Exception \FileSystemException ;
9
- use Magento \Framework \Phrase ;
10
- use Magento \Framework \DataObject ;
11
- use Magento \Framework \DataObject_MyResult ;
12
- use PHPUnit \Framework \TestCase ;
13
- use Magento \Framework \Code \Generator \EntityAbstract ;
14
- use Magento \Framework \Code \Generator \Io ;
15
- use Magento \Framework \Code \Generator \ClassGenerator ;
16
- use Magento \Framework \Code \Generator \DefinedClasses ;
17
- use \PHPUnit_Framework_MockObject_MockObject as Mock ;
18
-
19
- class EntityAbstractTest extends TestCase
8
+ class EntityAbstractTest extends \PHPUnit \Framework \TestCase
20
9
{
21
10
/**#@+
22
11
* Source and result class parameters
@@ -44,7 +33,7 @@ class EntityAbstractTest extends TestCase
44
33
/**
45
34
* Model under test
46
35
*
47
- * @var EntityAbstract|Mock
36
+ * @var \Magento\Framework\Code\Generator\ EntityAbstract| \PHPUnit_Framework_MockObject_MockObject
48
37
*/
49
38
protected $ _model ;
50
39
@@ -60,9 +49,9 @@ class EntityAbstractTest extends TestCase
60
49
61
50
protected function setUp ()
62
51
{
63
- $ this ->sourceClass = '\\' . DataObject::class;
64
- $ this ->resultClass = '\\' . DataObject_MyResult::class;
65
- $ this ->_model = $ this ->getMockForAbstractClass (EntityAbstract::class);
52
+ $ this ->sourceClass = '\\' . \ Magento \ Framework \ DataObject::class;
53
+ $ this ->resultClass = '\\' . \ Magento \ Framework \ DataObject_MyResult::class;
54
+ $ this ->_model = $ this ->getMockForAbstractClass (\ Magento \ Framework \ Code \ Generator \ EntityAbstract::class);
66
55
}
67
56
68
57
protected function tearDown ()
@@ -75,26 +64,37 @@ public function testConstruct()
75
64
// without parameters
76
65
$ this ->assertAttributeEmpty ('_sourceClassName ' , $ this ->_model );
77
66
$ this ->assertAttributeEmpty ('_resultClassName ' , $ this ->_model );
78
- $ this ->assertAttributeInstanceOf (Io::class, '_ioObject ' , $ this ->_model );
79
- $ this ->assertAttributeInstanceOf (ClassGenerator::class, '_classGenerator ' , $ this ->_model );
80
- $ this ->assertAttributeInstanceOf (DefinedClasses::class, 'definedClasses ' , $ this ->_model );
67
+ $ this ->assertAttributeInstanceOf (\Magento \Framework \Code \Generator \Io::class, '_ioObject ' , $ this ->_model );
68
+ $ this ->assertAttributeInstanceOf (
69
+ \Magento \Framework \Code \Generator \ClassGenerator::class,
70
+ '_classGenerator ' ,
71
+ $ this ->_model
72
+ );
73
+ $ this ->assertAttributeInstanceOf (
74
+ \Magento \Framework \Code \Generator \DefinedClasses::class,
75
+ 'definedClasses ' ,
76
+ $ this ->_model
77
+ );
81
78
82
79
// with source class name
83
- $ this ->_model = $ this ->getMockForAbstractClass (EntityAbstract::class, [$ this ->sourceClass ]);
80
+ $ this ->_model = $ this ->getMockForAbstractClass (
81
+ \Magento \Framework \Code \Generator \EntityAbstract::class,
82
+ [$ this ->sourceClass ]
83
+ );
84
84
$ this ->assertAttributeEquals ($ this ->sourceClass , '_sourceClassName ' , $ this ->_model );
85
85
$ this ->assertAttributeEquals ($ this ->sourceClass . 'Abstract ' , '_resultClassName ' , $ this ->_model );
86
86
87
87
// with all arguments
88
88
// Configure IoObject mock
89
- $ ioObject = $ this ->getMockBuilder (Io::class)
89
+ $ ioObject = $ this ->getMockBuilder (\ Magento \ Framework \ Code \ Generator \ Io::class)
90
90
->disableOriginalConstructor ()
91
91
->getMock ();
92
- $ codeGenerator = $ this ->getMockBuilder (ClassGenerator::class)
92
+ $ codeGenerator = $ this ->getMockBuilder (\ Magento \ Framework \ Code \ Generator \ ClassGenerator::class)
93
93
->disableOriginalConstructor ()
94
94
->getMock ();
95
95
96
96
$ this ->_model = $ this ->getMockForAbstractClass (
97
- EntityAbstract::class,
97
+ \ Magento \ Framework \ Code \ Generator \ EntityAbstract::class,
98
98
[$ this ->sourceClass , $ this ->resultClass , $ ioObject , $ codeGenerator ]
99
99
);
100
100
$ this ->assertAttributeEquals ($ this ->resultClass , '_resultClassName ' , $ this ->_model );
@@ -186,7 +186,7 @@ public function testGenerate(
186
186
}
187
187
$ abstractGetters = ['_getClassProperties ' , '_getClassMethods ' ];
188
188
$ this ->_model = $ this ->getMockForAbstractClass (
189
- EntityAbstract::class,
189
+ \ Magento \ Framework \ Code \ Generator \ EntityAbstract::class,
190
190
$ arguments ,
191
191
'' ,
192
192
true ,
@@ -209,51 +209,6 @@ public function testGenerate(
209
209
}
210
210
}
211
211
212
- /**
213
- * @inheritdoc
214
- */
215
- public function testGenerateFailure ()
216
- {
217
- $ infoMessage = 'Error: an object of a generated class may be a dependency for another object, but this '
218
- . 'dependency has not been defined or set correctly in the signature of the related construct method. '
219
- . 'Due to the current error, executing the CLI commands `bin/magento setup:di:compile` or `bin/magento '
220
- . 'deploy:mode:set production` does not create the required generated classes. '
221
- . 'Magento cannot write a class file to the "generated" directory that is read-only. Before using the '
222
- . 'read-only file system, the classes to be generated must be created beforehand in the "generated" '
223
- . 'directory. For details, see the "File systems access permissions" topic at http://devdocs.magento.com. ' ;
224
-
225
- $ exceptionMessage = 'Some description ' ;
226
-
227
- $ abstractGetters = ['_getClassProperties ' , '_getClassMethods ' ];
228
-
229
- $ arguments = $ this ->_prepareMocksForGenerateCode (true );
230
-
231
- /** @var Io|Mock $ioObjectMock */
232
- $ ioObjectMock = $ arguments ['io_object ' ];
233
- $ ioObjectMock ->expects ($ this ->once ())
234
- ->method ('writeResultFile ' )
235
- ->with (self ::RESULT_FILE , self ::RESULT_CODE )
236
- ->willThrowException (new FileSystemException (new Phrase ($ exceptionMessage )));
237
-
238
- $ this ->_model = $ this ->getMockForAbstractClass (
239
- EntityAbstract::class,
240
- $ arguments ,
241
- '' ,
242
- true ,
243
- true ,
244
- true ,
245
- $ abstractGetters
246
- );
247
- // we need to mock abstract methods to set correct return value type
248
- foreach ($ abstractGetters as $ methodName ) {
249
- $ this ->_model ->expects ($ this ->any ())->method ($ methodName )->will ($ this ->returnValue ([]));
250
- }
251
-
252
- $ result = $ this ->_model ->generate ();
253
- $ this ->assertFalse ($ result );
254
- $ this ->assertEquals ([$ infoMessage , $ exceptionMessage ], $ this ->_model ->getErrors ());
255
- }
256
-
257
212
/**
258
213
* Prepares mocks for validation verification
259
214
*
@@ -271,7 +226,7 @@ protected function _prepareMocksForValidateData(
271
226
$ resultFileExists = false
272
227
) {
273
228
// Configure DefinedClasses mock
274
- $ definedClassesMock = $ this ->createMock (DefinedClasses::class);
229
+ $ definedClassesMock = $ this ->createMock (\ Magento \ Framework \ Code \ Generator \ DefinedClasses::class);
275
230
$ definedClassesMock ->expects ($ this ->once ())
276
231
->method ('isClassLoadable ' )
277
232
->with ($ this ->sourceClass )
@@ -284,7 +239,7 @@ protected function _prepareMocksForValidateData(
284
239
}
285
240
286
241
// Configure IoObject mock
287
- $ ioObject = $ this ->getMockBuilder (Io::class)
242
+ $ ioObject = $ this ->getMockBuilder (\ Magento \ Framework \ Code \ Generator \ Io::class)
288
243
->disableOriginalConstructor ()
289
244
->getMock ();
290
245
@@ -317,7 +272,7 @@ protected function _prepareMocksForGenerateCode($willWriteCode)
317
272
// Configure mocks for the validation step
318
273
$ mocks = $ this ->_prepareMocksForValidateData ();
319
274
320
- $ codeGenerator = $ this ->getMockBuilder (ClassGenerator::class)
275
+ $ codeGenerator = $ this ->getMockBuilder (\ Magento \ Framework \ Code \ Generator \ ClassGenerator::class)
321
276
->disableOriginalConstructor ()
322
277
->getMock ();
323
278
@@ -334,7 +289,7 @@ protected function _prepareMocksForGenerateCode($willWriteCode)
334
289
->will ($ this ->returnValue ($ willWriteCode ? self ::RESULT_CODE : null ));
335
290
336
291
// Add configuration for the generation step
337
- /** @var Io|Mock $ioObject */
292
+ /** @var $ioObject \PHPUnit_Framework_MockObject_MockObject */
338
293
$ ioObject = $ mocks ['io_object ' ];
339
294
if ($ willWriteCode ) {
340
295
$ ioObject ->expects ($ this ->once ())->method ('writeResultFile ' )->with (self ::RESULT_FILE , self ::RESULT_CODE );
0 commit comments