CodeCheckerTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright (c) 2015 Thomas Müller <deepdiver@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 OC\App\CodeChecker\PrivateCheck;
  12. use Test\TestCase;
  13. class CodeCheckerTest 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 PrivateCheck(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. ['OC_Hook', 1000, 'test-extends.php'],
  33. ['oC_Avatar', 1001, 'test-implements.php'],
  34. ['OC_App', 1002, 'test-static-call.php'],
  35. ['OC_API', 1003, 'test-const.php'],
  36. ['OC_AppConfig', 1004, 'test-new.php'],
  37. ['OC_AppConfig', 1006, 'test-use.php'],
  38. ];
  39. }
  40. /**
  41. * @dataProvider validFilesData
  42. * @param string $fileToVerify
  43. */
  44. public function testPassValidUsage($fileToVerify) {
  45. $checker = new CodeChecker(
  46. new PrivateCheck(new EmptyCheck()),
  47. false
  48. );
  49. $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");
  50. $this->assertEquals(0, count($errors));
  51. }
  52. public function validFilesData() {
  53. return [
  54. ['test-identical-operator.php'],
  55. ];
  56. }
  57. }