diff --git a/.gitattributes b/.gitattributes index fdc4e69..2eb1a64 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,14 +5,15 @@ # https://www.reddit.com/r/PHP/comments/2jzp6k/i_dont_need_your_tests_in_my_production # https://blog.madewithlove.be/post/gitattributes/ # -.gitattributes export-ignore -.gitignore export-ignore -appveyor.yml export-ignore -box.json export-ignore -phpcs.xml.dist export-ignore -/.github/ export-ignore -/doc/ export-ignore -/tests/ export-ignore +.gitattributes export-ignore +.gitignore export-ignore +appveyor.yml export-ignore +box.json export-ignore +phpcs.xml.dist export-ignore +phpunit.xml.dist export-ignore +/.github/ export-ignore +/doc/ export-ignore +/tests/ export-ignore # # Auto detect text files and perform LF normalization diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fc25c25..b16d6ed 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -118,8 +118,15 @@ jobs: run: composer remove --dev php-parallel-lint/php-code-style --no-update --no-interaction - name: Install Composer dependencies + if: ${{ matrix.php != '8.2' }} uses: ramsey/composer-install@v2 + - name: "Install Composer dependencies (PHP 8.2, ignore PHP reqs)" + if: ${{ matrix.php == '8.2' }} + uses: ramsey/composer-install@v2 + with: + composer-options: --ignore-platform-req=php + - name: 'Integration test 1 - linting own code, no colors' continue-on-error: true run: ./parallel-lint --exclude vendor --exclude tests/fixtures --no-colors . @@ -127,12 +134,7 @@ jobs: - name: 'Integration test 2 - linting own code' run: ./parallel-lint --exclude vendor --exclude tests/fixtures . - - name: 'Run unit tests PHP <= 5.5' - if: ${{ matrix.php < 5.6 }} - run: composer testphp5 - - - name: 'Run unit tests PHP >= 5.6' - if: ${{ matrix.php >= 5.6 }} + - name: 'Run unit tests' run: composer test - uses: actions/download-artifact@v3 diff --git a/.gitignore b/.gitignore index 0822554..4c1c0ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ +/build /vendor composer.lock .phpcs.xml phpcs.xml +.phpunit.result.cache +phpunit.xml diff --git a/composer.json b/composer.json index 300c87d..2bd8a28 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "jakub-onderka/php-parallel-lint": "*" }, "require-dev": { - "nette/tester": "^1.3 || ^2.0", + "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0", "php-parallel-lint/php-console-highlighter": "0.* || ^1.0", "php-parallel-lint/php-code-style": "^2.0" }, @@ -45,10 +45,11 @@ "parallel-lint" ], "scripts": { - "test": "@php vendor/bin/tester -C -p php tests", - "testphp5": "@php vendor/bin/tester -c tests/php5.3-5.5.ini -p php tests" + "test": "@php ./vendor/phpunit/phpunit/phpunit --no-coverage", + "coverage": "@php ./vendor/phpunit/phpunit/phpunit" }, "scripts-descriptions": { - "test": "Run all tests!" + "test": "Run all tests!", + "coverage": "Run all tests *with code coverage*" } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 8501dce..6a1bd42 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -12,7 +12,8 @@ . - + + */build/* */tests/fixtures/* */vendor/* @@ -83,9 +84,4 @@ /src/(Application|ParallelLint|Settings|Outputs/TextOutput)\.php$ - - - /tests/*\.php$ - - diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..441226b --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,34 @@ + + + + + + tests/Unit + + + + + + src + + + + + + + + + diff --git a/tests/ParallelLintLintTest.php b/tests/ParallelLintLintTest.php deleted file mode 100644 index 2528149..0000000 --- a/tests/ParallelLintLintTest.php +++ /dev/null @@ -1,144 +0,0 @@ -getPhpExecutable(); - $parallelLint = new ParallelLint($phpExecutable, 10); - Assert::equal($phpExecutable, $parallelLint->getPhpExecutable()); - Assert::equal(10, $parallelLint->getParallelJobs()); - - $phpExecutable2 = $this->getPhpExecutable(); - $parallelLint->setPhpExecutable($phpExecutable2); - Assert::equal($phpExecutable2, $parallelLint->getPhpExecutable()); - - $parallelLint->setParallelJobs(33); - Assert::equal(33, $parallelLint->getParallelJobs()); - - $parallelLint->setShortTagEnabled(true); - Assert::true($parallelLint->isShortTagEnabled()); - - $parallelLint->setAspTagsEnabled(true); - Assert::true($parallelLint->isAspTagsEnabled()); - - $parallelLint->setShortTagEnabled(false); - Assert::false($parallelLint->isShortTagEnabled()); - - $parallelLint->setAspTagsEnabled(false); - Assert::false($parallelLint->isAspTagsEnabled()); - } - - public function testEmptyArray() - { - $parallelLint = new ParallelLint($this->getPhpExecutable()); - $result = $parallelLint->lint(array()); - - Assert::equal(0, $result->getCheckedFilesCount()); - Assert::equal(0, $result->getFilesWithSyntaxErrorCount()); - Assert::false($result->hasSyntaxError()); - Assert::equal(0, count($result->getErrors())); - } - - public function testNotExistsFile() - { - $parallelLint = new ParallelLint($this->getPhpExecutable()); - $result = $parallelLint->lint(array('path/for-not-found/')); - - Assert::equal(0, $result->getCheckedFilesCount()); - Assert::equal(0, $result->getFilesWithSyntaxErrorCount()); - Assert::false($result->hasSyntaxError()); - Assert::equal(1, count($result->getErrors())); - } - - public function testEmptyFile() - { - $parallelLint = new ParallelLint($this->getPhpExecutable()); - $result = $parallelLint->lint(array(__DIR__ . '/fixtures/fixture-01/empty-file')); - - Assert::equal(1, $result->getCheckedFilesCount()); - Assert::equal(0, $result->getFilesWithSyntaxErrorCount()); - Assert::false($result->hasSyntaxError()); - Assert::equal(0, count($result->getErrors())); - } - - public function testValidFile() - { - $parallelLint = new ParallelLint($this->getPhpExecutable()); - $result = $parallelLint->lint(array(__DIR__ . '/fixtures/fixture-02/example.php')); - - Assert::equal(1, $result->getCheckedFilesCount()); - Assert::equal(0, $result->getFilesWithSyntaxErrorCount()); - Assert::equal(0, count($result->getErrors())); - } - - public function testInvalidFile() - { - $parallelLint = new ParallelLint($this->getPhpExecutable()); - $result = $parallelLint->lint(array(__DIR__ . '/fixtures/fixture-03/example.php')); - - Assert::equal(1, $result->getCheckedFilesCount()); - Assert::equal(1, $result->getFilesWithSyntaxErrorCount()); - Assert::true($result->hasSyntaxError()); - Assert::equal(1, count($result->getErrors())); - } - - public function testDeprecated() - { - $parallelLint = new ParallelLint($this->getPhpExecutable()); - $result = $parallelLint->lint(array(__DIR__ . '/fixtures/fixture-05/Foo.php')); - Assert::equal(1, $result->getCheckedFilesCount()); - Assert::equal(0, $result->getFilesWithSyntaxErrorCount()); - Assert::false($result->hasSyntaxError()); - Assert::equal(0, count($result->getErrors())); - - if (PHP_VERSION_ID < 70000 || PHP_VERSION_ID >= 80000) { - Environment::skip('test for php version 7.0-7.4'); - } - - $parallelLint = new ParallelLint($this->getPhpExecutable()); - $parallelLint->setShowDeprecated(true); - $result = $parallelLint->lint(array(__DIR__ . '/fixtures/fixture-05/Foo.php')); - Assert::equal(1, $result->getCheckedFilesCount()); - Assert::equal(1, $result->getFilesWithSyntaxErrorCount()); - Assert::true($result->hasSyntaxError()); - Assert::equal(1, count($result->getErrors())); - } - - public function testValidAndInvalidFiles() - { - $parallelLint = new ParallelLint($this->getPhpExecutable()); - $result = $parallelLint->lint(array( - __DIR__ . '/fixtures/fixture-02/example.php', - __DIR__ . '/fixtures/fixture-03/example.php', - )); - - Assert::equal(2, $result->getCheckedFilesCount()); - Assert::equal(1, $result->getFilesWithSyntaxErrorCount()); - Assert::true($result->hasSyntaxError()); - Assert::equal(1, count($result->getErrors())); - } - - private function getPhpExecutable() - { - return PhpExecutable::getPhpExecutable('php'); - } -} - -$testCase = new ParallelLintLintTest(); -$testCase->run(); diff --git a/tests/SyntaxErrorNormalizeMessageTest.php b/tests/SyntaxErrorNormalizeMessageTest.php deleted file mode 100644 index 69249b4..0000000 --- a/tests/SyntaxErrorNormalizeMessageTest.php +++ /dev/null @@ -1,34 +0,0 @@ -getNormalizedMessage()); - } - - public function testInWordInErrorMessageAndInFileName() - { - $message = 'Fatal error: \'break\' not in the \'loop\' or \'switch\' context in test in file.php on line 2'; - $error = new SyntaxError('test in file.php', $message); - Assert::equal('\'break\' not in the \'loop\' or \'switch\' context', $error->getNormalizedMessage()); - } -} - -$testCase = new SyntaxErrorNormalizeMessageTest(); -$testCase->run(); diff --git a/tests/Unit/Errors/SyntaxErrorGetNormalizeMessageTest.php b/tests/Unit/Errors/SyntaxErrorGetNormalizeMessageTest.php new file mode 100644 index 0000000..6e3a88e --- /dev/null +++ b/tests/Unit/Errors/SyntaxErrorGetNormalizeMessageTest.php @@ -0,0 +1,23 @@ +assertSame('\'break\' not in the \'loop\' or \'switch\' context', $error->getNormalizedMessage()); + } + + public function testInWordInErrorMessageAndInFileName() + { + $message = 'Fatal error: \'break\' not in the \'loop\' or \'switch\' context in test in file.php on line 2'; + $error = new SyntaxError('test in file.php', $message); + $this->assertSame('\'break\' not in the \'loop\' or \'switch\' context', $error->getNormalizedMessage()); + } +} diff --git a/tests/ManagerRunTest.php b/tests/Unit/ManagerRunTest.php similarity index 65% rename from tests/ManagerRunTest.php rename to tests/Unit/ManagerRunTest.php index 7402681..e68a9f3 100644 --- a/tests/ManagerRunTest.php +++ b/tests/Unit/ManagerRunTest.php @@ -1,95 +1,88 @@ expectExceptionPolyfill('\PHP_Parallel_Lint\PhpParallelLint\Exceptions\PathNotFoundException'); + $settings = $this->prepareSettings(); $settings->paths = array('path/for-not-found/'); $manager = $this->getManager($settings); - Assert::exception(function () use ($manager, $settings) { - $manager->run($settings); - }, '\PHP_Parallel_Lint\PhpParallelLint\Exceptions\PathNotFoundException'); + $manager->run($settings); } public function testFilesNotFound() { + $this->expectExceptionPolyfill('\PHP_Parallel_Lint\PhpParallelLint\Exceptions\ParallelLintException'); + $this->expectExceptionMessagePolyfill('No file found to check.'); + $settings = $this->prepareSettings(); - $settings->paths = array('fixtures/fixture-01/'); + $settings->paths = array('tests/fixtures/fixture-01/'); $manager = $this->getManager($settings); - Assert::exception(function () use ($manager, $settings) { - $manager->run($settings); - }, '\PHP_Parallel_Lint\PhpParallelLint\Exceptions\ParallelLintException', 'No file found to check.'); + $manager->run($settings); } public function testSuccess() { $settings = $this->prepareSettings(); - $settings->paths = array('fixtures/fixture-02/'); + $settings->paths = array('tests/fixtures/fixture-02/'); $manager = $this->getManager($settings); $result = $manager->run($settings); - Assert::false($result->hasError()); + $this->assertFalse($result->hasError()); } public function testError() { $settings = $this->prepareSettings(); - $settings->paths = array('fixtures/fixture-03/'); + $settings->paths = array('tests/fixtures/fixture-03/'); $manager = $this->getManager($settings); $result = $manager->run($settings); - Assert::true($result->hasError()); + $this->assertTrue($result->hasError()); } public function testExcludeRelativeSubdirectory() { $settings = $this->prepareSettings(); - $settings->paths = array('fixtures/fixture-04/'); + $settings->paths = array('tests/fixtures/fixture-04/'); $manager = $this->getManager($settings); $result = $manager->run($settings); - Assert::true($result->hasError()); + $this->assertTrue($result->hasError()); - $settings->excluded = array('fixtures/fixture-04/dir1/dir2'); + $settings->excluded = array('tests/fixtures/fixture-04/dir1/dir2'); $manager = $this->getManager($settings); $result = $manager->run($settings); - Assert::false($result->hasError()); + $this->assertFalse($result->hasError()); } public function testExcludeAbsoluteSubdirectory() { $settings = $this->prepareSettings(); $cwd = getcwd(); - $settings->paths = array($cwd . '/fixtures/fixture-04/'); + $settings->paths = array($cwd . '/tests/fixtures/fixture-04/'); $settings->excluded = array(); $manager = $this->getManager($settings); $result = $manager->run($settings); - Assert::true($result->hasError()); + $this->assertTrue($result->hasError()); - $settings->excluded = array($cwd . '/fixtures/fixture-04/dir1/dir2'); + $settings->excluded = array($cwd . '/tests/fixtures/fixture-04/dir1/dir2'); $manager = $this->getManager($settings); $result = $manager->run($settings); - Assert::false($result->hasError()); + $this->assertFalse($result->hasError()); } /** @@ -100,13 +93,13 @@ public function testExcludeAbsoluteSubdirectory() public function testMultiPartExtensions() { $settings = $this->prepareSettings(); - $settings->paths = array('fixtures/fixture-06/'); + $settings->paths = array('tests/fixtures/fixture-06/'); $settings->extensions = array('php', 'php.dist'); $manager = $this->getManager($settings); $result = $manager->run($settings); - Assert::false($result->hasError()); + $this->assertFalse($result->hasError()); } /** @@ -138,6 +131,3 @@ private function prepareSettings() return $settings; } } - -$testCase = new ManagerRunTest(); -$testCase->run(); diff --git a/tests/OutputTest.php b/tests/Unit/Outputs/OutputTest.php similarity index 74% rename from tests/OutputTest.php rename to tests/Unit/Outputs/OutputTest.php index cbdc0d7..31cad47 100644 --- a/tests/OutputTest.php +++ b/tests/Unit/Outputs/OutputTest.php @@ -1,13 +1,6 @@ getLine(); } - Assert::equal($result[$i]->type, 'issue'); - Assert::equal($result[$i]->check_name, 'Parse error'); - Assert::equal($result[$i]->categories, 'Style'); - Assert::equal($result[$i]->severity, 'minor'); - Assert::equal($result[$i]->description, $message); - Assert::equal($result[$i]->fingerprint, md5($filePath . $message . $line)); - Assert::equal($result[$i]->location->path, $filePath); - Assert::equal($result[$i]->location->lines->begin, $line); + $this->assertSame($result[$i]->type, 'issue'); + $this->assertSame($result[$i]->check_name, 'Parse error'); + $this->assertSame($result[$i]->categories, 'Style'); + $this->assertSame($result[$i]->severity, 'minor'); + $this->assertSame($result[$i]->description, $message); + $this->assertSame($result[$i]->fingerprint, md5($filePath . $message . $line)); + $this->assertSame($result[$i]->location->path, $filePath); + $this->assertSame($result[$i]->location->lines->begin, $line); } } @@ -70,8 +62,8 @@ public function testCheckstyleOutput() // phpcs:ignore Generic.PHP.NoSilencedErrors -- Test only code, this is okay. $parsed = @simplexml_load_string($xml); - Assert::contains("unexpected '"'", $xml); - Assert::type('SimpleXMLElement', $parsed); + $this->assertStringContainsStringPolyfill("unexpected '"'", $xml); + $this->assertInstanceOf('SimpleXMLElement', $parsed); } public function getGitLabOutputData() @@ -99,6 +91,3 @@ public function getGitLabOutputData() ); } } - -$testCase = new OutputTest(); -$testCase->run(); diff --git a/tests/Unit/ParallelLintLintTest.php b/tests/Unit/ParallelLintLintTest.php new file mode 100644 index 0000000..f0a8148 --- /dev/null +++ b/tests/Unit/ParallelLintLintTest.php @@ -0,0 +1,132 @@ +getPhpExecutable(); + $parallelLint = new ParallelLint($phpExecutable, 10); + $this->assertSame($phpExecutable, $parallelLint->getPhpExecutable()); + $this->assertSame(10, $parallelLint->getParallelJobs()); + + $phpExecutable2 = $this->getPhpExecutable(); + $parallelLint->setPhpExecutable($phpExecutable2); + $this->assertSame($phpExecutable2, $parallelLint->getPhpExecutable()); + + $parallelLint->setParallelJobs(33); + $this->assertSame(33, $parallelLint->getParallelJobs()); + + $parallelLint->setShortTagEnabled(true); + $this->assertTrue($parallelLint->isShortTagEnabled()); + + $parallelLint->setAspTagsEnabled(true); + $this->assertTrue($parallelLint->isAspTagsEnabled()); + + $parallelLint->setShortTagEnabled(false); + $this->assertFalse($parallelLint->isShortTagEnabled()); + + $parallelLint->setAspTagsEnabled(false); + $this->assertFalse($parallelLint->isAspTagsEnabled()); + } + + public function testEmptyArray() + { + $parallelLint = new ParallelLint($this->getPhpExecutable()); + $result = $parallelLint->lint(array()); + + $this->assertSame(0, $result->getCheckedFilesCount()); + $this->assertSame(0, $result->getFilesWithSyntaxErrorCount()); + $this->assertFalse($result->hasSyntaxError()); + $this->assertSame(0, count($result->getErrors())); + } + + public function testNotExistsFile() + { + $parallelLint = new ParallelLint($this->getPhpExecutable()); + $result = $parallelLint->lint(array('path/for-not-found/')); + + $this->assertSame(0, $result->getCheckedFilesCount()); + $this->assertSame(0, $result->getFilesWithSyntaxErrorCount()); + $this->assertFalse($result->hasSyntaxError()); + $this->assertSame(1, count($result->getErrors())); + } + + public function testEmptyFile() + { + $parallelLint = new ParallelLint($this->getPhpExecutable()); + $result = $parallelLint->lint(array(PL_TESTROOT . '/fixtures/fixture-01/empty-file')); + + $this->assertSame(1, $result->getCheckedFilesCount()); + $this->assertSame(0, $result->getFilesWithSyntaxErrorCount()); + $this->assertFalse($result->hasSyntaxError()); + $this->assertSame(0, count($result->getErrors())); + } + + public function testValidFile() + { + $parallelLint = new ParallelLint($this->getPhpExecutable()); + $result = $parallelLint->lint(array(PL_TESTROOT . '/fixtures/fixture-02/example.php')); + + $this->assertSame(1, $result->getCheckedFilesCount()); + $this->assertSame(0, $result->getFilesWithSyntaxErrorCount()); + $this->assertSame(0, count($result->getErrors())); + } + + public function testInvalidFile() + { + $parallelLint = new ParallelLint($this->getPhpExecutable()); + $result = $parallelLint->lint(array(PL_TESTROOT . '/fixtures/fixture-03/example.php')); + + $this->assertSame(1, $result->getCheckedFilesCount()); + $this->assertSame(1, $result->getFilesWithSyntaxErrorCount()); + $this->assertTrue($result->hasSyntaxError()); + $this->assertSame(1, count($result->getErrors())); + } + + public function testDeprecated() + { + $parallelLint = new ParallelLint($this->getPhpExecutable()); + $result = $parallelLint->lint(array(PL_TESTROOT . '/fixtures/fixture-05/Foo.php')); + $this->assertSame(1, $result->getCheckedFilesCount()); + $this->assertSame(0, $result->getFilesWithSyntaxErrorCount()); + $this->assertFalse($result->hasSyntaxError()); + $this->assertSame(0, count($result->getErrors())); + + if (PHP_VERSION_ID < 70000 || PHP_VERSION_ID >= 80000) { + $this->markTestSkipped('Test for php version 7.0-7.4'); + } + + $parallelLint = new ParallelLint($this->getPhpExecutable()); + $parallelLint->setShowDeprecated(true); + $result = $parallelLint->lint(array(PL_TESTROOT . '/fixtures/fixture-05/Foo.php')); + $this->assertSame(1, $result->getCheckedFilesCount()); + $this->assertSame(1, $result->getFilesWithSyntaxErrorCount()); + $this->assertTrue($result->hasSyntaxError()); + $this->assertSame(1, count($result->getErrors())); + } + + public function testValidAndInvalidFiles() + { + $parallelLint = new ParallelLint($this->getPhpExecutable()); + $result = $parallelLint->lint(array( + PL_TESTROOT . '/fixtures/fixture-02/example.php', + PL_TESTROOT . '/fixtures/fixture-03/example.php', + )); + + $this->assertSame(2, $result->getCheckedFilesCount()); + $this->assertSame(1, $result->getFilesWithSyntaxErrorCount()); + $this->assertTrue($result->hasSyntaxError()); + $this->assertSame(1, count($result->getErrors())); + } + + private function getPhpExecutable() + { + return PhpExecutable::getPhpExecutable('php'); + } +} diff --git a/tests/SkipLintProcessTest.php b/tests/Unit/Process/SkipLintProcessTest.php similarity index 59% rename from tests/SkipLintProcessTest.php rename to tests/Unit/Process/SkipLintProcessTest.php index 9387d9f..e1f9169 100644 --- a/tests/SkipLintProcessTest.php +++ b/tests/Unit/Process/SkipLintProcessTest.php @@ -1,26 +1,18 @@ isSkipped($fileToCheck); - Assert::notEqual(null, $status); + $this->assertNotNull($status); } } } - -$skipLintProcessTest = new SkipLintProcessTest(); -$skipLintProcessTest->run(); diff --git a/tests/SettingsParseArgumentsTest.php b/tests/Unit/SettingsParseArgumentsTest.php similarity index 60% rename from tests/SettingsParseArgumentsTest.php rename to tests/Unit/SettingsParseArgumentsTest.php index 48cbadc..6ef1cf5 100644 --- a/tests/SettingsParseArgumentsTest.php +++ b/tests/Unit/SettingsParseArgumentsTest.php @@ -1,19 +1,11 @@ format = Settings::FORMAT_TEXT; $expectedSettings->syntaxErrorCallbackFile = null; - Assert::equal($expectedSettings->shortTag, $settings->shortTag); - Assert::equal($expectedSettings->aspTags, $settings->aspTags); - Assert::equal($expectedSettings->parallelJobs, $settings->parallelJobs); - Assert::equal($expectedSettings->extensions, $settings->extensions); - Assert::equal($expectedSettings->paths, $settings->paths); - Assert::equal($expectedSettings->excluded, $settings->excluded); - Assert::equal($expectedSettings->colors, $settings->colors); - Assert::equal($expectedSettings->showProgress, $settings->showProgress); - Assert::equal($expectedSettings->format, $settings->format); - Assert::equal($expectedSettings->syntaxErrorCallbackFile, $settings->syntaxErrorCallbackFile); + $this->assertSame($expectedSettings->shortTag, $settings->shortTag); + $this->assertSame($expectedSettings->aspTags, $settings->aspTags); + $this->assertSame($expectedSettings->parallelJobs, $settings->parallelJobs); + $this->assertSame($expectedSettings->extensions, $settings->extensions); + $this->assertSame($expectedSettings->paths, $settings->paths); + $this->assertSame($expectedSettings->excluded, $settings->excluded); + $this->assertSame($expectedSettings->colors, $settings->colors); + $this->assertSame($expectedSettings->showProgress, $settings->showProgress); + $this->assertSame($expectedSettings->format, $settings->format); + $this->assertSame($expectedSettings->syntaxErrorCallbackFile, $settings->syntaxErrorCallbackFile); } public function testMoreArguments() @@ -63,16 +55,16 @@ public function testMoreArguments() $expectedSettings->format = Settings::FORMAT_TEXT; $expectedSettings->showDeprecated = false; - Assert::equal($expectedSettings->shortTag, $settings->shortTag); - Assert::equal($expectedSettings->aspTags, $settings->aspTags); - Assert::equal($expectedSettings->parallelJobs, $settings->parallelJobs); - Assert::equal($expectedSettings->extensions, $settings->extensions); - Assert::equal($expectedSettings->paths, $settings->paths); - Assert::equal($expectedSettings->excluded, $settings->excluded); - Assert::equal($expectedSettings->colors, $settings->colors); - Assert::equal($expectedSettings->showProgress, $settings->showProgress); - Assert::equal($expectedSettings->format, $settings->format); - Assert::equal($expectedSettings->showDeprecated, $settings->showDeprecated); + $this->assertSame($expectedSettings->shortTag, $settings->shortTag); + $this->assertSame($expectedSettings->aspTags, $settings->aspTags); + $this->assertSame($expectedSettings->parallelJobs, $settings->parallelJobs); + $this->assertSame($expectedSettings->extensions, $settings->extensions); + $this->assertSame($expectedSettings->paths, $settings->paths); + $this->assertSame($expectedSettings->excluded, $settings->excluded); + $this->assertSame($expectedSettings->colors, $settings->colors); + $this->assertSame($expectedSettings->showProgress, $settings->showProgress); + $this->assertSame($expectedSettings->format, $settings->format); + $this->assertSame($expectedSettings->showDeprecated, $settings->showDeprecated); } public function testColorsForced() @@ -84,7 +76,7 @@ public function testColorsForced() $expectedSettings = new Settings(); $expectedSettings->colors = Settings::FORCED; - Assert::equal($expectedSettings->colors, $settings->colors); + $this->assertSame($expectedSettings->colors, $settings->colors); } public function testNoProgress() @@ -96,7 +88,7 @@ public function testNoProgress() $expectedSettings = new Settings(); $expectedSettings->showProgress = false; - Assert::equal($expectedSettings->showProgress, $settings->showProgress); + $this->assertSame($expectedSettings->showProgress, $settings->showProgress); } public function testJsonOutput() @@ -104,7 +96,7 @@ public function testJsonOutput() $commandLine = './parallel-lint --json .'; $argv = explode(" ", $commandLine); $settings = Settings::parseArguments($argv); - Assert::equal(Settings::FORMAT_JSON, $settings->format); + $this->assertSame(Settings::FORMAT_JSON, $settings->format); } public function testGitLabOutput() @@ -112,7 +104,7 @@ public function testGitLabOutput() $commandLine = './parallel-lint --gitlab .'; $argv = explode(" ", $commandLine); $settings = Settings::parseArguments($argv); - Assert::equal(Settings::FORMAT_GITLAB, $settings->format); + $this->assertSame(Settings::FORMAT_GITLAB, $settings->format); } public function testCheckstyleOutput() @@ -120,7 +112,7 @@ public function testCheckstyleOutput() $commandLine = './parallel-lint --checkstyle .'; $argv = explode(" ", $commandLine); $settings = Settings::parseArguments($argv); - Assert::equal(Settings::FORMAT_CHECKSTYLE, $settings->format); + $this->assertSame(Settings::FORMAT_CHECKSTYLE, $settings->format); } public function testExtensions() @@ -132,7 +124,7 @@ public function testExtensions() $expectedSettings = new Settings(); $expectedSettings->extensions = array('php', 'php.dist', 'phpt'); - Assert::equal($expectedSettings->extensions, $settings->extensions); + $this->assertSame($expectedSettings->extensions, $settings->extensions); } public function testFailCallaback() @@ -144,9 +136,6 @@ public function testFailCallaback() $expectedSettings = new Settings(); $expectedSettings->syntaxErrorCallbackFile = "./path/to/my_custom_callback_file.php"; - Assert::equal($expectedSettings->syntaxErrorCallbackFile, $settings->syntaxErrorCallbackFile); + $this->assertSame($expectedSettings->syntaxErrorCallbackFile, $settings->syntaxErrorCallbackFile); } } - -$testCase = new SettingsParseArgumentsTest(); -$testCase->run(); diff --git a/tests/UnitTestCase.php b/tests/UnitTestCase.php new file mode 100644 index 0000000..e521458 --- /dev/null +++ b/tests/UnitTestCase.php @@ -0,0 +1,89 @@ +exceptionMessage = ''; + } + + /** + * PHPUnit Polyfill: Set an expectation to receive a particular type of Exception. + * + * @param mixed $exception The name of the exception to expect. + * + * @return void + */ + public function expectExceptionPolyfill($exception) + { + if (method_exists('\PHPUnit\Framework\TestCase', 'expectException')) { + // PHPUnit >= 5.2.0. + parent::expectException($exception); + return; + } + + $this->setExpectedException($exception, $this->exceptionMessage); + } + + /** + * PHPUnit Polyfill: Set an expectation to receive an Exception with a particular error message. + * + * @param string $message The error message to expect. + * + * @return void + */ + public function expectExceptionMessagePolyfill($message) + { + if (method_exists('\PHPUnit\Framework\TestCase', 'expectExceptionMessage')) { + // PHPUnit >= 5.2.0. + parent::expectExceptionMessage($message); + return; + } + + // Store the received message in case any of the other methods are called as well. + $this->exceptionMessage = $message; + + $exception = $this->getExpectedException(); + $this->setExpectedException($exception, $message); + } + + /** + * PHPUnit Polyfill: Asserts that a string haystack contains a needle. + * + * @param string $needle The string to search for. + * @param string $haystack The string to treat as the haystack. + * @param string $message Optional failure message to display. + * + * @return void + */ + public static function assertStringContainsStringPolyfill($needle, $haystack, $message = '') + { + if (\method_exists('\PHPUnit\Framework\Assert', 'assertStringContainsString')) { + // PHPUnit >= 7.5.0. + parent::assertStringContainsString($needle, $haystack, $message); + return; + } + + // PHPUnit < 7.5.0. + if ($needle === '') { + static::assertSame($needle, $needle, $message); + return; + } + + static::assertContains($needle, $haystack, $message); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..cbcf6e7 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,69 @@ += 6 name. +if ( + class_exists('PHPUnit_Framework_Exception') === true + && class_exists('PHPUnit\Framework\Exception') === false +) { + class_alias('PHPUnit_Framework_Exception', 'PHPUnit\Framework\Exception'); +} + +define('PL_TESTROOT', __DIR__); diff --git a/tests/php5.3-5.5.ini b/tests/php5.3-5.5.ini deleted file mode 100644 index 6e4cb53..0000000 --- a/tests/php5.3-5.5.ini +++ /dev/null @@ -1,11 +0,0 @@ -[PHP] - -extension=json.so -extension=simplexml.so -extension=tokenizer.so - -memory_limit=512M - -error_reporting=-1 -display_errors=On -display_startup_errors = On