CodeCheckerTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. );
  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. ['OC_Hook', 1000, 'test-extends.php'],
  32. ['oC_Avatar', 1001, 'test-implements.php'],
  33. ['OC_App', 1002, 'test-static-call.php'],
  34. ['OC_API', 1003, 'test-const.php'],
  35. ['OC_AppConfig', 1004, 'test-new.php'],
  36. ['OC_AppConfig', 1006, 'test-use.php'],
  37. ];
  38. }
  39. /**
  40. * @dataProvider validFilesData
  41. * @param string $fileToVerify
  42. */
  43. public function testPassValidUsage($fileToVerify) {
  44. $checker = new CodeChecker(
  45. new PrivateCheck(new EmptyCheck())
  46. );
  47. $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");
  48. $this->assertEquals(0, count($errors));
  49. }
  50. public function validFilesData() {
  51. return [
  52. ['test-identical-operator.php'],
  53. ];
  54. }
  55. }