From 7d38d4bd4f8808b8b8ce5c65bba4b337f583014b Mon Sep 17 00:00:00 2001 From: Vaggelis Yfantis Date: Fri, 5 Jun 2020 06:16:03 +0300 Subject: [PATCH 01/32] Updated changelog action --- .github/workflows/changelog.yml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 396ce8e0..d1ccce57 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -21,12 +21,30 @@ jobs: token: ${{ secrets.CHANGELOG_KEY }} repository: pestphp/website path: pestphp-website + - name: Read package.json + id: package + uses: juliangruber/read-file-action@v1 + with: + path: ${{ env.home}}/CHANGELOG.md + - name: Add file headers + uses: DamianReeves/write-file-action@v1.0 + with: + path: ./CHANGELOG.md + contents: | + --- + title: Changelog + description: Changelog + extends: _layouts.documentation + section: content + --- + ${{ steps.package.outputs.content }} + write-mode: overwrite - name: Copy CHANGELOG to website repository run: cp CHANGELOG.md pestphp-website/source/docs/changelog.md - name: Create Pull Request uses: peter-evans/create-pull-request@v2 with: - token: ${{ secrets.CHANGELOG_KEY }} + token: ${{ secrets.CHANGELOG_KEY }} commit-message: Update changelog.md committer: GitHub Action author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> From 6437db7aa033319f7a3b26421fe69b2e39a1c916 Mon Sep 17 00:00:00 2001 From: Vaggelis Yfantis Date: Fri, 5 Jun 2020 06:18:18 +0300 Subject: [PATCH 02/32] Updated changelog action --- .github/workflows/changelog.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index d1ccce57..b606f1a0 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -25,7 +25,7 @@ jobs: id: package uses: juliangruber/read-file-action@v1 with: - path: ${{ env.home}}/CHANGELOG.md + path: ./CHANGELOG.md - name: Add file headers uses: DamianReeves/write-file-action@v1.0 with: From 6b7aa10e9147a7d997c4a112ef6765981593a0ca Mon Sep 17 00:00:00 2001 From: Vaggelis Yfantis Date: Fri, 5 Jun 2020 17:03:32 +0300 Subject: [PATCH 03/32] Update changelog.yml --- .github/workflows/changelog.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index b606f1a0..8a84d7f1 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -21,7 +21,7 @@ jobs: token: ${{ secrets.CHANGELOG_KEY }} repository: pestphp/website path: pestphp-website - - name: Read package.json + - name: Read CHANGELOG.md id: package uses: juliangruber/read-file-action@v1 with: @@ -45,8 +45,8 @@ jobs: uses: peter-evans/create-pull-request@v2 with: token: ${{ secrets.CHANGELOG_KEY }} - commit-message: Update changelog.md - committer: GitHub Action - author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> - title: 'Update changelog.md' - path: ./pestphp-website + commit-message: Update changelog.md + committer: GitHub Action + author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> + title: 'Update changelog.md' + path: ./pestphp-website From b0c964d4d9c527f251c30addaad4562e3341fef0 Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Thu, 28 May 2020 23:11:14 +0200 Subject: [PATCH 04/32] Don't use "reapath" in binary for cross-compatibility --- bin/pest | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/pest b/bin/pest index 9b66a2b6..5ff4eea1 100755 --- a/bin/pest +++ b/bin/pest @@ -1,6 +1,7 @@ #!/usr/bin/env php register(); + (new Provider())->register(); $rootPath = getcwd(); From 3d2c83a50135244c31224bb4e605e710f78da8f8 Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Thu, 28 May 2020 23:12:16 +0200 Subject: [PATCH 05/32] Make sure test targets are sanitized in a windows-compatible way --- src/PendingObjects/UsesCall.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/PendingObjects/UsesCall.php b/src/PendingObjects/UsesCall.php index d7cfc1f6..56205be8 100644 --- a/src/PendingObjects/UsesCall.php +++ b/src/PendingObjects/UsesCall.php @@ -59,7 +59,17 @@ final class UsesCall public function in(string ...$targets): void { $targets = array_map(function ($path): string { - return $path[0] === DIRECTORY_SEPARATOR + $startChar = DIRECTORY_SEPARATOR; + + if ('\\' === DIRECTORY_SEPARATOR) { + $path = (string) preg_replace_callback('~^(?P[a-z]+:\\\)~i', function ($match): string { + return strtolower($match['drive']); + }, $path); + + $startChar = strtolower((string) preg_replace('~^([a-z]+:\\\).*$~i', '$1', __DIR__)); + } + + return 0 === strpos($path, $startChar) ? $path : implode(DIRECTORY_SEPARATOR, [ dirname($this->filename), @@ -68,12 +78,12 @@ final class UsesCall }, $targets); $this->targets = array_map(function ($target): string { - $realTarget = realpath($target); - if ($realTarget === false) { - throw new InvalidUsesPath($target); + $isValid = is_dir($target) || file_exists($target); + if (!$isValid) { + throw new InvalidUsesPath($target . "\n"); } - return $realTarget; + return $target; }, $targets); } From 163de283381055f50fd8c30f1b58a7d74a4609bb Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Sat, 30 May 2020 00:10:48 +0200 Subject: [PATCH 06/32] Make sure PHP is called before calling pest as sub process --- tests/Visual/SingleTestOrDirectory.php | 2 +- tests/Visual/Success.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Visual/SingleTestOrDirectory.php b/tests/Visual/SingleTestOrDirectory.php index d86fc4c9..b2200ed8 100644 --- a/tests/Visual/SingleTestOrDirectory.php +++ b/tests/Visual/SingleTestOrDirectory.php @@ -3,7 +3,7 @@ use Symfony\Component\Process\Process; $run = function (string $target) { - $process = new Process(['./bin/pest', $target], dirname(__DIR__, 2)); + $process = new Process(['php', 'bin/pest', $target], dirname(__DIR__, 2)); $process->run(); diff --git a/tests/Visual/Success.php b/tests/Visual/Success.php index 70d11a52..d327beb5 100644 --- a/tests/Visual/Success.php +++ b/tests/Visual/Success.php @@ -9,7 +9,7 @@ test('visual snapshot of test suite on success', function () { ]); $output = function () use ($testsPath) { - $process = (new Symfony\Component\Process\Process(['./bin/pest'], dirname($testsPath), ['EXCLUDE' => 'integration', 'REBUILD_SNAPSHOTS' => false])); + $process = (new Symfony\Component\Process\Process(['php', 'bin/pest'], dirname($testsPath), ['EXCLUDE' => 'integration', 'REBUILD_SNAPSHOTS' => false])); $process->run(); From 24f85354e28ddf27f00ee23be8afc306a2ecc41b Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Sat, 30 May 2020 00:11:26 +0200 Subject: [PATCH 07/32] Normalize Windows dir name in TestCaseFactory --- src/Factories/TestCaseFactory.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index e36613ab..3f6e4f0d 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -158,10 +158,18 @@ final class TestCaseFactory */ public function makeClassFromFilename(string $filename): string { + if ('\\' === DIRECTORY_SEPARATOR) { + // In case Windows, strtolower drive name, like in UsesCall. + $filename = (string) preg_replace_callback('~^(?P[a-z]+:\\\)~i', function ($match): string { + return strtolower($match['drive']); + }, $filename); + } + $rootPath = TestSuite::getInstance()->rootPath; $relativePath = str_replace($rootPath . DIRECTORY_SEPARATOR, '', $filename); // Strip out any %-encoded octets. $relativePath = (string) preg_replace('|%[a-fA-F0-9][a-fA-F0-9]|', '', $relativePath); + $relativePath = str_replace('\\', '/', $relativePath); // Limit to A-Z, a-z, 0-9, '_', '-'. $relativePath = (string) preg_replace('/[^A-Za-z0-9.\/]/', '', $relativePath); From 926d8ecb8db5c2adeb8ec49d622404bf1bf990dd Mon Sep 17 00:00:00 2001 From: Dimitrios Karvounaris Date: Tue, 2 Jun 2020 17:11:30 +0200 Subject: [PATCH 08/32] Call binary as php sub process --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index f832fda5..af259d39 100644 --- a/composer.json +++ b/composer.json @@ -67,9 +67,9 @@ "lint": "rector process src && php-cs-fixer fix -v", "test:lint": "php-cs-fixer fix -v --dry-run && rector process src --dry-run", "test:types": "phpstan analyse --ansi", - "test:unit": "bin/pest --colors=always --exclude-group=integration", - "test:integration": "bin/pest --colors=always --group=integration", - "test:integration:snapshots": "REBUILD_SNAPSHOTS=true bin/pest --colors=always", + "test:unit": "php bin/pest --colors=always --exclude-group=integration", + "test:integration": "php bin/pest --colors=always --group=integration", + "test:integration:snapshots": "REBUILD_SNAPSHOTS=true php bin/pest --colors=always", "test": [ "@test:lint", "@test:types", From a0b80826315f7457011f01bd1281f597fe5b48f2 Mon Sep 17 00:00:00 2001 From: Dimitrios Karvounaris Date: Tue, 2 Jun 2020 18:01:43 +0200 Subject: [PATCH 09/32] Fix issue with case-insensitive windows paths --- src/Factories/TestCaseFactory.php | 1 + src/TestSuite.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index 3f6e4f0d..05859fdd 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -165,6 +165,7 @@ final class TestCaseFactory }, $filename); } + $filename = realpath($filename); $rootPath = TestSuite::getInstance()->rootPath; $relativePath = str_replace($rootPath . DIRECTORY_SEPARATOR, '', $filename); // Strip out any %-encoded octets. diff --git a/src/TestSuite.php b/src/TestSuite.php index 2d2bbfd8..e3d9f772 100644 --- a/src/TestSuite.php +++ b/src/TestSuite.php @@ -83,7 +83,7 @@ final class TestSuite $this->afterEach = new AfterEachRepository(); $this->afterAll = new AfterAllRepository(); - $this->rootPath = $rootPath; + $this->rootPath = realpath($rootPath); } /** From f6859eeb3b39ffebc2aa2cf2d95112db7e0cead4 Mon Sep 17 00:00:00 2001 From: Dimitrios Karvounaris Date: Tue, 2 Jun 2020 18:25:29 +0200 Subject: [PATCH 10/32] Launch pest as php subprocess --- tests/Visual/SingleTestOrDirectory.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Visual/SingleTestOrDirectory.php b/tests/Visual/SingleTestOrDirectory.php index b2200ed8..5cf1e6f3 100644 --- a/tests/Visual/SingleTestOrDirectory.php +++ b/tests/Visual/SingleTestOrDirectory.php @@ -33,6 +33,7 @@ EOF, $run('tests/Fixtures')); it('has ascii chars (decorated printer)', function () { $process = new Process([ + 'php', './bin/pest', 'tests/Fixtures/DirectoryWithTests/ExampleTest.php', ], dirname(__DIR__, 2)); @@ -49,6 +50,7 @@ EOF, $output); it('disable decorating printer when colors is set to never', function () { $process = new Process([ + 'php', './bin/pest', '--colors=never', 'tests/Fixtures/DirectoryWithTests/ExampleTest.php', From c05df43217936429cb5d0d4db58c7dc79c5e2ada Mon Sep 17 00:00:00 2001 From: Dimitrios Karvounaris Date: Tue, 2 Jun 2020 18:29:50 +0200 Subject: [PATCH 11/32] Compare lines without involving linebreaks Fixes tests failing under Windows environments for any linebreak character differences --- .../DirectoryWithTests/ExampleTest.php | 2 +- tests/Fixtures/ExampleTest.php | 2 +- tests/Visual/SingleTestOrDirectory.php | 43 +++++++------------ 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/tests/Fixtures/DirectoryWithTests/ExampleTest.php b/tests/Fixtures/DirectoryWithTests/ExampleTest.php index 8553ad34..81ce02ff 100644 --- a/tests/Fixtures/DirectoryWithTests/ExampleTest.php +++ b/tests/Fixtures/DirectoryWithTests/ExampleTest.php @@ -1,3 +1,3 @@ assertTrue(true); +it('example 1')->assertTrue(true); diff --git a/tests/Fixtures/ExampleTest.php b/tests/Fixtures/ExampleTest.php index 8553ad34..a2704020 100644 --- a/tests/Fixtures/ExampleTest.php +++ b/tests/Fixtures/ExampleTest.php @@ -1,3 +1,3 @@ assertTrue(true); +it('example 2')->assertTrue(true); diff --git a/tests/Visual/SingleTestOrDirectory.php b/tests/Visual/SingleTestOrDirectory.php index 5cf1e6f3..40ab399c 100644 --- a/tests/Visual/SingleTestOrDirectory.php +++ b/tests/Visual/SingleTestOrDirectory.php @@ -11,24 +11,19 @@ $run = function (string $target) { }; test('allows to run a single test', function () use ($run) { - assertStringContainsString(<<run(); $output = $process->getOutput(); - assertStringContainsString(<<run(); $output = $process->getOutput(); - assertStringContainsString(<< Date: Tue, 2 Jun 2020 18:33:53 +0200 Subject: [PATCH 12/32] in() does not handle absolute paths under Windows This fixes plugins to be included incorrectly under Windows --- src/PendingObjects/UsesCall.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PendingObjects/UsesCall.php b/src/PendingObjects/UsesCall.php index 56205be8..4523dab5 100644 --- a/src/PendingObjects/UsesCall.php +++ b/src/PendingObjects/UsesCall.php @@ -61,7 +61,7 @@ final class UsesCall $targets = array_map(function ($path): string { $startChar = DIRECTORY_SEPARATOR; - if ('\\' === DIRECTORY_SEPARATOR) { + if ('\\' === DIRECTORY_SEPARATOR || preg_match('~\A[A-Z]:(?![^/\\\\])~i', $path) > 0) { $path = (string) preg_replace_callback('~^(?P[a-z]+:\\\)~i', function ($match): string { return strtolower($match['drive']); }, $path); From 8a42d405069d2abc3ee0dcb3d856250dc1d223ac Mon Sep 17 00:00:00 2001 From: Dimitrios Karvounaris Date: Tue, 2 Jun 2020 18:58:16 +0200 Subject: [PATCH 13/32] traits from Autoload.php not loading on Windows Windows requires realpath() so the case of the paths and filenames are always identical --- src/PendingObjects/UsesCall.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PendingObjects/UsesCall.php b/src/PendingObjects/UsesCall.php index 4523dab5..142c14a3 100644 --- a/src/PendingObjects/UsesCall.php +++ b/src/PendingObjects/UsesCall.php @@ -83,7 +83,7 @@ final class UsesCall throw new InvalidUsesPath($target . "\n"); } - return $target; + return realpath($target); }, $targets); } From 0d198f589d2482b8d57ce2a7ecf3fe2fa1d9f090 Mon Sep 17 00:00:00 2001 From: Dimitrios Karvounaris Date: Tue, 2 Jun 2020 19:30:25 +0200 Subject: [PATCH 14/32] Fix changes in success snapshot --- tests/.snapshots/success.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index e34ef134..1231d8a8 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -81,10 +81,10 @@ ✓ higher order message test PASS Tests\Fixtures\DirectoryWithTests\ExampleTest - ✓ it example + ✓ it example 1 PASS Tests\Fixtures\ExampleTest - ✓ it example + ✓ it example 2 PASS Tests\PHPUnit\CustomTestCase\UsesPerDirectory ✓ closure was bound to custom test case From fe11140fc24e2cdb6039ce652b019d7477fc5ee0 Mon Sep 17 00:00:00 2001 From: Dimitrios Karvounaris Date: Tue, 2 Jun 2020 19:43:06 +0200 Subject: [PATCH 15/32] Adding dom extension to CI --- .github/workflows/formats.yml | 2 +- .github/workflows/tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/formats.yml b/.github/workflows/formats.yml index f3598b3b..bbdd5771 100644 --- a/.github/workflows/formats.yml +++ b/.github/workflows/formats.yml @@ -30,7 +30,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: mbstring, zip + extensions: dom, mbstring, zip tools: prestissimo coverage: pcov diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 10188221..8c600d9d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -29,7 +29,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: mbstring, zip + extensions: dom, mbstring, zip coverage: none - name: Install Composer dependencies From d35320c6971deaf7e2ba477b08b44b3b3e2f4114 Mon Sep 17 00:00:00 2001 From: Dimitrios Karvounaris Date: Fri, 5 Jun 2020 17:25:53 +0200 Subject: [PATCH 16/32] Compare filename correctly on all OS --- src/Support/Backtrace.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Support/Backtrace.php b/src/Support/Backtrace.php index 0347932f..0e87e849 100644 --- a/src/Support/Backtrace.php +++ b/src/Support/Backtrace.php @@ -24,7 +24,7 @@ final class Backtrace $current = null; foreach (debug_backtrace() as $trace) { - if (Str::endsWith($trace[self::FILE], 'vendor/phpunit/phpunit/src/Util/FileLoader.php')) { + if (Str::endsWith($trace[self::FILE], realpath('vendor/phpunit/phpunit/src/Util/FileLoader.php'))) { break; } From 6e18912ea6f1083cf9c9e361ce6d3ab97c28c7b3 Mon Sep 17 00:00:00 2001 From: Dimitrios Karvounaris Date: Fri, 5 Jun 2020 17:38:59 +0200 Subject: [PATCH 17/32] Test to check if the full test path is shown --- tests/Visual/SingleTestOrDirectory.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/Visual/SingleTestOrDirectory.php b/tests/Visual/SingleTestOrDirectory.php index 40ab399c..6298f98e 100644 --- a/tests/Visual/SingleTestOrDirectory.php +++ b/tests/Visual/SingleTestOrDirectory.php @@ -10,6 +10,11 @@ $run = function (string $target) { return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput()); }; +test('output contains full test path', function() use ($run) { + $output = $run('tests/Fixtures/DirectoryWithTests/ExampleTest.php'); + assertStringContainsString(' PASS Tests\Fixtures\DirectoryWithTests\ExampleTest', $output); +}); + test('allows to run a single test', function () use ($run) { $output = $run('tests/Fixtures/DirectoryWithTests/ExampleTest.php'); assertStringContainsString(' PASS Tests\Fixtures\DirectoryWithTests\ExampleTest', $output); From 9bdd2540079f71844973fc3245210996a2f2b9ba Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 5 Jun 2020 18:14:27 +0200 Subject: [PATCH 18/32] tests: adapts to collision beta 2 --- tests/.snapshots/success.txt | 18 +++++++++--------- .../{PhpunitTest.php => ExecutedTest.php} | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) rename tests/PHPUnit/CustomTestCase/{PhpunitTest.php => ExecutedTest.php} (67%) diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index e34ef134..1a8a5130 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -1,5 +1,5 @@ - PASS Tests\CustomTestCase\PhpunitTest + PASS Tests\CustomTestCase\ExecutedTest ✓ that gets executed PASS Tests\Features\AfterAll @@ -24,7 +24,7 @@ ✓ it sets arrays ✓ it gets bound to test case object with ('a') ✓ it gets bound to test case object with ('b') - ✓ it truncates the description with (' fooo fooo fooo fooo fooo fooo fooo f...oo fooo') + ✓ it truncates the description with ('FoooFoooFoooFoooFoooFoooFoooF...ooFooo') ✓ lazy datasets with (1) ✓ lazy datasets with (2) ✓ lazy datasets did the job right @@ -40,10 +40,10 @@ ✓ eager wrapped registered datasets with (1) ✓ eager wrapped registered datasets with (2) ✓ eager registered wrapped datasets did the job right - ✓ lazy named datasets with ( bar object (...)) + ✓ lazy named datasets with (Bar Object (...)) PASS Tests\Features\Exceptions - ✓ it gives access the the underlying expect exception + ✓ it gives access the the underlying expectException ✓ it catch exceptions ✓ it catch exceptions and messages @@ -64,8 +64,8 @@ ✓ it has bar PASS Tests\Features\PendingHigherOrderTests - ✓ get 'foo' → get 'bar' → assert true true - ✓ get 'foo' → assert true true + ✓ get 'foo' → get 'bar' → assertTrue true + ✓ get 'foo' → assertTrue true WARN Tests\Features\Skip ✓ it do not skips @@ -87,10 +87,10 @@ ✓ it example PASS Tests\PHPUnit\CustomTestCase\UsesPerDirectory - ✓ closure was bound to custom test case + ✓ closure was bound to CustomTestCase PASS Tests\PHPUnit\CustomTestCaseInSubFolders\SubFolder\SubFolder\UsesPerSubDirectory - ✓ closure was bound to custom test case + ✓ closure was bound to CustomTestCase PASS Tests\PHPUnit\CustomTestCaseInSubFolders\SubFolder2\UsesPerFile ✓ custom traits can be used @@ -135,4 +135,4 @@ s visual snapshot of test suite on success Tests: 6 skipped, 71 passed - Time: 2.89s + Time: 2.96s diff --git a/tests/PHPUnit/CustomTestCase/PhpunitTest.php b/tests/PHPUnit/CustomTestCase/ExecutedTest.php similarity index 67% rename from tests/PHPUnit/CustomTestCase/PhpunitTest.php rename to tests/PHPUnit/CustomTestCase/ExecutedTest.php index 233da16d..71a32980 100644 --- a/tests/PHPUnit/CustomTestCase/PhpunitTest.php +++ b/tests/PHPUnit/CustomTestCase/ExecutedTest.php @@ -7,7 +7,7 @@ namespace Tests\CustomTestCase; use function PHPUnit\Framework\assertTrue; use PHPUnit\Framework\TestCase; -class PhpunitTest extends TestCase +class ExecutedTest extends TestCase { public static $executed = false; @@ -16,8 +16,8 @@ class PhpunitTest extends TestCase { self::$executed = true; - $this->assertTrue(true); + assertTrue(true); } } -// register_shutdown_function(fn () => assertTrue(PhpunitTest::$executed)); +// register_shutdown_function(fn () => assertTrue(ExecutedTest::$executed)); From f5f717f1ad46db6791a2e213cda53b0d4d9dad6a Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 5 Jun 2020 18:18:06 +0200 Subject: [PATCH 19/32] chore: requires more than collision beta1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f832fda5..44aaf9ad 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ ], "require": { "php": "^7.3", - "nunomaduro/collision": "^5.0", + "nunomaduro/collision": "^5.0.0-BETA2", "pestphp/pest-plugin": "dev-master", "pestphp/pest-plugin-coverage": "dev-master", "phpunit/phpunit": "^9.1.4", From dff9bbc1349b8600cd93d48fad7b36266020a06e Mon Sep 17 00:00:00 2001 From: Dimitrios Karvounaris Date: Fri, 5 Jun 2020 18:24:03 +0200 Subject: [PATCH 20/32] Fix file paths not being used properly basename() will strip full path information on some systems. What is needed is to use both dirname() & basename() on paths, as recognized by all systems, and only afterwards do any replacements. --- src/Factories/TestCaseFactory.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index 05859fdd..022c0d1a 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -165,18 +165,18 @@ final class TestCaseFactory }, $filename); } - $filename = realpath($filename); + $filename = realpath($filename); $rootPath = TestSuite::getInstance()->rootPath; $relativePath = str_replace($rootPath . DIRECTORY_SEPARATOR, '', $filename); + $relativePath = dirname(ucfirst($relativePath)) . DIRECTORY_SEPARATOR . basename($relativePath, '.php'); + $relativePath = str_replace(DIRECTORY_SEPARATOR, '\\', $relativePath); + // Strip out any %-encoded octets. $relativePath = (string) preg_replace('|%[a-fA-F0-9][a-fA-F0-9]|', '', $relativePath); - $relativePath = str_replace('\\', '/', $relativePath); - // Limit to A-Z, a-z, 0-9, '_', '-'. - $relativePath = (string) preg_replace('/[^A-Za-z0-9.\/]/', '', $relativePath); - - $classFQN = 'P\\' . basename(ucfirst(str_replace(DIRECTORY_SEPARATOR, '\\', $relativePath)), '.php'); + $relativePath = (string) preg_replace('/[^A-Za-z0-9.\\\]/', '', $relativePath); + $classFQN = 'P\\' . $relativePath; if (class_exists($classFQN)) { return $classFQN; } From ffa3f1d6836e586d7fbd8be3a92d7cc3f0f54cdc Mon Sep 17 00:00:00 2001 From: Dimitrios Karvounaris Date: Fri, 5 Jun 2020 18:26:52 +0200 Subject: [PATCH 21/32] Skip visual snapshot test on Windows --- tests/Visual/Success.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Visual/Success.php b/tests/Visual/Success.php index d327beb5..f8678973 100644 --- a/tests/Visual/Success.php +++ b/tests/Visual/Success.php @@ -24,4 +24,5 @@ test('visual snapshot of test suite on success', function () { array_pop($output); assertStringContainsString(implode("\n", $output), file_get_contents($snapshot)); } -})->skip(!getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE')); +})->skip(!getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE')) + ->skip(PHP_OS_FAMILY === 'Windows', 'File sorting algorithm causes different test order on Windows'); From 38584bec935a74886a989538478aa78b7a07a90d Mon Sep 17 00:00:00 2001 From: Dimitrios Karvounaris Date: Fri, 5 Jun 2020 18:29:57 +0200 Subject: [PATCH 22/32] Updating success.txt snapshot --- tests/.snapshots/success.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 1231d8a8..eb00d006 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -126,6 +126,7 @@ ✓ it does not allow to add the same test description twice PASS Tests\Visual\SingleTestOrDirectory + ✓ output contains full test path ✓ allows to run a single test ✓ allows to run a directory ✓ it has ascii chars (decorated printer) @@ -134,5 +135,5 @@ WARN Tests\Visual\Success s visual snapshot of test suite on success - Tests: 6 skipped, 71 passed + Tests: 6 skipped, 72 passed Time: 2.89s From d24830121e1efea2e3e5ccda9f3dc89ab3b6d007 Mon Sep 17 00:00:00 2001 From: Dimitrios Karvounaris Date: Fri, 5 Jun 2020 19:24:56 +0200 Subject: [PATCH 23/32] Reverting changes from c05df432 --- tests/.snapshots/success.txt | 3 +- tests/Visual/SingleTestOrDirectory.php | 48 +++++++++++++++----------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index eb00d006..1231d8a8 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -126,7 +126,6 @@ ✓ it does not allow to add the same test description twice PASS Tests\Visual\SingleTestOrDirectory - ✓ output contains full test path ✓ allows to run a single test ✓ allows to run a directory ✓ it has ascii chars (decorated printer) @@ -135,5 +134,5 @@ WARN Tests\Visual\Success s visual snapshot of test suite on success - Tests: 6 skipped, 72 passed + Tests: 6 skipped, 71 passed Time: 2.89s diff --git a/tests/Visual/SingleTestOrDirectory.php b/tests/Visual/SingleTestOrDirectory.php index 6298f98e..8f287ddd 100644 --- a/tests/Visual/SingleTestOrDirectory.php +++ b/tests/Visual/SingleTestOrDirectory.php @@ -10,25 +10,25 @@ $run = function (string $target) { return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput()); }; -test('output contains full test path', function() use ($run) { - $output = $run('tests/Fixtures/DirectoryWithTests/ExampleTest.php'); - assertStringContainsString(' PASS Tests\Fixtures\DirectoryWithTests\ExampleTest', $output); -}); - test('allows to run a single test', function () use ($run) { - $output = $run('tests/Fixtures/DirectoryWithTests/ExampleTest.php'); - assertStringContainsString(' PASS Tests\Fixtures\DirectoryWithTests\ExampleTest', $output); - assertStringContainsString(' ✓ it example 1', $output); - assertStringContainsString(' Tests: 1 passed', $output); + assertStringContainsString(<<run(); $output = $process->getOutput(); - assertStringContainsString(" \e[30;42;1m PASS \e[39;49;22m\e[39m Tests\Fixtures\DirectoryWithTests\ExampleTest\e[39m", $output); - assertStringContainsString(" \e[32;1m✓\e[39;22m\e[39m \e[2mit example 1\e[22m\e[39m", $output); - assertStringContainsString(" \e[37;1mTests: \e[39;22m\e[32;1m1 passed\e[39;22m", $output); + assertStringContainsString(<<run(); $output = $process->getOutput(); - assertStringContainsString(' PASS Tests\Fixtures\DirectoryWithTests\ExampleTest', $output); - assertStringContainsString(" ✓ \e[2mit example 1\e[22m", $output); - assertStringContainsString(' Tests: 1 passed', $output); + assertStringContainsString(<< Date: Fri, 5 Jun 2020 19:29:43 +0200 Subject: [PATCH 24/32] // missing change --- tests/Visual/SingleTestOrDirectory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Visual/SingleTestOrDirectory.php b/tests/Visual/SingleTestOrDirectory.php index 8f287ddd..cefb4a7e 100644 --- a/tests/Visual/SingleTestOrDirectory.php +++ b/tests/Visual/SingleTestOrDirectory.php @@ -42,7 +42,7 @@ it('has ascii chars (decorated printer)', function () { $output = $process->getOutput(); assertStringContainsString(<< Date: Fri, 5 Jun 2020 19:30:35 +0200 Subject: [PATCH 25/32] // unnecessary linebreak --- src/PendingObjects/UsesCall.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PendingObjects/UsesCall.php b/src/PendingObjects/UsesCall.php index 142c14a3..52d81b74 100644 --- a/src/PendingObjects/UsesCall.php +++ b/src/PendingObjects/UsesCall.php @@ -80,7 +80,7 @@ final class UsesCall $this->targets = array_map(function ($target): string { $isValid = is_dir($target) || file_exists($target); if (!$isValid) { - throw new InvalidUsesPath($target . "\n"); + throw new InvalidUsesPath($target); } return realpath($target); From 40a5d067eca4a7ab78f4701b12c22e590fd02858 Mon Sep 17 00:00:00 2001 From: Dimitrios Karvounaris Date: Fri, 5 Jun 2020 19:35:13 +0200 Subject: [PATCH 26/32] // fixing type checks --- src/Factories/TestCaseFactory.php | 2 +- src/PendingObjects/UsesCall.php | 2 +- src/Support/Backtrace.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index 022c0d1a..49c6eaad 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -165,7 +165,7 @@ final class TestCaseFactory }, $filename); } - $filename = realpath($filename); + $filename = (string) realpath($filename); $rootPath = TestSuite::getInstance()->rootPath; $relativePath = str_replace($rootPath . DIRECTORY_SEPARATOR, '', $filename); $relativePath = dirname(ucfirst($relativePath)) . DIRECTORY_SEPARATOR . basename($relativePath, '.php'); diff --git a/src/PendingObjects/UsesCall.php b/src/PendingObjects/UsesCall.php index 52d81b74..f9418fd5 100644 --- a/src/PendingObjects/UsesCall.php +++ b/src/PendingObjects/UsesCall.php @@ -83,7 +83,7 @@ final class UsesCall throw new InvalidUsesPath($target); } - return realpath($target); + return (string) realpath($target); }, $targets); } diff --git a/src/Support/Backtrace.php b/src/Support/Backtrace.php index 0e87e849..cf90ab03 100644 --- a/src/Support/Backtrace.php +++ b/src/Support/Backtrace.php @@ -24,7 +24,7 @@ final class Backtrace $current = null; foreach (debug_backtrace() as $trace) { - if (Str::endsWith($trace[self::FILE], realpath('vendor/phpunit/phpunit/src/Util/FileLoader.php'))) { + if (Str::endsWith($trace[self::FILE], (string) realpath('vendor/phpunit/phpunit/src/Util/FileLoader.php'))) { break; } From b93cd724c1bcadcebf68f7648a820902fcc00eff Mon Sep 17 00:00:00 2001 From: Dimitrios Karvounaris Date: Fri, 5 Jun 2020 19:37:53 +0200 Subject: [PATCH 27/32] // tiny fix --- tests/Visual/SingleTestOrDirectory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Visual/SingleTestOrDirectory.php b/tests/Visual/SingleTestOrDirectory.php index cefb4a7e..10ea1c1b 100644 --- a/tests/Visual/SingleTestOrDirectory.php +++ b/tests/Visual/SingleTestOrDirectory.php @@ -60,7 +60,7 @@ it('disable decorating printer when colors is set to never', function () { assertStringContainsString(<< Date: Fri, 5 Jun 2020 19:42:07 +0200 Subject: [PATCH 28/32] // fixing once more, wrong code pasted :( --- tests/Visual/SingleTestOrDirectory.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Visual/SingleTestOrDirectory.php b/tests/Visual/SingleTestOrDirectory.php index 10ea1c1b..52ccf3e6 100644 --- a/tests/Visual/SingleTestOrDirectory.php +++ b/tests/Visual/SingleTestOrDirectory.php @@ -59,9 +59,9 @@ it('disable decorating printer when colors is set to never', function () { $output = $process->getOutput(); assertStringContainsString(<< Date: Fri, 5 Jun 2020 19:45:58 +0200 Subject: [PATCH 29/32] // fixing type check --- src/TestSuite.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TestSuite.php b/src/TestSuite.php index e3d9f772..b9c232b2 100644 --- a/src/TestSuite.php +++ b/src/TestSuite.php @@ -83,7 +83,7 @@ final class TestSuite $this->afterEach = new AfterEachRepository(); $this->afterAll = new AfterAllRepository(); - $this->rootPath = realpath($rootPath); + $this->rootPath = (string) realpath($rootPath); } /** From a13c19cc29d453e1bf7766f2e87dd6c0ea3d9dae Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 5 Jun 2020 20:04:10 +0200 Subject: [PATCH 30/32] chore: fixes deps --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 1c29cfa7..2b7803ec 100644 --- a/composer.json +++ b/composer.json @@ -19,8 +19,8 @@ "require": { "php": "^7.3", "nunomaduro/collision": "^5.0.0-BETA2", - "pestphp/pest-plugin": "dev-master", - "pestphp/pest-plugin-coverage": "dev-master", + "pestphp/pest-plugin": "^0.2", + "pestphp/pest-plugin-coverage": "^0.2", "phpunit/phpunit": "^9.1.4", "sebastian/environment": "^5.1" }, From afbbc359843adbd37296fa0d865e8b197105cbd3 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 5 Jun 2020 20:49:14 +0200 Subject: [PATCH 31/32] tests: refactor visual testing --- .../.snapshots/allows-to-run-a-directory.txt | 7 ++ .../allows-to-run-a-single-test.txt | 4 ++ .../.snapshots/disable-decorating-printer.txt | 5 ++ tests/.snapshots/has-ascii-chars.txt | 5 ++ tests/.snapshots/success.txt | 4 +- tests/Visual/SingleTestOrDirectory.php | 67 ++++++++----------- tests/Visual/foo.txt | 6 ++ 7 files changed, 56 insertions(+), 42 deletions(-) create mode 100644 tests/.snapshots/allows-to-run-a-directory.txt create mode 100644 tests/.snapshots/allows-to-run-a-single-test.txt create mode 100644 tests/.snapshots/disable-decorating-printer.txt create mode 100644 tests/.snapshots/has-ascii-chars.txt create mode 100644 tests/Visual/foo.txt diff --git a/tests/.snapshots/allows-to-run-a-directory.txt b/tests/.snapshots/allows-to-run-a-directory.txt new file mode 100644 index 00000000..aaf96389 --- /dev/null +++ b/tests/.snapshots/allows-to-run-a-directory.txt @@ -0,0 +1,7 @@ + PASS Tests\Fixtures\DirectoryWithTests\ExampleTest + ✓ it example 1 + + PASS Tests\Fixtures\ExampleTest + ✓ it example 2 + + Tests: 2 passed diff --git a/tests/.snapshots/allows-to-run-a-single-test.txt b/tests/.snapshots/allows-to-run-a-single-test.txt new file mode 100644 index 00000000..0812d708 --- /dev/null +++ b/tests/.snapshots/allows-to-run-a-single-test.txt @@ -0,0 +1,4 @@ + PASS Tests\Fixtures\DirectoryWithTests\ExampleTest + ✓ it example 1 + + Tests: 1 passed diff --git a/tests/.snapshots/disable-decorating-printer.txt b/tests/.snapshots/disable-decorating-printer.txt new file mode 100644 index 00000000..dc804c2f --- /dev/null +++ b/tests/.snapshots/disable-decorating-printer.txt @@ -0,0 +1,5 @@ + + PASS Tests\Fixtures\DirectoryWithTests\ExampleTest + ✓ it example 1 + + Tests: 1 passed diff --git a/tests/.snapshots/has-ascii-chars.txt b/tests/.snapshots/has-ascii-chars.txt new file mode 100644 index 00000000..403f6ac7 --- /dev/null +++ b/tests/.snapshots/has-ascii-chars.txt @@ -0,0 +1,5 @@ + +  PASS  Tests\Fixtures\DirectoryWithTests\ExampleTest + ✓ it example 1 + + Tests: 1 passed diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 82705172..294814f2 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -128,11 +128,11 @@ PASS Tests\Visual\SingleTestOrDirectory ✓ allows to run a single test ✓ allows to run a directory - ✓ it has ascii chars (decorated printer) + ✓ it has ascii chars ✓ it disable decorating printer when colors is set to never WARN Tests\Visual\Success s visual snapshot of test suite on success Tests: 6 skipped, 71 passed - Time: 2.89s + Time: 2.87s diff --git a/tests/Visual/SingleTestOrDirectory.php b/tests/Visual/SingleTestOrDirectory.php index 52ccf3e6..70222546 100644 --- a/tests/Visual/SingleTestOrDirectory.php +++ b/tests/Visual/SingleTestOrDirectory.php @@ -2,53 +2,42 @@ use Symfony\Component\Process\Process; -$run = function (string $target) { +$run = function (string $target, $decorated = false) { $process = new Process(['php', 'bin/pest', $target], dirname(__DIR__, 2)); $process->run(); - return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput()); + return $decorated ? $process->getOutput() : preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput()); }; -test('allows to run a single test', function () use ($run) { - assertStringContainsString(<< file_get_contents(implode(DIRECTORY_SEPARATOR, [ + $testsPath, + '.snapshots', + "$name.txt", +])); - Tests: 1 passed -EOF, $run('tests/Fixtures/DirectoryWithTests/ExampleTest.php')); +test('allows to run a single test', function () use ($run, $snapshot) { + assertStringContainsString( + $snapshot('allows-to-run-a-single-test'), + $run('tests/Fixtures/DirectoryWithTests/ExampleTest.php')); }); -test('allows to run a directory', function () use ($run) { - assertStringContainsString(<<run(); - $output = $process->getOutput(); - assertStringContainsString(<<run(); $output = $process->getOutput(); - assertStringContainsString(<< Date: Fri, 5 Jun 2020 20:51:57 +0200 Subject: [PATCH 32/32] tests: fixes testing running in php 7.3 --- tests/Visual/SingleTestOrDirectory.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/Visual/SingleTestOrDirectory.php b/tests/Visual/SingleTestOrDirectory.php index 70222546..261318c3 100644 --- a/tests/Visual/SingleTestOrDirectory.php +++ b/tests/Visual/SingleTestOrDirectory.php @@ -10,12 +10,15 @@ $run = function (string $target, $decorated = false) { return $decorated ? $process->getOutput() : preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput()); }; -$testsPath = dirname(__DIR__); -$snapshot = fn (string $name) => file_get_contents(implode(DIRECTORY_SEPARATOR, [ - $testsPath, - '.snapshots', - "$name.txt", -])); +$snapshot = function ($name) { + $testsPath = dirname(__DIR__); + + return file_get_contents(implode(DIRECTORY_SEPARATOR, [ + $testsPath, + '.snapshots', + "$name.txt", + ])); +}; test('allows to run a single test', function () use ($run, $snapshot) { assertStringContainsString(