summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-06-15 17:20:38 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2015-07-17 12:34:56 +0200
commitf228a3dc28b579b3d11126544928edacd2e2d9c4 (patch)
treed11eebce3ef51c264bc896cf28cb14a132559d8f /tests
parent483c886291f23577417d820a8e65702ec0d1cc85 (diff)
downloadnextcloud-server-f228a3dc28b579b3d11126544928edacd2e2d9c4.tar.gz
nextcloud-server-f228a3dc28b579b3d11126544928edacd2e2d9c4.zip
Add support for deprecated constants
Diffstat (limited to 'tests')
-rw-r--r--tests/data/app/code-checker/test-deprecated-constant-alias.php12
-rw-r--r--tests/data/app/code-checker/test-deprecated-constant-sub-alias.php12
-rw-r--r--tests/data/app/code-checker/test-deprecated-constant-sub.php12
-rw-r--r--tests/data/app/code-checker/test-deprecated-constant.php10
-rw-r--r--tests/lib/app/codecheckvisitor.php63
-rw-r--r--tests/lib/app/mock/codechecker.php39
6 files changed, 148 insertions, 0 deletions
diff --git a/tests/data/app/code-checker/test-deprecated-constant-alias.php b/tests/data/app/code-checker/test-deprecated-constant-alias.php
new file mode 100644
index 00000000000..4f3d3e81316
--- /dev/null
+++ b/tests/data/app/code-checker/test-deprecated-constant-alias.php
@@ -0,0 +1,12 @@
+<?php
+
+use OCP\NamespaceName\ClassName as Constant;
+
+/**
+ * Class BadClass - creating an instance of a blacklisted class is not allowed
+ */
+class BadClass {
+ public function test() {
+ return Constant::CONSTANT_NAME;
+ }
+}
diff --git a/tests/data/app/code-checker/test-deprecated-constant-sub-alias.php b/tests/data/app/code-checker/test-deprecated-constant-sub-alias.php
new file mode 100644
index 00000000000..b7e7c7e6be9
--- /dev/null
+++ b/tests/data/app/code-checker/test-deprecated-constant-sub-alias.php
@@ -0,0 +1,12 @@
+<?php
+
+use OCP\NamespaceName as Constant;
+
+/**
+ * Class BadClass - creating an instance of a blacklisted class is not allowed
+ */
+class BadClass {
+ public function test() {
+ return Constant\ClassName::CONSTANT_NAME;
+ }
+}
diff --git a/tests/data/app/code-checker/test-deprecated-constant-sub.php b/tests/data/app/code-checker/test-deprecated-constant-sub.php
new file mode 100644
index 00000000000..0ef837c14c6
--- /dev/null
+++ b/tests/data/app/code-checker/test-deprecated-constant-sub.php
@@ -0,0 +1,12 @@
+<?php
+
+use OCP\NamespaceName;
+
+/**
+ * Class BadClass - creating an instance of a blacklisted class is not allowed
+ */
+class BadClass {
+ public function test() {
+ return NamespaceName\ClassName::CONSTANT_NAME;
+ }
+}
diff --git a/tests/data/app/code-checker/test-deprecated-constant.php b/tests/data/app/code-checker/test-deprecated-constant.php
new file mode 100644
index 00000000000..965d84500fd
--- /dev/null
+++ b/tests/data/app/code-checker/test-deprecated-constant.php
@@ -0,0 +1,10 @@
+<?php
+
+/**
+ * Class BadClass - creating an instance of a blacklisted class is not allowed
+ */
+class BadClass {
+ public function test() {
+ return \OCP\NamespaceName\ClassName::CONSTANT_NAME;
+ }
+}
diff --git a/tests/lib/app/codecheckvisitor.php b/tests/lib/app/codecheckvisitor.php
new file mode 100644
index 00000000000..4b663cf40b7
--- /dev/null
+++ b/tests/lib/app/codecheckvisitor.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ * Copyright (c) 2015 Joas Schilling <nickvergessen@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\App;
+
+use OC;
+use Test\TestCase;
+
+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'],
+ ];
+ }
+
+ /**
+ * @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");
+
+ $this->assertEquals(1, count($errors));
+ $this->assertEquals($expectedErrorCode, $errors[0]['errorCode']);
+ $this->assertEquals($expectedErrorToken, $errors[0]['disallowedToken']);
+ }
+
+ public function providesConstantsToCheck() {
+ return [
+ ['OCP\NamespaceName\ClassName::CONSTANT_NAME', 1003, 'test-deprecated-constant.php'],
+ ['Constant::CONSTANT_NAME', 1003, 'test-deprecated-constant-alias.php'],
+ ['NamespaceName\ClassName::CONSTANT_NAME', 1003, 'test-deprecated-constant-sub.php'],
+ ['Constant\ClassName::CONSTANT_NAME', 1003, 'test-deprecated-constant-sub-alias.php'],
+ ];
+ }
+
+ /**
+ * @dataProvider providesConstantsToCheck
+ * @param string $expectedErrorToken
+ * @param int $expectedErrorCode
+ * @param string $fileToVerify
+ */
+ public function testConstantsToCheck($expectedErrorToken, $expectedErrorCode, $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']);
+ }
+}
diff --git a/tests/lib/app/mock/codechecker.php b/tests/lib/app/mock/codechecker.php
new file mode 100644
index 00000000000..228fd881e44
--- /dev/null
+++ b/tests/lib/app/mock/codechecker.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * @author Joas Schilling <nickvergessen@owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace Test\App\Mock;
+
+class CodeChecker extends \OC\App\CodeChecker {
+ protected $checkEqualOperators = true;
+
+ /** @var string */
+ protected $blackListDescription = 'deprecated';
+
+ protected $blackListedClassNames = [
+ // Deprecated classes
+ 'OCP\AppFramework\IApi' => '8.0.0',
+ ];
+
+ protected $blackListedConstants = [
+ // Deprecated constants
+ 'OCP\NamespaceName\ClassName::CONSTANT_NAME' => '8.0.0',
+ ];
+}