From 40766f9275c1c8ea6d9aa0b946efabd5ef1164ed Mon Sep 17 00:00:00 2001 From: Francisco Kraefft Date: Wed, 17 Jun 2020 09:59:46 -0300 Subject: [PATCH 1/4] Fix in Test Repository use method. --- src/Repositories/TestRepository.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Repositories/TestRepository.php b/src/Repositories/TestRepository.php index 3f4cb99e6..2af718f2e 100644 --- a/src/Repositories/TestRepository.php +++ b/src/Repositories/TestRepository.php @@ -4,13 +4,13 @@ namespace Pest\Repositories; +use Pest\TestSuite; +use Pest\Support\Str; +use Pest\Factories\TestCaseFactory; use Pest\Exceptions\ShouldNotHappen; use Pest\Exceptions\TestAlreadyExist; use Pest\Exceptions\TestCaseAlreadyInUse; use Pest\Exceptions\TestCaseClassOrTraitNotFound; -use Pest\Factories\TestCaseFactory; -use Pest\Support\Str; -use Pest\TestSuite; /** * @internal @@ -104,7 +104,14 @@ public function use(array $classOrTraits, array $groups, array $paths): void } foreach ($paths as $path) { - $this->uses[$path] = [$classOrTraits, $groups]; + if (array_key_exists($path, $this->uses)) { + $this->uses[$path] = [ + array_merge($this->uses[$path][0], $classOrTraits), + array_merge($this->uses[$path][1], $groups) + ]; + } else { + $this->uses[$path] = [$classOrTraits, $groups]; + } } } From e9e72d607e90d57b4e582e28e30ec07f1d726054 Mon Sep 17 00:00:00 2001 From: Francisco Kraefft Date: Wed, 17 Jun 2020 11:55:48 -0300 Subject: [PATCH 2/4] vscode folder added to gitignore. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 69a8e2d8f..55be80190 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ coverage.xml .temp/coverage.php *.swp *.swo +.vscode/ \ No newline at end of file From ae7991c7e975db7d23e458bc4619ee5e86a0d07a Mon Sep 17 00:00:00 2001 From: Francisco Kraefft Date: Wed, 17 Jun 2020 11:56:24 -0300 Subject: [PATCH 3/4] Style fixes. --- src/Repositories/TestRepository.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Repositories/TestRepository.php b/src/Repositories/TestRepository.php index 2af718f2e..092424480 100644 --- a/src/Repositories/TestRepository.php +++ b/src/Repositories/TestRepository.php @@ -4,13 +4,13 @@ namespace Pest\Repositories; -use Pest\TestSuite; -use Pest\Support\Str; -use Pest\Factories\TestCaseFactory; use Pest\Exceptions\ShouldNotHappen; use Pest\Exceptions\TestAlreadyExist; use Pest\Exceptions\TestCaseAlreadyInUse; use Pest\Exceptions\TestCaseClassOrTraitNotFound; +use Pest\Factories\TestCaseFactory; +use Pest\Support\Str; +use Pest\TestSuite; /** * @internal @@ -107,7 +107,7 @@ public function use(array $classOrTraits, array $groups, array $paths): void if (array_key_exists($path, $this->uses)) { $this->uses[$path] = [ array_merge($this->uses[$path][0], $classOrTraits), - array_merge($this->uses[$path][1], $groups) + array_merge($this->uses[$path][1], $groups), ]; } else { $this->uses[$path] = [$classOrTraits, $groups]; From accd4eb7b4ee38d6dfba48e03f41c976dc6274aa Mon Sep 17 00:00:00 2001 From: Francisco Kraefft Date: Wed, 17 Jun 2020 11:57:08 -0300 Subject: [PATCH 4/4] Multiple global uses registered in the same path test added. --- tests/.snapshots/success.txt | 5 +++-- tests/Autoload.php | 9 +++++++++ tests/Plugins/Traits.php | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 8e3f32e03..961a01809 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -101,6 +101,7 @@ PASS Tests\Plugins\Traits ✓ it allows global uses + ✓ it allows multiple global uses registered in the same path PASS Tests\Unit\Actions\AddsDefaults ✓ it sets defaults @@ -143,5 +144,5 @@ WARN Tests\Visual\Success s visual snapshot of test suite on success - Tests: 6 skipped, 78 passed - Time: 3.09s + Tests: 6 skipped, 79 passed + Time: 3.44s diff --git a/tests/Autoload.php b/tests/Autoload.php index 1945c6432..9283dbadc 100644 --- a/tests/Autoload.php +++ b/tests/Autoload.php @@ -12,4 +12,13 @@ public function assertPluginTraitGotRegistered(): void } } +trait SecondPluginTrait +{ + public function assertSecondPluginTraitGotRegistered(): void + { + assertTrue(true); + } +} + Pest\Plugin::uses(PluginTrait::class); +Pest\Plugin::uses(SecondPluginTrait::class); diff --git a/tests/Plugins/Traits.php b/tests/Plugins/Traits.php index bd318c284..47573baa4 100644 --- a/tests/Plugins/Traits.php +++ b/tests/Plugins/Traits.php @@ -1,3 +1,5 @@ assertPluginTraitGotRegistered(); + +it('allows multiple global uses registered in the same path')->assertSecondPluginTraitGotRegistered();