diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2015-06-15 18:36:04 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2015-07-17 12:34:56 +0200 |
commit | eb1c4379415c60dbb873b549683978af79d1027d (patch) | |
tree | 41ebe1bb3a9c1a9b8e4849e60079848bf43ccfea /tests | |
parent | 2783a780708e4e5c04b6935840416d219bc4d852 (diff) | |
download | nextcloud-server-eb1c4379415c60dbb873b549683978af79d1027d.tar.gz nextcloud-server-eb1c4379415c60dbb873b549683978af79d1027d.zip |
Check for methods as good as possible
Diffstat (limited to 'tests')
7 files changed, 52 insertions, 56 deletions
diff --git a/tests/data/app/code-checker/test-deprecated-function-alias.php b/tests/data/app/code-checker/test-deprecated-function-alias.php index 0c958cc635c..28ed5051191 100644 --- a/tests/data/app/code-checker/test-deprecated-function-alias.php +++ b/tests/data/app/code-checker/test-deprecated-function-alias.php @@ -3,3 +3,4 @@ use OCP\NamespaceName\ClassName as Alias; Alias::functionName(); +Alias::methodName(); diff --git a/tests/data/app/code-checker/test-deprecated-function-sub-alias.php b/tests/data/app/code-checker/test-deprecated-function-sub-alias.php index f728eaf9fd0..73dd5814531 100644 --- a/tests/data/app/code-checker/test-deprecated-function-sub-alias.php +++ b/tests/data/app/code-checker/test-deprecated-function-sub-alias.php @@ -3,3 +3,4 @@ use OCP\NamespaceName as SubAlias; SubAlias\ClassName::functionName(); +SubAlias\ClassName::methodName(); diff --git a/tests/data/app/code-checker/test-deprecated-function-sub.php b/tests/data/app/code-checker/test-deprecated-function-sub.php index f7e15903d5d..c08d3bad8c0 100644 --- a/tests/data/app/code-checker/test-deprecated-function-sub.php +++ b/tests/data/app/code-checker/test-deprecated-function-sub.php @@ -3,3 +3,4 @@ use OCP\NamespaceName; NamespaceName\ClassName::functionName(); +NamespaceName\ClassName::methodName(); diff --git a/tests/data/app/code-checker/test-deprecated-function.php b/tests/data/app/code-checker/test-deprecated-function.php index 0016076e377..12a144a7118 100644 --- a/tests/data/app/code-checker/test-deprecated-function.php +++ b/tests/data/app/code-checker/test-deprecated-function.php @@ -1,3 +1,4 @@ <?php \OCP\NamespaceName\ClassName::functionName(); +\OCP\NamespaceName\ClassName::methodName(); diff --git a/tests/data/app/code-checker/test-deprecated-method.php b/tests/data/app/code-checker/test-deprecated-method.php new file mode 100644 index 00000000000..ee2fdb642d4 --- /dev/null +++ b/tests/data/app/code-checker/test-deprecated-method.php @@ -0,0 +1,5 @@ +<?php + +$class = new \OCP\NamespaceName\ClassName(); +$class->methodName(); +$class::methodName(); diff --git a/tests/lib/app/codecheckvisitor.php b/tests/lib/app/codecheckvisitor.php index 3eac3beedc8..d836f1b3c84 100644 --- a/tests/lib/app/codecheckvisitor.php +++ b/tests/lib/app/codecheckvisitor.php @@ -15,73 +15,55 @@ class CodeCheckVisitor extends TestCase { public function providesFilesToCheck() { return [ - ['OCP\AppFramework\IApi', 1006, 'test-deprecated-use.php'], - ['OCP\AppFramework\IApi', 1006, 'test-deprecated-use-alias.php'], - ['AppFramework\IApi', 1001, 'test-deprecated-use-sub.php'], - ['OAF\IApi', 1001, 'test-deprecated-use-sub-alias.php'], - ]; - } + [[['OCP\AppFramework\IApi', 1006]], 'test-deprecated-use.php'], + [[['OCP\AppFramework\IApi', 1006]], 'test-deprecated-use-alias.php'], + [[['AppFramework\IApi', 1001]], 'test-deprecated-use-sub.php'], + [[['OAF\IApi', 1001]], 'test-deprecated-use-sub-alias.php'], - /** - * @dataProvider providesFilesToCheck - * @param string $expectedErrorToken - * @param int $expectedErrorCode - * @param string $fileToVerify - */ - public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) { - $checker = new \Test\App\Mock\CodeChecker(); - $errors = $checker->analyseFile(OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); + [[['OCP\NamespaceName\ClassName::CONSTANT_NAME', 1003]], 'test-deprecated-constant.php'], + [[['Alias::CONSTANT_NAME', 1003]], 'test-deprecated-constant-alias.php'], + [[['NamespaceName\ClassName::CONSTANT_NAME', 1003]], 'test-deprecated-constant-sub.php'], + [[['SubAlias\ClassName::CONSTANT_NAME', 1003]], 'test-deprecated-constant-sub-alias.php'], - $this->assertEquals(1, count($errors)); - $this->assertEquals($expectedErrorCode, $errors[0]['errorCode']); - $this->assertEquals($expectedErrorToken, $errors[0]['disallowedToken']); - } + [[ + ['OCP\NamespaceName\ClassName::functionName', 1002], + ['OCP\NamespaceName\ClassName::methodName', 1007], + ], 'test-deprecated-function.php'], + [[ + ['Alias::functionName', 1002], + ['Alias::methodName', 1007], + ], 'test-deprecated-function-alias.php'], + [[ + ['NamespaceName\ClassName::functionName', 1002], + ['NamespaceName\ClassName::methodName', 1007], + ], 'test-deprecated-function-sub.php'], + [[ + ['SubAlias\ClassName::functionName', 1002], + ['SubAlias\ClassName::methodName', 1007], + ], 'test-deprecated-function-sub-alias.php'], - public function providesConstantsToCheck() { - return [ - ['OCP\NamespaceName\ClassName::CONSTANT_NAME', 1003, 'test-deprecated-constant.php'], - ['Alias::CONSTANT_NAME', 1003, 'test-deprecated-constant-alias.php'], - ['NamespaceName\ClassName::CONSTANT_NAME', 1003, 'test-deprecated-constant-sub.php'], - ['SubAlias\ClassName::CONSTANT_NAME', 1003, 'test-deprecated-constant-sub-alias.php'], + // TODO Failing to resolve variables to classes +// [[['OCP\NamespaceName\ClassName::methodName', 1007]], 'test-deprecated-method.php'], +// [[['Alias::methodName', 1002]], 'test-deprecated-method-alias.php'], +// [[['NamespaceName\ClassName::methodName', 1002]], 'test-deprecated-method-sub.php'], +// [[['SubAlias\ClassName::methodName', 1002]], 'test-deprecated-method-sub-alias.php'], ]; } /** - * @dataProvider providesConstantsToCheck - * @param string $expectedErrorToken - * @param int $expectedErrorCode + * @dataProvider providesFilesToCheck + * @param array $expectedErrors * @param string $fileToVerify */ - public function testConstantsToCheck($expectedErrorToken, $expectedErrorCode, $fileToVerify) { + public function testMethodsToCheck($expectedErrors, $fileToVerify) { $checker = new \Test\App\Mock\CodeChecker(); $errors = $checker->analyseFile(OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); - $this->assertEquals(1, count($errors)); - $this->assertEquals($expectedErrorCode, $errors[0]['errorCode']); - $this->assertEquals($expectedErrorToken, $errors[0]['disallowedToken']); - } - - public function providesFunctionsToCheck() { - return [ - ['OCP\NamespaceName\ClassName::functionName', 1002, 'test-deprecated-function.php'], - ['Alias::functionName', 1002, 'test-deprecated-function-alias.php'], - ['NamespaceName\ClassName::functionName', 1002, 'test-deprecated-function-sub.php'], - ['SubAlias\ClassName::functionName', 1002, 'test-deprecated-function-sub-alias.php'], - ]; - } - - /** - * @dataProvider providesFunctionsToCheck - * @param string $expectedErrorToken - * @param int $expectedErrorCode - * @param string $fileToVerify - */ - public function testFunctionsToCheck($expectedErrorToken, $expectedErrorCode, $fileToVerify) { - $checker = new \Test\App\Mock\CodeChecker(); - $errors = $checker->analyseFile(OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); + $this->assertCount(sizeof($expectedErrors), $errors); - $this->assertEquals(1, count($errors)); - $this->assertEquals($expectedErrorCode, $errors[0]['errorCode']); - $this->assertEquals($expectedErrorToken, $errors[0]['disallowedToken']); + foreach ($expectedErrors as $int => $expectedError) { + $this->assertEquals($expectedError[0], $errors[$int]['disallowedToken']); + $this->assertEquals($expectedError[1], $errors[$int]['errorCode']); + } } } diff --git a/tests/lib/app/mock/codechecker.php b/tests/lib/app/mock/codechecker.php index e67d060b1f4..b5a775cc43d 100644 --- a/tests/lib/app/mock/codechecker.php +++ b/tests/lib/app/mock/codechecker.php @@ -38,7 +38,12 @@ class CodeChecker extends \OC\App\CodeChecker { ]; protected $blackListedFunctions = [ - // Deprecated constants + // Deprecated functions 'OCP\NamespaceName\ClassName::functionName' => '8.0.0', ]; + + protected $blackListedMethods = [ + // Deprecated methods + 'OCP\NamespaceName\ClassName::methodName' => '8.0.0', + ]; } |