diff --git a/.gitignore b/.gitignore index da2119a16..c1adae14d 100755 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ coverage/ .vscode codeception.yml dev/tests/functional/MFTF.suite.yml -dev/tests/functional/_output \ No newline at end of file +dev/tests/functional/_output +dev/tests/mftf.log \ No newline at end of file diff --git a/bin/all-checks.bat b/bin/all-checks.bat new file mode 100644 index 000000000..d910923ce --- /dev/null +++ b/bin/all-checks.bat @@ -0,0 +1,8 @@ +:: Copyright © Magento, Inc. All rights reserved. +:: See COPYING.txt for license details. + +@echo off +call bin\static-checks.bat + +@echo off +call bin\phpunit-checks.bat diff --git a/bin/copyright-check.bat b/bin/copyright-check.bat new file mode 100644 index 000000000..9f2e23bfb --- /dev/null +++ b/bin/copyright-check.bat @@ -0,0 +1,41 @@ +:: Copyright © Magento, Inc. All rights reserved. +:: See COPYING.txt for license details. + +@echo off +SETLOCAL EnableDelayedExpansion +SET BLACKLIST_FILE=bin/blacklist.txt +SET i=0 + +FOR /F %%x IN ('git ls-tree --full-tree -r --name-only HEAD') DO ( + SET GOOD_EXT= + if "%%~xx"==".php" set GOOD_EXT=1 + if "%%~xx"==".xml" set GOOD_EXT=1 + if "%%~xx"==".xsd" set GOOD_EXT=1 + IF DEFINED GOOD_EXT ( + SET BLACKLISTED= + FOR /F "tokens=* skip=5" %%f IN (%BLACKLIST_FILE%) DO ( + SET LINE=%%x + IF NOT "!LINE!"=="!LINE:%%f=!" ( + SET BLACKLISTED=1 + ) + ) + IF NOT DEFINED BLACKLISTED ( + FIND "Copyright © Magento, Inc. All rights reserved." %%x >nul + IF ERRORLEVEL 1 ( + SET /A i+=1 + SET NO_COPYRIGHT_LIST[!i!]=%%x + ) + ) + ) +) + +IF DEFINED NO_COPYRIGHT_LIST[1] ( + ECHO THE FOLLOWING FILES ARE MISSING THE MAGENTO COPYRIGHT: + ECHO. + ECHO Copyright © Magento, Inc. All rights reserved. + ECHO See COPYING.txt for license details. + ECHO. + FOR /L %%a IN (1,1,%i%) DO ( + ECHO !NO_COPYRIGHT_LIST[%%a]! + ) +) \ No newline at end of file diff --git a/bin/static-checks.bat b/bin/static-checks.bat index 0b9402094..5e14dd289 100644 --- a/bin/static-checks.bat +++ b/bin/static-checks.bat @@ -5,17 +5,15 @@ @echo off @echo ===============================PHP CODE SNIFFER REPORT=============================== -call vendor\bin\phpcs .\src --standard=.\dev\tests\static\Magento --ignore=src\Magento\FunctionalTestingFramework\Group,src\Magento\FunctionalTestingFramework\AcceptanceTester.php -call vendor\bin\phpcs .\dev\tests\unit --standard=.\dev\tests\static\Magento -call vendor\bin\phpcs .\dev\tests\verification --standard=.\dev\tests\static\Magento --ignore=dev\tests\verification\_generated +call vendor\bin\phpcs --standard=.\dev\tests\static\Magento --ignore=src/Magento/FunctionalTestingFramework/Group,src/Magento/FunctionalTestingFramework/AcceptanceTester.php .\src +call vendor\bin\phpcs --standard=.\dev\tests\static\Magento .\dev\tests\unit +call vendor\bin\phpcs --standard=.\dev\tests\static\Magento --ignore=dev/tests/verification/_generated .\dev\tests\verification @echo ===============================COPY PASTE DETECTOR REPORT=============================== call vendor\bin\phpcpd .\src -@echo "===============================PHP MESS DETECTOR REPORT=============================== -vendor\bin\phpmd .\src text \dev\tests\static\Magento\CodeMessDetector\ruleset.xml --exclude _generated,src\Magento\FunctionalTestingFramework\Group,src\Magento\FunctionalTestingFramework\AcceptanceTester.php +@echo ===============================PHP MESS DETECTOR REPORT=============================== +call vendor\bin\phpmd --exclude _generated,src\Magento\FunctionalTestingFramework\Group,src\Magento\FunctionalTestingFramework\AcceptanceTester.php .\src text \dev\tests\static\Magento\CodeMessDetector\ruleset.xml @echo ===============================MAGENTO COPYRIGHT REPORT=============================== -echo msgbox "INFO:Copyright check currently not run as part of .bat implementation" > "%temp%\popup.vbs" -wscript.exe "%temp%\popup.vbs" -::bin\copyright-check +call bin\copyright-check.bat diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/Config/Reader/FilesystemTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/Config/Reader/FilesystemTest.php new file mode 100644 index 000000000..b59858e7f --- /dev/null +++ b/dev/tests/unit/Magento/FunctionalTestFramework/Config/Reader/FilesystemTest.php @@ -0,0 +1,108 @@ +setMockLoggingUtil(); + } + + /** + * Test Reading Empty Files + * @throws \Exception + */ + public function testEmptyXmlFile() + { + // create mocked items and read the file + $someFile = $this->setMockFile("somepath.xml", ""); + $filesystem = $this->createPseudoFileSystem($someFile); + $filesystem->read(); + + // validate log statement + TestLoggingUtil::getInstance()->validateMockLogStatement( + "warning", + "XML File is empty.", + ["File" => "somepath.xml"] + ); + } + + /** + * Function used to set mock for File created in test + * + * @param string $fileName + * @param string $content + * @return object + * @throws \Exception + */ + public function setMockFile($fileName, $content) + { + $file = AspectMock::double( + File::class, + [ + 'current' => "", + 'count' => 1, + 'getFilename' => $fileName + ] + )->make(); + + //set mocked data property for File + $property = new \ReflectionProperty(File::class, 'data'); + $property->setAccessible(true); + $property->setValue($file, [$fileName => $content]); + + return $file; + } + + /** + * Function used to set mock for filesystem class during test + * + * @param string $fileList + * @return object + * @throws \Exception + */ + public function createPseudoFileSystem($fileList) + { + $filesystem = AspectMock::double(Filesystem::class)->make(); + + //set resolver to use mocked resolver + $mockFileResolver = AspectMock::double(Module::class, ['get' => $fileList])->make(); + $property = new \ReflectionProperty(Filesystem::class, 'fileResolver'); + $property->setAccessible(true); + $property->setValue($filesystem, $mockFileResolver); + + //set validator to use mocked validator + $mockValidation = AspectMock::double(ValidationState::class, ['isValidationRequired' => false])->make(); + $property = new \ReflectionProperty(Filesystem::class, 'validationState'); + $property->setAccessible(true); + $property->setValue($filesystem, $mockValidation); + + return $filesystem; + } + + /** + * After class functionality + * @return void + */ + public static function tearDownAfterClass() + { + TestLoggingUtil::getInstance()->clearMockLoggingUtil(); + parent::tearDownAfterClass(); + } +} diff --git a/src/Magento/FunctionalTestingFramework/Config/Reader/Filesystem.php b/src/Magento/FunctionalTestingFramework/Config/Reader/Filesystem.php index adcb330ba..e287a84d9 100644 --- a/src/Magento/FunctionalTestingFramework/Config/Reader/Filesystem.php +++ b/src/Magento/FunctionalTestingFramework/Config/Reader/Filesystem.php @@ -5,6 +5,9 @@ */ namespace Magento\FunctionalTestingFramework\Config\Reader; +use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig; +use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil; + /** * Filesystem configuration loader. Loads configuration from XML files, split by scopes. */ @@ -144,6 +147,10 @@ protected function readFiles($fileList) /** @var \Magento\FunctionalTestingFramework\Config\Dom $configMerger */ $configMerger = null; foreach ($fileList as $key => $content) { + //check if file is empty and continue to next if it is + if (!$this->verifyFileEmpty($content, $fileList->getFilename())) { + continue; + } try { if (!$configMerger) { $configMerger = $this->createConfigMerger($this->domDocumentClass, $content); @@ -192,4 +199,25 @@ protected function createConfigMerger($mergerClass, $initialContents) } return $result; } + + /** + * Checks if content is empty and logs warning, returns false if file is empty + * + * @param string $content + * @param string $fileName + * @return bool + */ + protected function verifyFileEmpty($content, $fileName) + { + if (empty($content)) { + if (MftfApplicationConfig::getConfig()->verboseEnabled()) { + LoggingUtil::getInstance()->getLogger(Filesystem::class)->warn( + "XML File is empty.", + ["File" => $fileName] + ); + } + return false; + } + return true; + } } diff --git a/src/Magento/FunctionalTestingFramework/Config/Reader/MftfFilesystem.php b/src/Magento/FunctionalTestingFramework/Config/Reader/MftfFilesystem.php index e39e39199..1106ec9b7 100644 --- a/src/Magento/FunctionalTestingFramework/Config/Reader/MftfFilesystem.php +++ b/src/Magento/FunctionalTestingFramework/Config/Reader/MftfFilesystem.php @@ -25,6 +25,10 @@ public function readFiles($fileList) /** @var \Magento\FunctionalTestingFramework\Test\Config\Dom $configMerger */ $configMerger = null; foreach ($fileList as $key => $content) { + //check if file is empty and continue to next if it is + if (!parent::verifyFileEmpty($content, $fileList->getFilename())) { + continue; + } try { if (!$configMerger) { $configMerger = $this->createConfigMerger(