StrongComparisonCheckTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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\EmptyCheck;
  11. use OC\App\CodeChecker\StrongComparisonCheck;
  12. use Test\TestCase;
  13. class StrongComparisonCheckTest 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 StrongComparisonCheck(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. ['==', 1005, 'test-equal.php'],
  32. ['!=', 1005, 'test-not-equal.php'],
  33. ];
  34. }
  35. /**
  36. * @dataProvider validFilesData
  37. * @param string $fileToVerify
  38. */
  39. public function testPassValidUsage($fileToVerify) {
  40. $checker = new CodeChecker(
  41. new StrongComparisonCheck(new EmptyCheck())
  42. );
  43. $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify");
  44. $this->assertEquals(0, count($errors));
  45. }
  46. public function validFilesData() {
  47. return [
  48. ['test-deprecated-use.php'],
  49. ['test-deprecated-use-alias.php'],
  50. ['test-deprecated-use-sub.php'],
  51. ['test-deprecated-use-sub-alias.php'],
  52. ['test-extends.php'],
  53. ['test-implements.php'],
  54. ['test-static-call.php'],
  55. ['test-const.php'],
  56. ['test-new.php'],
  57. ['test-use.php'],
  58. ['test-identical-operator.php'],
  59. ];
  60. }
  61. }