|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Tests\unit\Magento\FunctionalTestingFramework\Console; |
| 7 | + |
| 8 | +use AspectMock\Test as AspectMock; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | +use Magento\FunctionalTestingFramework\Console\BaseGenerateCommand; |
| 11 | +use Magento\FunctionalTestingFramework\Suite\Objects\SuiteObject; |
| 12 | +use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler; |
| 13 | +use Magento\FunctionalTestingFramework\Test\Objects\TestObject; |
| 14 | +use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler; |
| 15 | +class BaseGenerateCommandTest extends TestCase |
| 16 | +{ |
| 17 | + public function tearDown() |
| 18 | + { |
| 19 | + AspectMock::clean(); |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * One test in one suite |
| 24 | + */ |
| 25 | + public function testSimpleTestConfig() |
| 26 | + { |
| 27 | + $testOne = new TestObject('Test1', [], [], []); |
| 28 | + $suiteOne = new SuiteObject('Suite1', ['Test1' => $testOne], [], []); |
| 29 | + |
| 30 | + $testArray = ['Test1' => $testOne]; |
| 31 | + $suiteArray = ['Suite1' => $suiteOne]; |
| 32 | + |
| 33 | + $this->mockHandlers($testArray, $suiteArray); |
| 34 | + |
| 35 | + $actual = json_decode($this->callConfig(['Test1']), true); |
| 36 | + $expected = ['tests' => null, 'suites' => ['Suite1' => ['Test1']]]; |
| 37 | + $this->assertEquals($expected, $actual); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Mock handlers to skip parsing |
| 42 | + * @param array $testArray |
| 43 | + * @param array $suiteArray |
| 44 | + * @throws \Exception |
| 45 | + */ |
| 46 | + public function mockHandlers($testArray, $suiteArray) |
| 47 | + { |
| 48 | + AspectMock::double(TestObjectHandler::class,['initTestData' => ''])->make(); |
| 49 | + $handler = TestObjectHandler::getInstance(); |
| 50 | + $property = new \ReflectionProperty(TestObjectHandler::class, 'tests'); |
| 51 | + $property->setAccessible(true); |
| 52 | + $property->setValue($handler, $testArray); |
| 53 | + |
| 54 | + AspectMock::double(SuiteObjectHandler::class, ['initSuiteData' => ''])->make(); |
| 55 | + $handler = SuiteObjectHandler::getInstance(); |
| 56 | + $property = new \ReflectionProperty(SuiteObjectHandler::class, 'suiteObjects'); |
| 57 | + $property->setAccessible(true); |
| 58 | + $property->setValue($handler, $suiteArray); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Changes visibility and runs getTestAndSuiteConfiguration |
| 63 | + * @param array $testArray |
| 64 | + * @return string |
| 65 | + */ |
| 66 | + public function callConfig($testArray) |
| 67 | + { |
| 68 | + $command = new BaseGenerateCommand(); |
| 69 | + $class = new \ReflectionClass($command); |
| 70 | + $method = $class->getMethod('getTestAndSuiteConfiguration'); |
| 71 | + $method->setAccessible(true); |
| 72 | + return $method->invokeArgs($command, [$testArray]); |
| 73 | + } |
| 74 | +} |
0 commit comments