Skip to content

Commit 1671bcd

Browse files
authored
Merge pull request #476 from magento/MQE-1750
MQE-1750: unit tests
2 parents 5ee8dda + 68c5576 commit 1671bcd

File tree

13 files changed

+1203
-83
lines changed

13 files changed

+1203
-83
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace tests\unit\Magento\FunctionalTestFramework\Test\Util;
8+
9+
use Magento\FunctionalTestingFramework\Composer\ComposerInstall;
10+
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
11+
12+
class ComposerInstallTest extends MagentoTestCase
13+
{
14+
/**
15+
* ComposerInstall instance to be tested
16+
*
17+
* @var ComposerInstall
18+
*/
19+
private $composer;
20+
21+
public function setUp()
22+
{
23+
$composerJson = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Composer' . DIRECTORY_SEPARATOR . '_files'
24+
. DIRECTORY_SEPARATOR . 'dir1' . DIRECTORY_SEPARATOR . 'dir2' . DIRECTORY_SEPARATOR . 'composer.json';
25+
26+
$this->composer = new ComposerInstall($composerJson);
27+
}
28+
29+
/**
30+
* Test isMftfTestPackage()
31+
*/
32+
public function testIsMftfTestPackage()
33+
{
34+
$this->assertTrue($this->composer->isMftfTestPackage('magento/module2-functional-test'));
35+
}
36+
37+
/**
38+
* Test isMagentoPackage()
39+
*/
40+
public function testIsMagentoPackage()
41+
{
42+
$this->assertTrue($this->composer->isMagentoPackage('magento/module-authorization'));
43+
}
44+
45+
/**
46+
* Test isInstalledPackageOfType()
47+
*/
48+
public function testIsInstalledPackageOfType()
49+
{
50+
$this->assertTrue($this->composer->isInstalledPackageOfType('composer/composer', 'library'));
51+
}
52+
53+
/**
54+
* Test getInstalledTestPackages()
55+
*/
56+
public function testGetInstalledTestPackages()
57+
{
58+
$output = $this->composer->getInstalledTestPackages();
59+
$this->assertCount(1, $output);
60+
$this->assertArrayHasKey('magento/module2-functional-test', $output);
61+
}
62+
}
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace tests\unit\Magento\FunctionalTestFramework\Test\Util;
8+
9+
use Magento\FunctionalTestingFramework\Composer\ComposerPackage;
10+
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
11+
use Composer\Package\RootPackage;
12+
13+
class ComposerPackageTest extends MagentoTestCase
14+
{
15+
/**
16+
* ComposerPackage instance to be tested
17+
*
18+
* @var ComposerPackage
19+
*/
20+
private $composer;
21+
22+
public function setUp()
23+
{
24+
$composerJson = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Composer' . DIRECTORY_SEPARATOR . '_files'
25+
. DIRECTORY_SEPARATOR . 'dir1' . DIRECTORY_SEPARATOR . 'dir2' . DIRECTORY_SEPARATOR . 'composer.json';
26+
27+
$this->composer = new ComposerPackage($composerJson);
28+
}
29+
30+
/**
31+
* Test getName()
32+
*/
33+
public function testGetName()
34+
{
35+
$expected = 'magento/module2-functional-test';
36+
$this->assertEquals($expected, $this->composer->getName());
37+
}
38+
39+
/**
40+
* Test getType()
41+
*/
42+
public function testGetType()
43+
{
44+
$expected = 'magento2-functional-test-module';
45+
$this->assertEquals($expected, $this->composer->getType());
46+
}
47+
48+
/**
49+
* Test getVersion()
50+
*/
51+
public function testGetVersion()
52+
{
53+
$expected = '1.0.0';
54+
$this->assertEquals($expected, $this->composer->getVersion());
55+
}
56+
57+
/**
58+
* Test getDescription()
59+
*/
60+
public function testGetDescription()
61+
{
62+
$expected = 'MFTF tests for magento';
63+
$this->assertEquals($expected, $this->composer->getDescription());
64+
}
65+
66+
/**
67+
* Test getRequires()
68+
*/
69+
public function testGetRequires()
70+
{
71+
$expected = 'magento/magento2-functional-testing-framework';
72+
$output = $this->composer->getRequires();
73+
$this->assertCount(1, $output);
74+
$this->assertArrayHasKey($expected, $output);
75+
}
76+
77+
/**
78+
* Test getDevRequires()
79+
*/
80+
public function testGetDevRequires()
81+
{
82+
$expected = ['phpunit/phpunit'];
83+
$this->assertEquals($expected, array_keys($this->composer->getDevRequires()));
84+
}
85+
86+
/**
87+
* Test getSuggests()
88+
*/
89+
public function testGetSuggests()
90+
{
91+
$expected = [
92+
'magento/module-one',
93+
'magento/module-module-x',
94+
'magento/module-two',
95+
'magento/module-module-y',
96+
'magento/module-module-z',
97+
'magento/module-three',
98+
'magento/module-four'
99+
];
100+
$this->assertEquals($expected, array_keys($this->composer->getSuggests()));
101+
}
102+
103+
/**
104+
* Test getSuggestedMagentoModules()
105+
*/
106+
public function testGetSuggestedMagentoModules()
107+
{
108+
$expected = [
109+
'Magento_ModuleX',
110+
'Magento_ModuleY',
111+
'Magento_ModuleZ'
112+
];
113+
$this->assertEquals($expected, $this->composer->getSuggestedMagentoModules());
114+
}
115+
116+
/**
117+
* Test isMftfTestPackage()
118+
*/
119+
public function testIsMftfTestPackage()
120+
{
121+
$this->assertTrue($this->composer->isMftfTestPackage());
122+
}
123+
124+
/**
125+
* Test getRequiresForPackage()
126+
*/
127+
public function testGetRequiresForPackage()
128+
{
129+
$expected = [
130+
'php',
131+
'ext-curl',
132+
'allure-framework/allure-codeception',
133+
'codeception/codeception',
134+
'consolidation/robo',
135+
'csharpru/vault-php',
136+
'csharpru/vault-php-guzzle6-transport',
137+
'flow/jsonpath',
138+
'fzaninotto/faker',
139+
'monolog/monolog',
140+
'mustache/mustache',
141+
'symfony/process',
142+
'vlucas/phpdotenv'
143+
];
144+
$this->assertEquals(
145+
$expected,
146+
array_keys($this->composer->getRequiresForPackage('magento/magento2-functional-testing-framework', '2.5.0'))
147+
);
148+
}
149+
150+
/**
151+
* Test isPackageRequiredInComposerJson()
152+
*/
153+
public function testIsPackageRequiredInComposerJson()
154+
{
155+
$this->assertTrue(
156+
$this->composer->isPackageRequiredInComposerJson('magento/magento2-functional-testing-framework')
157+
);
158+
}
159+
160+
/**
161+
* Test getRootPackage()
162+
*/
163+
public function testGetRootPackage()
164+
{
165+
$this->assertInstanceOf(
166+
RootPackage::class,
167+
$this->composer->getRootPackage()
168+
);
169+
}
170+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "magento/module2-functional-test",
3+
"type": "magento2-functional-test-module",
4+
"description": "MFTF tests for magento",
5+
"version": "1.0.0",
6+
"require": {
7+
"magento/magento2-functional-testing-framework": "^2.5.0"
8+
},
9+
"require-dev": {
10+
"phpunit/phpunit": "~6.5.0 || ~7.0.0"
11+
},
12+
"suggest": {
13+
"magento/module-one": "name: Magento_ModuleY, version: ~100.0.0",
14+
"magento/module-module-x": " type: magento2-module ,name: Magento_ModuleX, version: ~100.0.0",
15+
"magento/module-two": "*",
16+
"magento/module-module-y": "type: magento2-module, name:Magento_ModuleY,version:~100.0.0",
17+
"magento/module-module-z": " type:magento2-module, name: Magento_ModuleZ , version: ~100.0.0",
18+
"magento/module-three": "type: magento2-module, ~100.0.0",
19+
"magento/module-four": "some suggestions"
20+
}
21+
}

0 commit comments

Comments
 (0)