Skip to content

Commit 4e65764

Browse files
committed
Merge branch 'develop' into MQE-1016
2 parents a5aa84c + 371f352 commit 4e65764

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+569
-144
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ coverage/
1313
.vscode
1414
codeception.yml
1515
dev/tests/functional/MFTF.suite.yml
16-
dev/tests/functional/_output
16+
dev/tests/functional/_output
17+
dev/mftf.log
18+
dev/tests/mftf.log

bin/all-checks.bat

Lines changed: 8 additions & 0 deletions
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

Lines changed: 41 additions & 0 deletions
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

Lines changed: 6 additions & 8 deletions
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
Lines changed: 108 additions & 0 deletions
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+
}

dev/tests/unit/Magento/FunctionalTestFramework/Util/ModuleResolverTest.php

Lines changed: 100 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use AspectMock\Proxy\Verifier;
1010
use AspectMock\Test as AspectMock;
1111

12+
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
13+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
1214
use Magento\FunctionalTestingFramework\ObjectManager;
1315
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
1416
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
@@ -54,9 +56,10 @@ public function testGetModulePathsAlreadySet()
5456
*/
5557
public function testGetModulePathsAggregate()
5658
{
57-
$this->setMockResolverClass(false, null, null, null, ["example" . DIRECTORY_SEPARATOR . "paths"]);
59+
$this->mockForceGenerate(false);
60+
$this->setMockResolverClass(false, null, null, null, ["example" => "example" . DIRECTORY_SEPARATOR . "paths"]);
5861
$resolver = ModuleResolver::getInstance();
59-
$this->setMockResolverProperties($resolver, null, null);
62+
$this->setMockResolverProperties($resolver, null, [0 => "Magento_example"]);
6063
$this->assertEquals(
6164
[
6265
"example" . DIRECTORY_SEPARATOR . "paths",
@@ -73,12 +76,13 @@ public function testGetModulePathsAggregate()
7376
*/
7477
public function testGetModulePathsLocations()
7578
{
79+
$this->mockForceGenerate(false);
7680
$mockResolver = $this->setMockResolverClass(
77-
false,
78-
null,
81+
true,
82+
[0 => "magento_example"],
7983
null,
8084
null,
81-
["example" . DIRECTORY_SEPARATOR . "paths"]
85+
["example" => "example" . DIRECTORY_SEPARATOR . "paths"]
8286
);
8387
$resolver = ModuleResolver::getInstance();
8488
$this->setMockResolverProperties($resolver, null, null);
@@ -166,15 +170,78 @@ function ($arg1, $arg2) {
166170
}
167171

168172
/**
169-
* Validate that getEnabledModules returns correctly with no admin token
173+
* Validate that getEnabledModules errors out when no Admin Token is returned and --force is false
170174
* @throws \Exception
171175
*/
172176
public function testGetModulePathsNoAdminToken()
173177
{
178+
// Set --force to false
179+
$this->mockForceGenerate(false);
180+
181+
// Mock ModuleResolver and $enabledModulesPath
174182
$this->setMockResolverClass(false, null, ["example" . DIRECTORY_SEPARATOR . "paths"], []);
175183
$resolver = ModuleResolver::getInstance();
176184
$this->setMockResolverProperties($resolver, null, null);
177-
$this->assertEquals(["example" . DIRECTORY_SEPARATOR . "paths"], $resolver->getModulesPath());
185+
186+
// Cannot Generate if no --force was passed in and no Admin Token is returned succesfully
187+
$this->expectException(TestFrameworkException::class);
188+
$resolver->getModulesPath();
189+
}
190+
191+
/**
192+
* Validates that getAdminToken is not called when --force is enabled
193+
*/
194+
public function testGetAdminTokenNotCalledWhenForce()
195+
{
196+
// Set --force to true
197+
$this->mockForceGenerate(true);
198+
199+
// Mock ModuleResolver and applyCustomModuleMethods()
200+
$mockResolver = $this->setMockResolverClass();
201+
$resolver = ModuleResolver::getInstance();
202+
$this->setMockResolverProperties($resolver, null, null);
203+
$resolver->getModulesPath();
204+
$mockResolver->verifyNeverInvoked("getAdminToken");
205+
206+
// verifyNeverInvoked does not add to assertion count
207+
$this->addToAssertionCount(1);
208+
}
209+
210+
/**
211+
* Verify the getAdminToken method returns throws an exception if ENV is not fully loaded.
212+
*/
213+
public function testGetAdminTokenWithMissingEnv()
214+
{
215+
// Set --force to true
216+
$this->mockForceGenerate(false);
217+
218+
// Unset env
219+
unset($_ENV['MAGENTO_ADMIN_USERNAME']);
220+
221+
// Mock ModuleResolver and applyCustomModuleMethods()
222+
$mockResolver = $this->setMockResolverClass();
223+
$resolver = ModuleResolver::getInstance();
224+
225+
// Expect exception
226+
$this->expectException(TestFrameworkException::class);
227+
$resolver->getModulesPath();
228+
}
229+
230+
/**
231+
* Verify the getAdminToken method returns throws an exception if Token was bad.
232+
*/
233+
public function testGetAdminTokenWithBadResponse()
234+
{
235+
// Set --force to true
236+
$this->mockForceGenerate(false);
237+
238+
// Mock ModuleResolver and applyCustomModuleMethods()
239+
$mockResolver = $this->setMockResolverClass();
240+
$resolver = ModuleResolver::getInstance();
241+
242+
// Expect exception
243+
$this->expectException(TestFrameworkException::class);
244+
$resolver->getModulesPath();
178245
}
179246

180247
/**
@@ -205,7 +272,7 @@ private function setMockResolverClass(
205272
if (isset($mockToken)) {
206273
$mockMethods['getAdminToken'] = $mockToken;
207274
}
208-
if (isset($mockModules)) {
275+
if (isset($mockGetModules)) {
209276
$mockMethods['getEnabledModules'] = $mockGetModules;
210277
}
211278
if (isset($mockCustomMethods)) {
@@ -220,7 +287,7 @@ private function setMockResolverClass(
220287
if (isset($mockCustomModules)) {
221288
$mockMethods['getCustomModulePaths'] = $mockCustomModules;
222289
}
223-
$mockMethods['printMagentoVersionInfo'] = null;
290+
// $mockMethods['printMagentoVersionInfo'] = null;
224291

225292
$mockResolver = AspectMock::double(
226293
ModuleResolver::class,
@@ -260,12 +327,36 @@ private function setMockResolverProperties($instance, $mockPaths = null, $mockMo
260327
$property->setValue($instance, $mockBlacklist);
261328
}
262329

330+
/**
331+
* Mocks MftfApplicationConfig->forceGenerateEnabled()
332+
* @param $forceGenerate
333+
* @throws \Exception
334+
* @return void
335+
*/
336+
private function mockForceGenerate($forceGenerate)
337+
{
338+
$mockConfig = AspectMock::double(
339+
MftfApplicationConfig::class,
340+
['forceGenerateEnabled' => $forceGenerate]
341+
);
342+
$instance = AspectMock::double(
343+
ObjectManager::class,
344+
['create' => $mockConfig->make(), 'get' => null]
345+
)->make();
346+
AspectMock::double(ObjectManagerFactory::class, ['getObjectManager' => $instance]);
347+
}
348+
263349
/**
264350
* After method functionality
265351
* @return void
266352
*/
267353
protected function tearDown()
268354
{
355+
// re set env
356+
if (!isset($_ENV['MAGENTO_ADMIN_USERNAME'])) {
357+
$_ENV['MAGENTO_ADMIN_USERNAME'] = "admin";
358+
}
359+
269360
AspectMock::clean();
270361
}
271362
}

0 commit comments

Comments
 (0)