Skip to content

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
merged 6 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

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 change setUpBeforeClass() to just setUp().

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 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);
}
}
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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()
);
}
}
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"
}
}
Loading