|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace tests\unit\Magento\FunctionalTestFramework\Test\Util; |
| 7 | + |
| 8 | +use AspectMock\Test as AspectMock; |
| 9 | +use Magento\FunctionalTestingFramework\Test\Util\ActionGroupAnnotationExtractor; |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | +use tests\unit\Util\TestLoggingUtil; |
| 12 | + |
| 13 | +class ActionGroupAnnotationExtractorTest extends TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * Before test functionality |
| 17 | + * @return void |
| 18 | + */ |
| 19 | + public function setUp() |
| 20 | + { |
| 21 | + TestLoggingUtil::getInstance()->setMockLoggingUtil(); |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * Annotation extractor takes in raw array and condenses it to expected format |
| 26 | + * |
| 27 | + * @throws \Exception |
| 28 | + */ |
| 29 | + public function testActionGroupExtractAnnotations() |
| 30 | + { |
| 31 | + // Test Data |
| 32 | + $actionGroupAnnotations = [ |
| 33 | + "nodeName" => "annotations", |
| 34 | + "description" => [ |
| 35 | + "nodeName" => "description", |
| 36 | + "value" => "someDescription" |
| 37 | + ], |
| 38 | + "page" => [ |
| 39 | + "nodeName" => "page", |
| 40 | + "value" => "somePage" |
| 41 | + ] |
| 42 | + ]; |
| 43 | + // Perform Test |
| 44 | + $extractor = new ActionGroupAnnotationExtractor(); |
| 45 | + $returnedAnnotations = $extractor->extractAnnotations($actionGroupAnnotations, "fileName"); |
| 46 | + |
| 47 | + // Asserts |
| 48 | + |
| 49 | + $this->assertEquals("somePage", $returnedAnnotations['page']); |
| 50 | + $this->assertEquals("someDescription", $returnedAnnotations['description']); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Annotation extractor should throw warning when required annotations are missing |
| 55 | + * |
| 56 | + * @throws \Exception |
| 57 | + */ |
| 58 | + public function testActionGroupMissingAnnotations() |
| 59 | + { |
| 60 | + // Action Group Data, missing page and description |
| 61 | + $testAnnotations = []; |
| 62 | + // Perform Test |
| 63 | + $extractor = new ActionGroupAnnotationExtractor(); |
| 64 | + AspectMock::double($extractor, ['isCommandDefined' => true]); |
| 65 | + $extractor->extractAnnotations($testAnnotations, "fileName"); |
| 66 | + |
| 67 | + // Asserts |
| 68 | + TestLoggingUtil::getInstance()->validateMockLogStatement( |
| 69 | + 'warning', |
| 70 | + 'DEPRECATION: Action Group File fileName is missing required annotations.', |
| 71 | + [ |
| 72 | + 'actionGroup' => 'fileName', |
| 73 | + 'missingAnnotations' => "description, page" |
| 74 | + ] |
| 75 | + ); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Annotation extractor should not throw warning when required |
| 80 | + * annotations are missing if command is not generate:docs |
| 81 | + * |
| 82 | + * @throws \Exception |
| 83 | + */ |
| 84 | + public function testActionGroupMissingAnnotationsNoWarning() |
| 85 | + { |
| 86 | + // Action Group Data, missing page and description |
| 87 | + $testAnnotations = []; |
| 88 | + // Perform Test |
| 89 | + $extractor = new ActionGroupAnnotationExtractor(); |
| 90 | + $extractor->extractAnnotations($testAnnotations, "fileName"); |
| 91 | + |
| 92 | + // Asserts |
| 93 | + TestLoggingUtil::getInstance()->validateMockLogEmpty(); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * After class functionality |
| 98 | + * @return void |
| 99 | + */ |
| 100 | + public static function tearDownAfterClass() |
| 101 | + { |
| 102 | + TestLoggingUtil::getInstance()->clearMockLoggingUtil(); |
| 103 | + } |
| 104 | +} |
0 commit comments