-
Notifications
You must be signed in to change notification settings - Fork 133
MQE-1750: unit tests #476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MQE-1750: unit tests #476
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9891e5d
MQE-1750: unit tests
jilu1 9f6cffc
Merge branch 'develop' into MQE-1750
jilu1 7c3bd33
MQE-1750: unit tests and some code refactor.
jilu1 c7d9900
MQE-1750: unit tests and some code refactor.
jilu1 5cfd7cd
MQE-1750: unit tests and some code refactor.
jilu1 68c5576
Merge branch 'develop' into MQE-1750
jilu1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
dev/tests/unit/Magento/FunctionalTestFramework/Composer/ComposerInstallTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace tests\unit\Magento\FunctionalTestFramework\Test\Util; | ||
|
||
use Magento\FunctionalTestingFramework\Composer\ComposerInstall; | ||
use Magento\FunctionalTestingFramework\Util\MagentoTestCase; | ||
|
||
class ComposerInstallTest extends MagentoTestCase | ||
{ | ||
/** | ||
* ComposerInstall instance to be tested | ||
* | ||
* @var ComposerInstall | ||
*/ | ||
private static $composer; | ||
|
||
public static function setUpBeforeClass() | ||
{ | ||
parent::setUpBeforeClass(); | ||
|
||
$composerJson = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Composer' . DIRECTORY_SEPARATOR . '_files' | ||
. DIRECTORY_SEPARATOR . 'dir1' . DIRECTORY_SEPARATOR . 'dir2' . DIRECTORY_SEPARATOR . 'composer.json'; | ||
|
||
self::$composer = new ComposerInstall($composerJson); | ||
} | ||
|
||
/** | ||
* Test isMftfTestPackage() | ||
*/ | ||
public function testIsMftfTestPackage() | ||
{ | ||
$this->assertTrue(self::$composer->isMftfTestPackage('magento/module2-functional-test')); | ||
} | ||
|
||
/** | ||
* Test isMagentoPackage() | ||
*/ | ||
public function testIsMagentoPackage() | ||
{ | ||
$this->assertTrue(self::$composer->isMagentoPackage('magento/module-authorization')); | ||
} | ||
|
||
/** | ||
* Test isInstalledPackageOfType() | ||
*/ | ||
public function testIsInstalledPackageOfType() | ||
{ | ||
$this->assertTrue( | ||
self::$composer->isInstalledPackageOfType('composer/composer', 'library') | ||
); | ||
} | ||
|
||
/** | ||
* Test getInstalledTestPackages() | ||
*/ | ||
public function testGetInstalledTestPackages() | ||
{ | ||
$output = self::$composer->getInstalledTestPackages(); | ||
$this->assertCount(1, $output); | ||
$this->assertArrayHasKey('magento/module2-functional-test', $output); | ||
} | ||
} |
172 changes: 172 additions & 0 deletions
172
dev/tests/unit/Magento/FunctionalTestFramework/Composer/ComposerPackageTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace tests\unit\Magento\FunctionalTestFramework\Test\Util; | ||
|
||
use Magento\FunctionalTestingFramework\Composer\ComposerPackage; | ||
use Magento\FunctionalTestingFramework\Util\MagentoTestCase; | ||
use Composer\Package\RootPackage; | ||
|
||
class ComposerPackageTest extends MagentoTestCase | ||
{ | ||
/** | ||
* ComposerPackage instance to be tested | ||
* | ||
* @var ComposerPackage | ||
*/ | ||
private static $composer; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
|
||
public static function setUpBeforeClass() | ||
{ | ||
parent::setUpBeforeClass(); | ||
|
||
$composerJson = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Composer' . DIRECTORY_SEPARATOR . '_files' | ||
. DIRECTORY_SEPARATOR . 'dir1' . DIRECTORY_SEPARATOR . 'dir2' . DIRECTORY_SEPARATOR . 'composer.json'; | ||
|
||
self::$composer = new ComposerPackage($composerJson); | ||
} | ||
|
||
/** | ||
* Test getName() | ||
*/ | ||
public function testGetName() | ||
{ | ||
$expected = 'magento/module2-functional-test'; | ||
$this->assertEquals($expected, self::$composer->getName()); | ||
} | ||
|
||
/** | ||
* Test getType() | ||
*/ | ||
public function testGetType() | ||
{ | ||
$expected = 'magento2-functional-test-module'; | ||
$this->assertEquals($expected, self::$composer->getType()); | ||
} | ||
|
||
/** | ||
* Test getVersion() | ||
*/ | ||
public function testGetVersion() | ||
{ | ||
$expected = '1.0.0'; | ||
$this->assertEquals($expected, self::$composer->getVersion()); | ||
} | ||
|
||
/** | ||
* Test getDescription() | ||
*/ | ||
public function testGetDescription() | ||
{ | ||
$expected = 'MFTF tests for magento'; | ||
$this->assertEquals($expected, self::$composer->getDescription()); | ||
} | ||
|
||
/** | ||
* Test getRequires() | ||
*/ | ||
public function testGetRequires() | ||
{ | ||
$expected = 'magento/magento2-functional-testing-framework'; | ||
$output = self::$composer->getRequires(); | ||
$this->assertCount(1, $output); | ||
$this->assertArrayHasKey($expected, $output); | ||
} | ||
|
||
/** | ||
* Test getDevRequires() | ||
*/ | ||
public function testGetDevRequires() | ||
{ | ||
$expected = ['phpunit/phpunit']; | ||
$this->assertEquals($expected, array_keys(self::$composer->getDevRequires())); | ||
} | ||
|
||
/** | ||
* Test getSuggests() | ||
*/ | ||
public function testGetSuggests() | ||
{ | ||
$expected = [ | ||
'magento/module-one', | ||
'magento/module-module-x', | ||
'magento/module-two', | ||
'magento/module-module-y', | ||
'magento/module-module-z', | ||
'magento/module-three', | ||
'magento/module-four' | ||
]; | ||
$this->assertEquals($expected, array_keys(self::$composer->getSuggests())); | ||
} | ||
|
||
/** | ||
* Test getSuggestedMagentoModules() | ||
*/ | ||
public function testGetSuggestedMagentoModules() | ||
{ | ||
$expected = [ | ||
'Magento_ModuleX', | ||
'Magento_ModuleY', | ||
'Magento_ModuleZ' | ||
]; | ||
$this->assertEquals($expected, self::$composer->getSuggestedMagentoModules()); | ||
} | ||
|
||
/** | ||
* Test isMftfTestPackage() | ||
*/ | ||
public function testIsMftfTestPackage() | ||
{ | ||
$this->assertTrue(self::$composer->isMftfTestPackage()); | ||
} | ||
|
||
/** | ||
* Test getRequiresForPackage() | ||
*/ | ||
public function testGetRequiresForPackage() | ||
{ | ||
$expected = [ | ||
'php', | ||
'ext-curl', | ||
'allure-framework/allure-codeception', | ||
'codeception/codeception', | ||
'consolidation/robo', | ||
'csharpru/vault-php', | ||
'csharpru/vault-php-guzzle6-transport', | ||
'flow/jsonpath', | ||
'fzaninotto/faker', | ||
'monolog/monolog', | ||
'mustache/mustache', | ||
'symfony/process', | ||
'vlucas/phpdotenv' | ||
]; | ||
$this->assertEquals( | ||
$expected, | ||
array_keys(self::$composer->getRequiresForPackage('magento/magento2-functional-testing-framework', '2.5.0')) | ||
); | ||
} | ||
|
||
/** | ||
* Test isPackageRequiredInComposerJson() | ||
*/ | ||
public function testIsPackageRequiredInComposerJson() | ||
{ | ||
$this->assertTrue( | ||
self::$composer->isPackageRequiredInComposerJson('magento/magento2-functional-testing-framework') | ||
); | ||
} | ||
|
||
/** | ||
* Test getRootPackage() | ||
*/ | ||
public function testGetRootPackage() | ||
{ | ||
$this->assertInstanceOf( | ||
RootPackage::class, | ||
self::$composer->getRootPackage() | ||
); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
dev/tests/unit/Magento/FunctionalTestFramework/Composer/_files/dir1/dir2/composer.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "magento/module2-functional-test", | ||
"type": "magento2-functional-test-module", | ||
"description": "MFTF tests for magento", | ||
"version": "1.0.0", | ||
"require": { | ||
"magento/magento2-functional-testing-framework": "^2.5.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "~6.5.0 || ~7.0.0" | ||
}, | ||
"suggest": { | ||
"magento/module-one": "name: Magento_ModuleY, version: ~100.0.0", | ||
"magento/module-module-x": " type: magento2-module ,name: Magento_ModuleX, version: ~100.0.0", | ||
"magento/module-two": "*", | ||
"magento/module-module-y": "type: magento2-module, name:Magento_ModuleY,version:~100.0.0", | ||
"magento/module-module-z": " type:magento2-module, name: Magento_ModuleZ , version: ~100.0.0", | ||
"magento/module-three": "type: magento2-module, ~100.0.0", | ||
"magento/module-four": "some suggestions" | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change this to just be
private $composer;
and changesetUpBeforeClass()
to justsetUp()
.Since this is initialized only once in the test, the object's state is subject to change due to test's manipulation, which set a bad pattern if we ever do any state tracking in that class in the future.
Also being the class under test, we should really initialize once per test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed