diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2015-06-15 15:24:45 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2015-07-17 12:34:56 +0200 |
commit | d2fc1b230235e1aa9fa5d956e9a7edbbeef72dfb (patch) | |
tree | 853e18e8fc0c2856268d864735d3bb9de2a7af50 /tests | |
parent | 4e95031ec4e74bb99dc2dc819ddb77893564e01c (diff) | |
download | nextcloud-server-d2fc1b230235e1aa9fa5d956e9a7edbbeef72dfb.tar.gz nextcloud-server-d2fc1b230235e1aa9fa5d956e9a7edbbeef72dfb.zip |
Correctly handle use statements
Diffstat (limited to 'tests')
-rw-r--r-- | tests/data/app/code-checker/test-deprecated-use-alias.php | 9 | ||||
-rw-r--r-- | tests/data/app/code-checker/test-deprecated-use-sub-alias.php | 9 | ||||
-rw-r--r-- | tests/data/app/code-checker/test-deprecated-use-sub.php | 9 | ||||
-rw-r--r-- | tests/data/app/code-checker/test-deprecated-use.php | 9 | ||||
-rw-r--r-- | tests/data/app/code-checker/test-use.php | 12 | ||||
-rw-r--r-- | tests/lib/app/codechecker.php | 9 | ||||
-rw-r--r-- | tests/lib/app/deprecationcodechecker.php | 13 |
7 files changed, 62 insertions, 8 deletions
diff --git a/tests/data/app/code-checker/test-deprecated-use-alias.php b/tests/data/app/code-checker/test-deprecated-use-alias.php new file mode 100644 index 00000000000..a92187fa880 --- /dev/null +++ b/tests/data/app/code-checker/test-deprecated-use-alias.php @@ -0,0 +1,9 @@ +<?php + +use OCP\AppFramework\IApi as OAFIA; + +/** + * Class BadClass - creating an instance of a blacklisted class is not allowed + */ +class BadClass implements OAFIA { +} diff --git a/tests/data/app/code-checker/test-deprecated-use-sub-alias.php b/tests/data/app/code-checker/test-deprecated-use-sub-alias.php new file mode 100644 index 00000000000..9da4b75d216 --- /dev/null +++ b/tests/data/app/code-checker/test-deprecated-use-sub-alias.php @@ -0,0 +1,9 @@ +<?php + +use OCP\AppFramework as OAF; + +/** + * Class BadClass - creating an instance of a blacklisted class is not allowed + */ +class BadClass implements OAF\IApi { +} diff --git a/tests/data/app/code-checker/test-deprecated-use-sub.php b/tests/data/app/code-checker/test-deprecated-use-sub.php new file mode 100644 index 00000000000..a53e9a7229e --- /dev/null +++ b/tests/data/app/code-checker/test-deprecated-use-sub.php @@ -0,0 +1,9 @@ +<?php + +use OCP\AppFramework; + +/** + * Class BadClass - creating an instance of a blacklisted class is not allowed + */ +class BadClass implements AppFramework\IApi { +} diff --git a/tests/data/app/code-checker/test-deprecated-use.php b/tests/data/app/code-checker/test-deprecated-use.php new file mode 100644 index 00000000000..ebf2c90bc5a --- /dev/null +++ b/tests/data/app/code-checker/test-deprecated-use.php @@ -0,0 +1,9 @@ +<?php + +use OCP\AppFramework\IApi; + +/** + * Class BadClass - creating an instance of a blacklisted class is not allowed + */ +class BadClass implements IApi { +} diff --git a/tests/data/app/code-checker/test-use.php b/tests/data/app/code-checker/test-use.php new file mode 100644 index 00000000000..9c4824f9767 --- /dev/null +++ b/tests/data/app/code-checker/test-use.php @@ -0,0 +1,12 @@ +<?php + +use OC_AppConfig as UseConfig; + +/** + * Class BadClass - creating an instance of a blacklisted class is not allowed + */ +class BadClass { + public function foo() { + $bar = new UseConfig(); + } +} diff --git a/tests/lib/app/codechecker.php b/tests/lib/app/codechecker.php index 36c1251b8c5..435aedfe3ad 100644 --- a/tests/lib/app/codechecker.php +++ b/tests/lib/app/codechecker.php @@ -15,9 +15,9 @@ class CodeChecker extends TestCase { /** * @dataProvider providesFilesToCheck - * @param $expectedErrorToken - * @param $expectedErrorCode - * @param $fileToVerify + * @param string $expectedErrorToken + * @param int $expectedErrorCode + * @param string $fileToVerify */ public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) { $checker = new OC\App\CodeChecker(); @@ -35,12 +35,13 @@ class CodeChecker extends TestCase { ['OC_App', 1002, 'test-static-call.php'], ['OC_API', 1003, 'test-const.php'], ['OC_AppConfig', 1004, 'test-new.php'], + ['OC_AppConfig', 1006, 'test-use.php'], ]; } /** * @dataProvider validFilesData - * @param $fileToVerify + * @param string $fileToVerify */ public function testPassValidUsage($fileToVerify) { $checker = new OC\App\CodeChecker(); diff --git a/tests/lib/app/deprecationcodechecker.php b/tests/lib/app/deprecationcodechecker.php index 3f3baa7c314..57d9ca85a7a 100644 --- a/tests/lib/app/deprecationcodechecker.php +++ b/tests/lib/app/deprecationcodechecker.php @@ -15,9 +15,9 @@ class DeprecationCodeChecker extends TestCase { /** * @dataProvider providesFilesToCheck - * @param $expectedErrorToken - * @param $expectedErrorCode - * @param $fileToVerify + * @param string $expectedErrorToken + * @param int $expectedErrorCode + * @param string $fileToVerify */ public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) { $checker = new \OC\App\DeprecationCodeChecker(); @@ -32,12 +32,16 @@ class DeprecationCodeChecker extends TestCase { return [ ['==', 1005, 'test-equal.php'], ['!=', 1005, 'test-not-equal.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 validFilesData - * @param $fileToVerify + * @param string $fileToVerify */ public function testPassValidUsage($fileToVerify) { $checker = new \OC\App\DeprecationCodeChecker(); @@ -53,6 +57,7 @@ class DeprecationCodeChecker extends TestCase { ['test-static-call.php'], ['test-const.php'], ['test-new.php'], + ['test-use.php'], ['test-identical-operator.php'], ]; } |