DeprecationCheckTest.php 2.0 KB

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