CodeCheckerTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. if (PHP_MAJOR_VERSION > 7) {
  22. $this->markTestSkipped('Only run on php7');
  23. }
  24. $checker = new CodeChecker(
  25. new PrivateCheck(new EmptyCheck()),
  26. false
  27. );
  28. $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");
  29. $this->assertEquals(1, count($errors));
  30. $this->assertEquals($expectedErrorCode, $errors[0]['errorCode']);
  31. $this->assertEquals($expectedErrorToken, $errors[0]['disallowedToken']);
  32. }
  33. public function providesFilesToCheck() {
  34. return [
  35. ['OC_Hook', 1000, 'test-extends.php'],
  36. ['oC_Avatar', 1001, 'test-implements.php'],
  37. ['OC_App', 1002, 'test-static-call.php'],
  38. ['OC_API', 1003, 'test-const.php'],
  39. ['OC_AppConfig', 1004, 'test-new.php'],
  40. ['OC_AppConfig', 1006, 'test-use.php'],
  41. ];
  42. }
  43. /**
  44. * @dataProvider validFilesData
  45. * @param string $fileToVerify
  46. */
  47. public function testPassValidUsage($fileToVerify) {
  48. if (PHP_MAJOR_VERSION > 7) {
  49. $this->markTestSkipped('Only run on php7');
  50. }
  51. $checker = new CodeChecker(
  52. new PrivateCheck(new EmptyCheck()),
  53. false
  54. );
  55. $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");
  56. $this->assertEquals(0, count($errors));
  57. }
  58. public function validFilesData() {
  59. return [
  60. ['test-identical-operator.php'],
  61. ];
  62. }
  63. }