Skip to content

Commit 8db2e20

Browse files
authored
Merge branch 'develop' into MQE-1027-2
2 parents c54c3b8 + 2f70705 commit 8db2e20

File tree

6 files changed

+195
-8
lines changed

6 files changed

+195
-8
lines changed

bin/all-checks.bat

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
:: Copyright © Magento, Inc. All rights reserved.
2+
:: See COPYING.txt for license details.
3+
4+
@echo off
5+
call bin\static-checks.bat
6+
7+
@echo off
8+
call bin\phpunit-checks.bat

bin/copyright-check.bat

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
:: Copyright © Magento, Inc. All rights reserved.
2+
:: See COPYING.txt for license details.
3+
4+
@echo off
5+
SETLOCAL EnableDelayedExpansion
6+
SET BLACKLIST_FILE=bin/blacklist.txt
7+
SET i=0
8+
9+
FOR /F %%x IN ('git ls-tree --full-tree -r --name-only HEAD') DO (
10+
SET GOOD_EXT=
11+
if "%%~xx"==".php" set GOOD_EXT=1
12+
if "%%~xx"==".xml" set GOOD_EXT=1
13+
if "%%~xx"==".xsd" set GOOD_EXT=1
14+
IF DEFINED GOOD_EXT (
15+
SET BLACKLISTED=
16+
FOR /F "tokens=* skip=5" %%f IN (%BLACKLIST_FILE%) DO (
17+
SET LINE=%%x
18+
IF NOT "!LINE!"=="!LINE:%%f=!" (
19+
SET BLACKLISTED=1
20+
)
21+
)
22+
IF NOT DEFINED BLACKLISTED (
23+
FIND "Copyright © Magento, Inc. All rights reserved." %%x >nul
24+
IF ERRORLEVEL 1 (
25+
SET /A i+=1
26+
SET NO_COPYRIGHT_LIST[!i!]=%%x
27+
)
28+
)
29+
)
30+
)
31+
32+
IF DEFINED NO_COPYRIGHT_LIST[1] (
33+
ECHO THE FOLLOWING FILES ARE MISSING THE MAGENTO COPYRIGHT:
34+
ECHO.
35+
ECHO Copyright © Magento, Inc. All rights reserved.
36+
ECHO See COPYING.txt for license details.
37+
ECHO.
38+
FOR /L %%a IN (1,1,%i%) DO (
39+
ECHO !NO_COPYRIGHT_LIST[%%a]!
40+
)
41+
)

bin/static-checks.bat

+6-8
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55

66
@echo off
77
@echo ===============================PHP CODE SNIFFER REPORT===============================
8-
call vendor\bin\phpcs .\src --standard=.\dev\tests\static\Magento --ignore=src\Magento\FunctionalTestingFramework\Group,src\Magento\FunctionalTestingFramework\AcceptanceTester.php
9-
call vendor\bin\phpcs .\dev\tests\unit --standard=.\dev\tests\static\Magento
10-
call vendor\bin\phpcs .\dev\tests\verification --standard=.\dev\tests\static\Magento --ignore=dev\tests\verification\_generated
8+
call vendor\bin\phpcs --standard=.\dev\tests\static\Magento --ignore=src/Magento/FunctionalTestingFramework/Group,src/Magento/FunctionalTestingFramework/AcceptanceTester.php .\src
9+
call vendor\bin\phpcs --standard=.\dev\tests\static\Magento .\dev\tests\unit
10+
call vendor\bin\phpcs --standard=.\dev\tests\static\Magento --ignore=dev/tests/verification/_generated .\dev\tests\verification
1111

1212
@echo ===============================COPY PASTE DETECTOR REPORT===============================
1313
call vendor\bin\phpcpd .\src
1414

15-
@echo "===============================PHP MESS DETECTOR REPORT===============================
16-
vendor\bin\phpmd .\src text \dev\tests\static\Magento\CodeMessDetector\ruleset.xml --exclude _generated,src\Magento\FunctionalTestingFramework\Group,src\Magento\FunctionalTestingFramework\AcceptanceTester.php
15+
@echo ===============================PHP MESS DETECTOR REPORT===============================
16+
call vendor\bin\phpmd --exclude _generated,src\Magento\FunctionalTestingFramework\Group,src\Magento\FunctionalTestingFramework\AcceptanceTester.php .\src text \dev\tests\static\Magento\CodeMessDetector\ruleset.xml
1717

1818
@echo ===============================MAGENTO COPYRIGHT REPORT===============================
19-
echo msgbox "INFO:Copyright check currently not run as part of .bat implementation" > "%temp%\popup.vbs"
20-
wscript.exe "%temp%\popup.vbs"
21-
::bin\copyright-check
19+
call bin\copyright-check.bat
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Tests\unit\Magento\FunctionalTestFramework\Test\Config\Reader;
7+
8+
use Magento\FunctionalTestingFramework\Config\FileResolver\Module;
9+
use Magento\FunctionalTestingFramework\Config\Reader\Filesystem;
10+
use Magento\FunctionalTestingFramework\Config\ValidationState;
11+
use Magento\FunctionalTestingFramework\Util\Iterator\File;
12+
use PHPUnit\Framework\TestCase;
13+
use AspectMock\Test as AspectMock;
14+
use tests\unit\Util\TestLoggingUtil;
15+
16+
class FilesystemTest extends TestCase
17+
{
18+
/**
19+
* Before test functionality
20+
* @return void
21+
*/
22+
public function setUp()
23+
{
24+
TestLoggingUtil::getInstance()->setMockLoggingUtil();
25+
}
26+
27+
/**
28+
* Test Reading Empty Files
29+
* @throws \Exception
30+
*/
31+
public function testEmptyXmlFile()
32+
{
33+
// create mocked items and read the file
34+
$someFile = $this->setMockFile("somepath.xml", "");
35+
$filesystem = $this->createPseudoFileSystem($someFile);
36+
$filesystem->read();
37+
38+
// validate log statement
39+
TestLoggingUtil::getInstance()->validateMockLogStatement(
40+
"warning",
41+
"XML File is empty.",
42+
["File" => "somepath.xml"]
43+
);
44+
}
45+
46+
/**
47+
* Function used to set mock for File created in test
48+
*
49+
* @param string $fileName
50+
* @param string $content
51+
* @return object
52+
* @throws \Exception
53+
*/
54+
public function setMockFile($fileName, $content)
55+
{
56+
$file = AspectMock::double(
57+
File::class,
58+
[
59+
'current' => "",
60+
'count' => 1,
61+
'getFilename' => $fileName
62+
]
63+
)->make();
64+
65+
//set mocked data property for File
66+
$property = new \ReflectionProperty(File::class, 'data');
67+
$property->setAccessible(true);
68+
$property->setValue($file, [$fileName => $content]);
69+
70+
return $file;
71+
}
72+
73+
/**
74+
* Function used to set mock for filesystem class during test
75+
*
76+
* @param string $fileList
77+
* @return object
78+
* @throws \Exception
79+
*/
80+
public function createPseudoFileSystem($fileList)
81+
{
82+
$filesystem = AspectMock::double(Filesystem::class)->make();
83+
84+
//set resolver to use mocked resolver
85+
$mockFileResolver = AspectMock::double(Module::class, ['get' => $fileList])->make();
86+
$property = new \ReflectionProperty(Filesystem::class, 'fileResolver');
87+
$property->setAccessible(true);
88+
$property->setValue($filesystem, $mockFileResolver);
89+
90+
//set validator to use mocked validator
91+
$mockValidation = AspectMock::double(ValidationState::class, ['isValidationRequired' => false])->make();
92+
$property = new \ReflectionProperty(Filesystem::class, 'validationState');
93+
$property->setAccessible(true);
94+
$property->setValue($filesystem, $mockValidation);
95+
96+
return $filesystem;
97+
}
98+
99+
/**
100+
* After class functionality
101+
* @return void
102+
*/
103+
public static function tearDownAfterClass()
104+
{
105+
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
106+
parent::tearDownAfterClass();
107+
}
108+
}

src/Magento/FunctionalTestingFramework/Config/Reader/Filesystem.php

+28
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\FunctionalTestingFramework\Config\Reader;
77

8+
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
9+
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
10+
811
/**
912
* Filesystem configuration loader. Loads configuration from XML files, split by scopes.
1013
*/
@@ -144,6 +147,10 @@ protected function readFiles($fileList)
144147
/** @var \Magento\FunctionalTestingFramework\Config\Dom $configMerger */
145148
$configMerger = null;
146149
foreach ($fileList as $key => $content) {
150+
//check if file is empty and continue to next if it is
151+
if (!$this->verifyFileEmpty($content, $fileList->getFilename())) {
152+
continue;
153+
}
147154
try {
148155
if (!$configMerger) {
149156
$configMerger = $this->createConfigMerger($this->domDocumentClass, $content);
@@ -192,4 +199,25 @@ protected function createConfigMerger($mergerClass, $initialContents)
192199
}
193200
return $result;
194201
}
202+
203+
/**
204+
* Checks if content is empty and logs warning, returns false if file is empty
205+
*
206+
* @param string $content
207+
* @param string $fileName
208+
* @return bool
209+
*/
210+
protected function verifyFileEmpty($content, $fileName)
211+
{
212+
if (empty($content)) {
213+
if (MftfApplicationConfig::getConfig()->verboseEnabled()) {
214+
LoggingUtil::getInstance()->getLogger(Filesystem::class)->warn(
215+
"XML File is empty.",
216+
["File" => $fileName]
217+
);
218+
}
219+
return false;
220+
}
221+
return true;
222+
}
195223
}

src/Magento/FunctionalTestingFramework/Config/Reader/MftfFilesystem.php

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public function readFiles($fileList)
2525
/** @var \Magento\FunctionalTestingFramework\Test\Config\Dom $configMerger */
2626
$configMerger = null;
2727
foreach ($fileList as $key => $content) {
28+
//check if file is empty and continue to next if it is
29+
if (!parent::verifyFileEmpty($content, $fileList->getFilename())) {
30+
continue;
31+
}
2832
try {
2933
if (!$configMerger) {
3034
$configMerger = $this->createConfigMerger(

0 commit comments

Comments
 (0)