DeprecationCheckTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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\DeprecationCheck;
  11. use OC\App\CodeChecker\EmptyCheck;
  12. use Test\TestCase;
  13. class DeprecationCheckTest extends TestCase {
  14. /**
  15. * @dataProvider providesFilesToCheck
  16. * @param string $expectedErrorToken
  17. * @param int $expectedErrorCode
  18. * @param string $fileToVerify
  19. */
  20. public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) {
  21. $checker = new CodeChecker(
  22. new DeprecationCheck(new EmptyCheck()),
  23. false
  24. );
  25. $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");
  26. $this->assertEquals(1, count($errors));
  27. $this->assertEquals($expectedErrorCode, $errors[0]['errorCode']);
  28. $this->assertEquals($expectedErrorToken, $errors[0]['disallowedToken']);
  29. }
  30. public function providesFilesToCheck() {
  31. return [
  32. ['OCP\AppFramework\IApi', 1006, 'test-deprecated-use.php'],
  33. ['OCP\AppFramework\IApi', 1006, 'test-deprecated-use-alias.php'],
  34. ['AppFramework\IApi', 1001, 'test-deprecated-use-sub.php'],
  35. ['OAF\IApi', 1001, 'test-deprecated-use-sub-alias.php'],
  36. ['OC_API::ADMIN_AUTH', 1003, 'test-const.php'],
  37. ];
  38. }
  39. /**
  40. * @dataProvider validFilesData
  41. * @param string $fileToVerify
  42. */
  43. public function testPassValidUsage($fileToVerify) {
  44. $checker = new CodeChecker(
  45. new DeprecationCheck(new EmptyCheck()),
  46. false
  47. );
  48. $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");
  49. $this->assertEquals(0, count($errors));
  50. }
  51. public function validFilesData() {
  52. return [
  53. ['test-equal.php'],
  54. ['test-not-equal.php'],
  55. ['test-extends.php'],
  56. ['test-implements.php'],
  57. ['test-static-call.php'],
  58. ['test-new.php'],
  59. ['test-use.php'],
  60. ['test-identical-operator.php'],
  61. ];
  62. }
  63. }