|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Test\Legacy; |
| 8 | + |
| 9 | +/** |
| 10 | + * Temporary test that will be removed in scope of MAGETWO-28356. |
| 11 | + * Test verifies obsolete usages in modules that were refactored to work with ResultInterface. |
| 12 | + */ |
| 13 | +class ObsoleteResponseTest extends \PHPUnit_Framework_TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @var array |
| 17 | + */ |
| 18 | + protected $obsoleteMethods = []; |
| 19 | + |
| 20 | + protected function setUp() |
| 21 | + { |
| 22 | + $this->obsoleteMethods = include __DIR__ . '/_files/obsolete_response_methods.php'; |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * Test verify that obsolete methods do not appear in refactored folders |
| 27 | + */ |
| 28 | + public function testObsoleteResponseMethods() |
| 29 | + { |
| 30 | + $invoker = new \Magento\Framework\Test\Utility\AggregateInvoker($this); |
| 31 | + $invoker( |
| 32 | + function ($file) { |
| 33 | + $content = file_get_contents($file); |
| 34 | + foreach ($this->obsoleteMethods as $method) { |
| 35 | + $this->assertSame( |
| 36 | + 0, |
| 37 | + preg_match('/(?<=[a-z\d_:]|->|function\s)' . $method . '\s*\(/iS', $content), |
| 38 | + "File: $file\nContains obsolete method: $method . " |
| 39 | + ); |
| 40 | + } |
| 41 | + }, |
| 42 | + $this->modulesFilesDataProvider() |
| 43 | + ); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Return refactored files |
| 48 | + * |
| 49 | + * @return array |
| 50 | + */ |
| 51 | + public function modulesFilesDataProvider() |
| 52 | + { |
| 53 | + $result = []; |
| 54 | + $appPath = \Magento\Framework\Test\Utility\Files::init()->getPathToSource(); |
| 55 | + $refactoredModules = $this->getRefactoredModules('refactored_modules*'); |
| 56 | + foreach ($refactoredModules as $refactoredFolder) { |
| 57 | + $files = \Magento\Framework\Test\Utility\Files::init()->getFiles([$appPath . $refactoredFolder], '*.php'); |
| 58 | + $result = array_merge($result, $files); |
| 59 | + } |
| 60 | + |
| 61 | + return \Magento\Framework\Test\Utility\Files::composeDataSets($result); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * @param string $filePattern |
| 66 | + * @return array |
| 67 | + */ |
| 68 | + protected function getRefactoredModules($filePattern) |
| 69 | + { |
| 70 | + $result = []; |
| 71 | + foreach (glob(__DIR__ . '/_files/response_whitelist/' . $filePattern) as $file) { |
| 72 | + $fileData = include $file; |
| 73 | + $result = array_merge($result, $fileData); |
| 74 | + } |
| 75 | + return $result; |
| 76 | + } |
| 77 | +} |
0 commit comments