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 diff --git a/src/Repositories/TestRepository.php b/src/Repositories/TestRepository.php index 3f4cb99e6..092424480 100644 --- a/src/Repositories/TestRepository.php +++ b/src/Repositories/TestRepository.php @@ -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]; + } } } 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();