diff --git a/dev/tests/static/framework/Magento/TestFramework/Utility/File.php b/dev/tests/static/framework/Magento/TestFramework/Utility/File.php index a46b293f625a0daf78ef4b5b5ab76e82674efbd0..7a8e02e5143a0808867a4b9c1d1d01b2da7b34f9 100644 --- a/dev/tests/static/framework/Magento/TestFramework/Utility/File.php +++ b/dev/tests/static/framework/Magento/TestFramework/Utility/File.php @@ -13,19 +13,6 @@ use Magento\TestFramework\Utility\File\RegexIteratorFactory; */ class File { - /**@#+ - * File types offset flags - */ - const INCLUDE_APP_CODE = Files::INCLUDE_APP_CODE; - const INCLUDE_PUB_CODE = Files::INCLUDE_PUB_CODE; - const INCLUDE_LIBS = Files::INCLUDE_LIBS; - const INCLUDE_TEMPLATES = Files::INCLUDE_TEMPLATES; - const INCLUDE_TESTS = Files::INCLUDE_TESTS; - const INCLUDE_SETUP = 128; - const INCLUDE_NON_CLASSES = Files::INCLUDE_NON_CLASSES; - const AS_DATA_SET = Files::AS_DATA_SET; - /**#@-*/ - /** * @var RegexIteratorFactory */ @@ -53,29 +40,23 @@ class File /** * Get list of PHP files * - * @param int $flags * @return array * @throws \Exception */ - public function getPhpFiles( - $flags = self::INCLUDE_APP_CODE - | self::INCLUDE_PUB_CODE - | self::INCLUDE_LIBS - | self::INCLUDE_TEMPLATES - | self::INCLUDE_TESTS - | self::INCLUDE_SETUP - | self::INCLUDE_NON_CLASSES - | self::AS_DATA_SET - ) { + public function getPhpFiles() + { $files = array_merge( - $this->fileUtilities->getPhpFiles((2147483647 - self::AS_DATA_SET) & $flags), - $this->getSetupPhpFiles($flags) + $this->fileUtilities->getPhpFiles( + Files::INCLUDE_APP_CODE + | Files::INCLUDE_PUB_CODE + | Files::INCLUDE_LIBS + | Files::INCLUDE_TEMPLATES + | Files::INCLUDE_TESTS + | Files::INCLUDE_NON_CLASSES + ), + $this->getSetupPhpFiles() ); - - if ($flags & self::AS_DATA_SET) { - return Files::composeDataSets($files); - } - return $files; + return Files::composeDataSets($files); } /** @@ -84,17 +65,15 @@ class File * @param int $flags * @return array */ - private function getSetupPhpFiles($flags) + private function getSetupPhpFiles() { $files = []; - if ($flags & self::INCLUDE_SETUP) { - $regexIterator = $this->regexIteratorFactory->create( - BP . '/setup', - '/.*php^/' - ); - foreach ($regexIterator as $file) { - $files = array_merge($files, [$file]); - } + $regexIterator = $this->regexIteratorFactory->create( + BP . '/setup', + '/.*php^/' + ); + foreach ($regexIterator as $file) { + $files = array_merge($files, [$file]); } return $files; } diff --git a/dev/tests/static/framework/Magento/TestFramework/Utility/FunctionDetector.php b/dev/tests/static/framework/Magento/TestFramework/Utility/FunctionDetector.php index aa48ca3344bb00555f0cd1241398f8103480e17f..17310404e372097169f7cc36dcd8bb125349565d 100644 --- a/dev/tests/static/framework/Magento/TestFramework/Utility/FunctionDetector.php +++ b/dev/tests/static/framework/Magento/TestFramework/Utility/FunctionDetector.php @@ -6,7 +6,7 @@ namespace Magento\TestFramework\Utility; /** - * A helper detects functions + * Check if one or more functions are used in the file */ class FunctionDetector { @@ -27,16 +27,16 @@ class FunctionDetector * ], * ] * - * @param string $fileFullPath + * @param string $filePath * @param string[] $functions * @return array */ - public function detectFunctions($fileFullPath, $functions) + public function detect($filePath, $functions) { $result = []; $regexp = $this->composeRegexp($functions); if ($regexp) { - $file = file($fileFullPath); + $file = file($filePath); array_unshift($file, ''); $lines = preg_grep( $regexp, diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FileTest.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FileTest.php index e802228c282f0a7f6af45ee181a5938a9b2aec7b..be8b246a9330495fd5b859a4feb2552772492e21 100644 --- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FileTest.php +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FileTest.php @@ -46,54 +46,20 @@ class FileTest extends \PHPUnit_Framework_TestCase ); } - public function testGetPhpFilesWithoutSetup() + public function testGetPhpFiles() { $appFiles = [ 'file1', 'file2' ]; + $setupFiles = [ + 'file3' + ]; $expected = [ 'file1' => ['file1'], - 'file2' => ['file2'] + 'file2' => ['file2'], + 'file3' => ['file3'] ]; - $this->regexIteratorFactoryMock->expects($this->never()) - ->method('create'); - $this->fileUtilitiesMock->expects($this->once()) - ->method('getPhpFiles') - ->with( - File::INCLUDE_APP_CODE - | File::INCLUDE_PUB_CODE - | File::INCLUDE_LIBS - | File::INCLUDE_TEMPLATES - | File::INCLUDE_TESTS - | File::INCLUDE_NON_CLASSES - ) - ->willReturn($appFiles); - $actual = $this->file->getPhpFiles( - File::INCLUDE_APP_CODE - | File::INCLUDE_PUB_CODE - | File::INCLUDE_LIBS - | File::INCLUDE_TEMPLATES - | File::INCLUDE_TESTS - | File::INCLUDE_NON_CLASSES - | File::AS_DATA_SET - ); - $this->assertEquals($expected, $actual); - } - - /** - * @param array $appFiles - * @param array$setupFiles - * @param int $flags - * @param array $expected - * @dataProvider getPhpFilesWithSetupDataProvider - */ - public function testGetPhpFilesWithSetup( - $appFiles, - $setupFiles, - $flags, - $expected - ) { $iteratorMock = $this->getMock(\IteratorAggregate::class, [], [], '', false); $iteratorMock->expects($this->any()) ->method('getIterator') @@ -104,61 +70,14 @@ class FileTest extends \PHPUnit_Framework_TestCase $this->fileUtilitiesMock->expects($this->once()) ->method('getPhpFiles') ->with( - File::INCLUDE_APP_CODE - | File::INCLUDE_PUB_CODE - | File::INCLUDE_LIBS - | File::INCLUDE_TEMPLATES - | File::INCLUDE_TESTS - | File::INCLUDE_SETUP - | File::INCLUDE_NON_CLASSES + Files::INCLUDE_APP_CODE + | Files::INCLUDE_PUB_CODE + | Files::INCLUDE_LIBS + | Files::INCLUDE_TEMPLATES + | Files::INCLUDE_TESTS + | Files::INCLUDE_NON_CLASSES ) ->willReturn($appFiles); - $this->assertEquals($expected, $this->file->getPhpFiles($flags)); - } - - /** - * @return array - */ - public function getPhpFilesWithSetupDataProvider() - { - $flags = File::INCLUDE_APP_CODE - | File::INCLUDE_PUB_CODE - | File::INCLUDE_LIBS - | File::INCLUDE_TEMPLATES - | File::INCLUDE_TESTS - | File::INCLUDE_SETUP - | File::INCLUDE_NON_CLASSES; - return [ - [ - [ - 'file1', - 'file2' - ], - [ - 'file3' - ], - $flags | File::AS_DATA_SET, - [ - 'file1' => ['file1'], - 'file2' => ['file2'], - 'file3' => ['file3'] - ] - ], - [ - [ - 'file1', - 'file2' - ], - [ - 'file3' - ], - $flags, - [ - 'file1', - 'file2', - 'file3' - ] - ] - ]; + $this->assertEquals($expected, $this->file->getPhpFiles()); } } diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FunctionDetectorTest.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FunctionDetectorTest.php index e2dc7cdd4fae97af39a30f626c5ed3687086a1c4..a356aaa3cc83b48e4bf310b31d2556ec4c63bc12 100644 --- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FunctionDetectorTest.php +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FunctionDetectorTest.php @@ -11,12 +11,12 @@ class FunctionDetectorTest extends \PHPUnit_Framework_TestCase { $fixturePath = __DIR__ . '/_files/test.txt'; $expectedResults = [ - 24 => ['strtoupper', 'md5'], - 36 => ['security'], - 37 => ['security'], + 1 => ['strtoupper', 'strtolower'], + 3 => ['foo'], + 4 => ['foo'], ]; $functionDetector = new FunctionDetector(); - $lines = $functionDetector->detectFunctions($fixturePath, ['security', 'md5', 'test', 'strtoupper']); + $lines = $functionDetector->detect($fixturePath, ['foo', 'strtoupper', 'test', 'strtolower']); $this->assertEquals($expectedResults, $lines); } } diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/_files/test.txt b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/_files/test.txt index a7f1bced711892131125585d8f6a5ea31d5157a1..c2feb8284b2373bc94f9c16f7b5383fbc60f711a 100644 --- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/_files/test.txt +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/_files/test.txt @@ -1,46 +1,9 @@ -<?php -/** - * Copyright © 2016 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Authorizenet\Model\Security; - -/** - * security - */ -class Test extends AuthorizenetResponse -{ - /** - * Generates an Md5 hash to compare against AuthNet's. - * - * @param string $merchantMd5 - * @param string $merchantApiLogin - * @param string $amount - * @param string $transactionId - * @return string - */ - public function checkSecurity($merchantMd5, $merchantApiLogin, $amount, $transactionId) - { - return strtoupper(md5($merchantMd5 . $merchantApiLogin . $transactionId . $amount)); - } - - /** - * Return if is valid order id. - * - * @param string $merchantMd5 - * @param string $merchantApiLogin - * @return bool - */ - public function security($merchantMd5, $merchantApiLogin) - { - $hash = $this->generateHash(security($merchantMd5), $merchantApiLogin, $this->getXAmount()); - security( - 'something' - ); - return Security::compareStrings($hash, $this->getData('x_MD5_Hash')); - - $this->security('check'); - Security::security(); - return $this->getXResponseCode() == \Magento\Authorizenet\Model\Security::RESPONSE_CODE_APPROVED; - } -} +strtoupper(strtolower($foo . $bar)) +function foo($merchantMd5, $merchantApiLogin) +$this->generateHash(foo($bar), $foo) +foo( + 'bar' +) +Foo::bar($foo, $this->getData('bar')) +$this->foo('bar') +Foo::foo() diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/UnsecureFunctionsUsageTest.php b/dev/tests/static/testsuite/Magento/Test/Legacy/UnsecureFunctionsUsageTest.php index 23d216c5fbcf6a49f2560d61486db35e0fce513c..44eb7fa78d8ac7099bfbfb6c14eae050c5e578e1 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/UnsecureFunctionsUsageTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/UnsecureFunctionsUsageTest.php @@ -97,7 +97,7 @@ class UnsecureFunctionsUsageTest extends \PHPUnit_Framework_TestCase $invoker( function ($fileFullPath) use ($functionDetector) { $functions = $this->getFunctions($fileFullPath); - $lines = $functionDetector->detectFunctions($fileFullPath, array_keys($functions)); + $lines = $functionDetector->detect($fileFullPath, array_keys($functions)); $message = ''; if (!empty($lines)) {