StrongComparisonCheckTest.php 1.9 KB

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