NodeVisitorTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Copyright (c) 2015 Joas Schilling <nickvergessen@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test\App\CodeChecker;
  9. use OC\App\CodeChecker\CodeChecker;
  10. use OC\App\CodeChecker\EmptyCheck;
  11. use Test\App\CodeChecker\Mock\TestList;
  12. use Test\TestCase;
  13. class NodeVisitorTest extends TestCase {
  14. public function providesFilesToCheck() {
  15. return [
  16. [[['OCP\AppFramework\IApi', 1006]], 'test-deprecated-use.php'],
  17. [[['OCP\AppFramework\IApi', 1006]], 'test-deprecated-use-alias.php'],
  18. [[['AppFramework\IApi', 1001]], 'test-deprecated-use-sub.php'],
  19. [[['OAF\IApi', 1001]], 'test-deprecated-use-sub-alias.php'],
  20. [[['OCP\NamespaceName\ClassName::CONSTANT_NAME', 1003]], 'test-deprecated-constant.php'],
  21. [[['Alias::CONSTANT_NAME', 1003]], 'test-deprecated-constant-alias.php'],
  22. [[['NamespaceName\ClassName::CONSTANT_NAME', 1003]], 'test-deprecated-constant-sub.php'],
  23. [[['SubAlias\ClassName::CONSTANT_NAME', 1003]], 'test-deprecated-constant-sub-alias.php'],
  24. [[
  25. ['OCP\NamespaceName\ClassName::functionName', 1002],
  26. ['OCP\NamespaceName\ClassName::methodName', 1007],
  27. ], 'test-deprecated-function.php'],
  28. [[
  29. ['Alias::functionName', 1002],
  30. ['Alias::methodName', 1007],
  31. ], 'test-deprecated-function-alias.php'],
  32. [[
  33. ['NamespaceName\ClassName::functionName', 1002],
  34. ['NamespaceName\ClassName::methodName', 1007],
  35. ], 'test-deprecated-function-sub.php'],
  36. [[
  37. ['SubAlias\ClassName::functionName', 1002],
  38. ['SubAlias\ClassName::methodName', 1007],
  39. ], 'test-deprecated-function-sub-alias.php'],
  40. // TODO Failing to resolve variables to classes
  41. // [[['OCP\NamespaceName\ClassName::methodName', 1007]], 'test-deprecated-method.php'],
  42. // [[['Alias::methodName', 1002]], 'test-deprecated-method-alias.php'],
  43. // [[['NamespaceName\ClassName::methodName', 1002]], 'test-deprecated-method-sub.php'],
  44. // [[['SubAlias\ClassName::methodName', 1002]], 'test-deprecated-method-sub-alias.php'],
  45. ];
  46. }
  47. /**
  48. * @dataProvider providesFilesToCheck
  49. * @param array $expectedErrors
  50. * @param string $fileToVerify
  51. */
  52. public function testMethodsToCheck($expectedErrors, $fileToVerify) {
  53. $checker = new CodeChecker(
  54. new TestList(new EmptyCheck())
  55. );
  56. $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");
  57. $this->assertCount(sizeof($expectedErrors), $errors);
  58. foreach ($expectedErrors as $int => $expectedError) {
  59. $this->assertEquals($expectedError[0], $errors[$int]['disallowedToken']);
  60. $this->assertEquals($expectedError[1], $errors[$int]['errorCode']);
  61. }
  62. }
  63. }