diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2021-02-11 11:32:01 +0100 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2021-02-11 11:46:02 +0100 |
commit | e618ea83b5a54f566e1cc1fbfdfcce07be752108 (patch) | |
tree | ccdd98ca8a2505576fa9813d78430acc69985d52 /tests | |
parent | d5dea10517bbceaf141f56b6dde0efb55fc6f4b5 (diff) | |
download | nextcloud-server-e618ea83b5a54f566e1cc1fbfdfcce07be752108.tar.gz nextcloud-server-e618ea83b5a54f566e1cc1fbfdfcce07be752108.zip |
Make the app code checker a NOOP
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/App/CodeChecker/CodeCheckerTest.php | 74 | ||||
-rw-r--r-- | tests/lib/App/CodeChecker/DeprecationCheckTest.php | 76 | ||||
-rw-r--r-- | tests/lib/App/CodeChecker/InfoCheckerTest.php | 76 | ||||
-rw-r--r-- | tests/lib/App/CodeChecker/Mock/TestList.php | 92 | ||||
-rw-r--r-- | tests/lib/App/CodeChecker/NodeVisitorTest.php | 77 | ||||
-rw-r--r-- | tests/lib/App/CodeChecker/StrongComparisonCheckTest.php | 76 |
6 files changed, 0 insertions, 471 deletions
diff --git a/tests/lib/App/CodeChecker/CodeCheckerTest.php b/tests/lib/App/CodeChecker/CodeCheckerTest.php deleted file mode 100644 index 7725d46a273..00000000000 --- a/tests/lib/App/CodeChecker/CodeCheckerTest.php +++ /dev/null @@ -1,74 +0,0 @@ -<?php -/** - * Copyright (c) 2015 Thomas Müller <deepdiver@owncloud.com> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace Test\App\CodeChecker; - -use OC\App\CodeChecker\CodeChecker; -use OC\App\CodeChecker\EmptyCheck; -use OC\App\CodeChecker\PrivateCheck; -use Test\TestCase; - -class CodeCheckerTest extends TestCase { - - /** - * @dataProvider providesFilesToCheck - * @param string $expectedErrorToken - * @param int $expectedErrorCode - * @param string $fileToVerify - */ - public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) { - if (PHP_MAJOR_VERSION > 7) { - $this->markTestSkipped('Only run on php7'); - } - - $checker = new CodeChecker( - new PrivateCheck(new EmptyCheck()), - false - ); - $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 providesFilesToCheck() { - return [ - ['OC_Hook', 1000, 'test-extends.php'], - ['oC_Avatar', 1001, 'test-implements.php'], - ['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 string $fileToVerify - */ - public function testPassValidUsage($fileToVerify) { - if (PHP_MAJOR_VERSION > 7) { - $this->markTestSkipped('Only run on php7'); - } - - $checker = new CodeChecker( - new PrivateCheck(new EmptyCheck()), - false - ); - $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); - - $this->assertEquals(0, count($errors)); - } - - public function validFilesData() { - return [ - ['test-identical-operator.php'], - ]; - } -} diff --git a/tests/lib/App/CodeChecker/DeprecationCheckTest.php b/tests/lib/App/CodeChecker/DeprecationCheckTest.php deleted file mode 100644 index ea8ed8f50d6..00000000000 --- a/tests/lib/App/CodeChecker/DeprecationCheckTest.php +++ /dev/null @@ -1,76 +0,0 @@ -<?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\CodeChecker; - -use OC\App\CodeChecker\CodeChecker; -use OC\App\CodeChecker\DeprecationCheck; -use OC\App\CodeChecker\EmptyCheck; -use Test\TestCase; - -class DeprecationCheckTest extends TestCase { - - /** - * @dataProvider providesFilesToCheck - * @param string $expectedErrorToken - * @param int $expectedErrorCode - * @param string $fileToVerify - */ - public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) { - if (PHP_MAJOR_VERSION > 7) { - $this->markTestSkipped('Only run on php7'); - } - - $checker = new CodeChecker( - new DeprecationCheck(new EmptyCheck()), - false - ); - $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 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'], - ['OC_API::ADMIN_AUTH', 1003, 'test-const.php'], - ]; - } - - /** - * @dataProvider validFilesData - * @param string $fileToVerify - */ - public function testPassValidUsage($fileToVerify) { - $checker = new CodeChecker( - new DeprecationCheck(new EmptyCheck()), - false - ); - $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); - - $this->assertEquals(0, count($errors)); - } - - public function validFilesData() { - return [ - ['test-equal.php'], - ['test-not-equal.php'], - ['test-extends.php'], - ['test-implements.php'], - ['test-static-call.php'], - ['test-new.php'], - ['test-use.php'], - ['test-identical-operator.php'], - ]; - } -} diff --git a/tests/lib/App/CodeChecker/InfoCheckerTest.php b/tests/lib/App/CodeChecker/InfoCheckerTest.php deleted file mode 100644 index 3b5060ae694..00000000000 --- a/tests/lib/App/CodeChecker/InfoCheckerTest.php +++ /dev/null @@ -1,76 +0,0 @@ -<?php -/** - * @author Morris Jobke <hey@morrisjobke.de> - * - * @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\CodeChecker; - -use OC\App\CodeChecker\InfoChecker; -use Test\TestCase; - -class InfoCheckerTest extends TestCase { - /** @var InfoChecker */ - protected $infoChecker; - - public static function setUpBeforeClass(): void { - \OC::$APPSROOTS[] = [ - 'path' => \OC::$SERVERROOT . '/tests/apps', - 'url' => '/apps-test', - 'writable' => false, - ]; - } - - public static function tearDownAfterClass(): void { - // remove last element - array_pop(\OC::$APPSROOTS); - } - - protected function setUp(): void { - parent::setUp(); - $this->infoChecker = new InfoChecker(); - } - - public function appInfoData() { - return [ - ['testapp_infoxml', []], - ['testapp_version', [ - ['type' => 'parseError', 'field' => 'Element \'licence\': This element is not expected. Expected is one of ( description, version ).' . "\n"], - ]], - ['testapp_dependency_missing', [ - ['type' => 'parseError', 'field' => 'Element \'info\': Missing child element(s). Expected is one of ( repository, screenshot, dependencies ).' . "\n"], - ]], - ['testapp_name_missing', [ - ['type' => 'parseError', 'field' => 'Element \'summary\': This element is not expected. Expected is ( name ).' . "\n"], - ]], - ]; - } - - /** - * @dataProvider appInfoData - * - * @param $appId - * @param $expectedErrors - */ - public function testApps($appId, $expectedErrors) { - $errors = $this->infoChecker->analyse($appId); - libxml_clear_errors(); - - $this->assertEquals($expectedErrors, $errors); - } -} diff --git a/tests/lib/App/CodeChecker/Mock/TestList.php b/tests/lib/App/CodeChecker/Mock/TestList.php deleted file mode 100644 index 1fe83293acf..00000000000 --- a/tests/lib/App/CodeChecker/Mock/TestList.php +++ /dev/null @@ -1,92 +0,0 @@ -<?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\CodeChecker\Mock; - -use OC\App\CodeChecker\ICheck; - -class TestList implements ICheck { - /** @var ICheck */ - protected $check; - - /** - * @param ICheck $check - */ - public function __construct(ICheck $check) { - $this->check = $check; - } - - /** - * @param int $errorCode - * @param string $errorObject - * @return string - */ - public function getDescription($errorCode, $errorObject) { - return 'testing'; - } - - /** - * @return array E.g.: `'ClassName' => 'oc version',` - */ - public function getClasses() { - return [ - // Deprecated classes - 'OCP\AppFramework\IApi' => '8.0.0', - ]; - } - - /** - * @return array E.g.: `'ClassName::CONSTANT_NAME' => 'oc version',` - */ - public function getConstants() { - return [ - // Deprecated constants - 'OCP\NamespaceName\ClassName::CONSTANT_NAME' => '8.0.0', - ]; - } - - /** - * @return array E.g.: `'functionName' => 'oc version',` - */ - public function getFunctions() { - return [ - // Deprecated functions - 'OCP\NamespaceName\ClassName::functionName' => '8.0.0', - ]; - } - - /** - * @return array E.g.: `'ClassName::methodName' => 'oc version',` - */ - public function getMethods() { - return [ - // Deprecated methods - 'OCP\NamespaceName\ClassName::methodName' => '8.0.0', - ]; - } - - /** - * @return bool - */ - public function checkStrongComparisons() { - return true; - } -} diff --git a/tests/lib/App/CodeChecker/NodeVisitorTest.php b/tests/lib/App/CodeChecker/NodeVisitorTest.php deleted file mode 100644 index d828b84fc75..00000000000 --- a/tests/lib/App/CodeChecker/NodeVisitorTest.php +++ /dev/null @@ -1,77 +0,0 @@ -<?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\CodeChecker; - -use OC\App\CodeChecker\CodeChecker; -use OC\App\CodeChecker\EmptyCheck; -use Test\App\CodeChecker\Mock\TestList; -use Test\TestCase; - -class NodeVisitorTest 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\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'], - - [[ - ['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'], - - // 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 providesFilesToCheck - * @param array $expectedErrors - * @param string $fileToVerify - */ - public function testMethodsToCheck($expectedErrors, $fileToVerify) { - if (PHP_MAJOR_VERSION > 7) { - $this->markTestSkipped('Only run on php7'); - } - - $checker = new CodeChecker( - new TestList(new EmptyCheck()), - false - ); - $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); - - $this->assertCount(sizeof($expectedErrors), $errors); - - 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/CodeChecker/StrongComparisonCheckTest.php b/tests/lib/App/CodeChecker/StrongComparisonCheckTest.php deleted file mode 100644 index e21dcbbc585..00000000000 --- a/tests/lib/App/CodeChecker/StrongComparisonCheckTest.php +++ /dev/null @@ -1,76 +0,0 @@ -<?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\CodeChecker; - -use OC\App\CodeChecker\CodeChecker; -use OC\App\CodeChecker\EmptyCheck; -use OC\App\CodeChecker\StrongComparisonCheck; -use Test\TestCase; - -class StrongComparisonCheckTest extends TestCase { - - /** - * @dataProvider providesFilesToCheck - * @param string $expectedErrorToken - * @param int $expectedErrorCode - * @param string $fileToVerify - */ - public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) { - $checker = new CodeChecker( - new StrongComparisonCheck(new EmptyCheck()), - false - ); - $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 providesFilesToCheck() { - return [ - ['==', 1005, 'test-equal.php'], - ['!=', 1005, 'test-not-equal.php'], - ]; - } - - /** - * @dataProvider validFilesData - * @param string $fileToVerify - */ - public function testPassValidUsage($fileToVerify) { - if (PHP_MAJOR_VERSION > 7) { - $this->markTestSkipped('Only run on php7'); - } - - $checker = new CodeChecker( - new StrongComparisonCheck(new EmptyCheck()), - false - ); - $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); - - $this->assertEquals(0, count($errors)); - } - - public function validFilesData() { - return [ - ['test-deprecated-use.php'], - ['test-deprecated-use-alias.php'], - ['test-deprecated-use-sub.php'], - ['test-deprecated-use-sub-alias.php'], - ['test-extends.php'], - ['test-implements.php'], - ['test-static-call.php'], - ['test-const.php'], - ['test-new.php'], - ['test-use.php'], - ['test-identical-operator.php'], - ]; - } -} |