Skip to content

Commit 3b814c5

Browse files
author
Yevhen Miroshnychenko
committed
MAGETWO-92986: Write Logs for Failed Process of Generating Factories in Extensions
1 parent 0083bd3 commit 3b814c5

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

dev/tests/integration/testsuite/Magento/Framework/Code/GeneratorTest.php

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,21 @@ class GeneratorTest extends \PHPUnit\Framework\TestCase
4444
*/
4545
protected $logDirectory;
4646

47+
/**
48+
* @var int
49+
*/
50+
protected $oldPermissionGenerationDir;
51+
52+
/**
53+
* @inheritdoc
54+
*/
4755
protected function setUp()
4856
{
4957
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
5058
/** @var Filesystem $filesystem */
5159
$filesystem = $objectManager->get(\Magento\Framework\Filesystem::class);
5260
$this->generatedDirectory = $filesystem->getDirectoryWrite(DirectoryList::GENERATED_CODE);
5361
$this->logDirectory = $filesystem->getDirectoryRead(DirectoryList::LOG);
54-
$this->generatedDirectory->create();
5562
$generatedDirectory = $this->generatedDirectory->getAbsolutePath();
5663
$this->_ioObject = new \Magento\Framework\Code\Generator\Io(
5764
new \Magento\Framework\Filesystem\Driver\File(),
@@ -72,13 +79,25 @@ protected function setUp()
7279
]
7380
);
7481
$this->_generator->setObjectManager($objectManager);
82+
83+
if (file_exists($generatedDirectory)) {
84+
$this->oldPermissionGenerationDir = fileperms($generatedDirectory);
85+
}
7586
}
7687

7788
protected function tearDown()
7889
{
7990
$this->generatedDirectory->changePermissionsRecursively('./', 0777, 0666);
8091
$this->generatedDirectory->delete();
8192
$this->_generator = null;
93+
94+
if ($this->oldPermissionGenerationDir) {
95+
mkdir(
96+
$this->generatedDirectory->getAbsolutePath(),
97+
$this->oldPermissionGenerationDir,
98+
true
99+
);
100+
}
82101
}
83102

84103
protected function _clearDocBlock($classBody)
@@ -195,23 +214,20 @@ public function testGenerateClassExtensionAttributesInterfaceFactoryWithNamespac
195214

196215
public function testGeneratorClassWithErrorSaveClassFile()
197216
{
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, '
199218
. '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';
206220

207221
$this->expectException(\RuntimeException::class);
208-
$this->expectExceptionMessageRegExp($exceptionMessageRegExp);
222+
$this->expectExceptionMessageRegExp("/^$msgPart.*/");
209223
$this->generatedDirectory->changePermissionsRecursively('./', 0555, 0444);
210224
$factoryClassName = self::CLASS_NAME_WITH_NAMESPACE . 'ExtensionInterfaceFactory';
211225

212226
$generatorResult = $this->_generator->generateClass($factoryClassName);
213227
$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]);
216232
}
217233
}

0 commit comments

Comments
 (0)