parent
3fae984b56
commit
4e95031ec4
@ -0,0 +1,44 @@ |
||||
<?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 OC\App; |
||||
|
||||
use PhpParser\Lexer; |
||||
use PhpParser\Node; |
||||
use PhpParser\Node\Name; |
||||
|
||||
class DeprecationCodeChecker extends CodeChecker { |
||||
protected $checkEqualOperators = true; |
||||
|
||||
/** @var string */ |
||||
protected $blackListDescription = 'deprecated'; |
||||
|
||||
protected $blackListedClassNames = [ |
||||
// Deprecated classes |
||||
'OCP\IConfig', |
||||
'OCP\Contacts', |
||||
'OCP\DB', |
||||
'OCP\IHelper', |
||||
'OCP\JSON', |
||||
'OCP\Response', |
||||
'OCP\AppFramework\IApi', |
||||
]; |
||||
} |
||||
@ -0,0 +1,59 @@ |
||||
<?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 DeprecationCodeChecker extends TestCase { |
||||
|
||||
/** |
||||
* @dataProvider providesFilesToCheck |
||||
* @param $expectedErrorToken |
||||
* @param $expectedErrorCode |
||||
* @param $fileToVerify |
||||
*/ |
||||
public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) { |
||||
$checker = new \OC\App\DeprecationCodeChecker(); |
||||
$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 $fileToVerify |
||||
*/ |
||||
public function testPassValidUsage($fileToVerify) { |
||||
$checker = new \OC\App\DeprecationCodeChecker(); |
||||
$errors = $checker->analyseFile(OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); |
||||
|
||||
$this->assertEquals(0, count($errors)); |
||||
} |
||||
|
||||
public function validFilesData() { |
||||
return [ |
||||
['test-extends.php'], |
||||
['test-implements.php'], |
||||
['test-static-call.php'], |
||||
['test-const.php'], |
||||
['test-new.php'], |
||||
['test-identical-operator.php'], |
||||
]; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue