|
| 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 | +} |
0 commit comments