@@ -44,14 +44,21 @@ class GeneratorTest extends \PHPUnit\Framework\TestCase
44
44
*/
45
45
protected $ logDirectory ;
46
46
47
+ /**
48
+ * @var int
49
+ */
50
+ protected $ oldPermissionGenerationDir ;
51
+
52
+ /**
53
+ * @inheritdoc
54
+ */
47
55
protected function setUp ()
48
56
{
49
57
$ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
50
58
/** @var Filesystem $filesystem */
51
59
$ filesystem = $ objectManager ->get (\Magento \Framework \Filesystem::class);
52
60
$ this ->generatedDirectory = $ filesystem ->getDirectoryWrite (DirectoryList::GENERATED_CODE );
53
61
$ this ->logDirectory = $ filesystem ->getDirectoryRead (DirectoryList::LOG );
54
- $ this ->generatedDirectory ->create ();
55
62
$ generatedDirectory = $ this ->generatedDirectory ->getAbsolutePath ();
56
63
$ this ->_ioObject = new \Magento \Framework \Code \Generator \Io (
57
64
new \Magento \Framework \Filesystem \Driver \File (),
@@ -72,13 +79,25 @@ protected function setUp()
72
79
]
73
80
);
74
81
$ this ->_generator ->setObjectManager ($ objectManager );
82
+
83
+ if (file_exists ($ generatedDirectory )) {
84
+ $ this ->oldPermissionGenerationDir = fileperms ($ generatedDirectory );
85
+ }
75
86
}
76
87
77
88
protected function tearDown ()
78
89
{
79
90
$ this ->generatedDirectory ->changePermissionsRecursively ('./ ' , 0777 , 0666 );
80
91
$ this ->generatedDirectory ->delete ();
81
92
$ this ->_generator = null ;
93
+
94
+ if ($ this ->oldPermissionGenerationDir ) {
95
+ mkdir (
96
+ $ this ->generatedDirectory ->getAbsolutePath (),
97
+ $ this ->oldPermissionGenerationDir ,
98
+ true
99
+ );
100
+ }
82
101
}
83
102
84
103
protected function _clearDocBlock ($ classBody )
@@ -195,23 +214,20 @@ public function testGenerateClassExtensionAttributesInterfaceFactoryWithNamespac
195
214
196
215
public function testGeneratorClassWithErrorSaveClassFile ()
197
216
{
198
- $ exceptionMessageRegExp = '/ Error: an object of a generated class may be a dependency for another object, '
217
+ $ msgPart = 'Error: an object of a generated class may be a dependency for another object, '
199
218
. 'but this dependency has not been defined or set correctly in the signature of the related construct '
200
- . 'method\. Due to the current error, executing the CLI commands `bin\/magento setup:di:compile` '
201
- . 'or `bin\/magento deploy:mode:set production` does not create the required generated classes\. Magento '
202
- . 'cannot write a class file to the "generated" directory that is read-only\. Before using the read-only '
203
- . 'file system, the classes to be generated must be created beforehand in the "generated" directory\. '
204
- . 'For details, see the "File systems access permissions" topic at http:\/\/devdocs\.magento\.com\.\n '
205
- . 'The specified ".*" file couldn \'t be written. in \[.*\]/ ' ;
219
+ . 'method ' ;
206
220
207
221
$ this ->expectException (\RuntimeException::class);
208
- $ this ->expectExceptionMessageRegExp ($ exceptionMessageRegExp );
222
+ $ this ->expectExceptionMessageRegExp (" /^ $ msgPart .*/ " );
209
223
$ this ->generatedDirectory ->changePermissionsRecursively ('./ ' , 0555 , 0444 );
210
224
$ factoryClassName = self ::CLASS_NAME_WITH_NAMESPACE . 'ExtensionInterfaceFactory ' ;
211
225
212
226
$ generatorResult = $ this ->_generator ->generateClass ($ factoryClassName );
213
227
$ this ->assertFalse ($ generatorResult );
214
- $ pathToSystemLog = $ this ->logDirectory ->getAbsolutePath ('system.log ' );
215
- $ this ->assertRegexp ($ exceptionMessageRegExp , file_get_contents ($ pathToSystemLog ));
228
+
229
+ $ pathToSystemLog = $ this ->logDirectory ->getAbsolutePath ('system.log ' );
230
+ $ logs = array_slice (file ($ pathToSystemLog ), -2 );
231
+ $ this ->assertContains ($ msgPart , $ logs [0 ]);
216
232
}
217
233
}
0 commit comments