Skip to content

Commit c77c643

Browse files
committed
feat: don't force using Factories trait when PHPUnit extension is enabled
1 parent ffdb019 commit c77c643

14 files changed

+118
-12
lines changed

.github/workflows/phpunit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ jobs:
202202
strategy:
203203
fail-fast: false
204204
matrix:
205-
php: [ 8.1, 8.2, 8.3, 8.4 ]
205+
php: [ 8.2, 8.3, 8.4 ]
206206
steps:
207207
- name: Checkout code
208208
uses: actions/checkout@v3

src/Configuration.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ public static function instance(): self
119119
throw new FoundryNotBooted();
120120
}
121121

122-
FactoriesTraitNotUsed::throwIfComingFromKernelTestCaseWithoutFactoriesTrait();
122+
if (!FoundryExtension::isEnabled()) {
123+
FactoriesTraitNotUsed::throwIfComingFromKernelTestCaseWithoutFactoriesTrait();
124+
}
123125

124126
return \is_callable(self::$instance) ? (self::$instance)() : self::$instance;
125127
}

src/Test/Factories.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ trait Factories
3232
#[Before(5)]
3333
public function _beforeHook(): void
3434
{
35-
$this->_loadDataProvidedProxies(); // todo remove
36-
37-
if (FoundryExtension::isEnabled()) {
38-
trigger_deprecation('zenstruck/foundry', '2.7', sprintf('Trait %s is deprecated and will be removed in Foundry 3.', Factories::class));
35+
if (!FoundryExtension::isEnabled()) {
36+
$this->_bootFoundry();
3937

4038
return;
4139
}
4240

43-
$this->_bootFoundry();
41+
trigger_deprecation('zenstruck/foundry', '2.7', sprintf('Trait %s is deprecated and will be removed in Foundry 3.', Factories::class));
42+
43+
$this->_loadDataProvidedProxies(); // todo remove
4444
}
4545

4646
/**

tests/Integration/ForceFactoriesTraitUsage/AnotherBaseTestCase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
abstract class AnotherBaseTestCase extends KernelTestCase
2020
{
21+
use SkipWithPHPUnitExtension;
22+
2123
// @phpstan-ignore missingType.generics
2224
public function useProxyClass(Proxy $proxy): void
2325
{

tests/Integration/ForceFactoriesTraitUsage/KernelTestCaseWithBothTraitsInWrongOrderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#[RequiresPhpunit('>=11.0')]
2424
final class KernelTestCaseWithBothTraitsInWrongOrderTest extends KernelTestCase
2525
{
26-
use Factories, ResetDatabase;
26+
use Factories, ResetDatabase, SkipWithPHPUnitExtension;
2727

2828
#[Test]
2929
public function should_not_throw(): void

tests/Integration/ForceFactoriesTraitUsage/KernelTestCaseWithBothTraitsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#[RequiresPhpunit('>=11.0')]
2424
final class KernelTestCaseWithBothTraitsTest extends KernelTestCase
2525
{
26-
use Factories, ResetDatabase;
26+
use Factories, ResetDatabase, SkipWithPHPUnitExtension;
2727

2828
#[Test]
2929
public function should_not_throw(): void

tests/Integration/ForceFactoriesTraitUsage/KernelTestCaseWithFactoriesTraitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#[RequiresPhpunit('>=11.0')]
2323
final class KernelTestCaseWithFactoriesTraitTest extends KernelTestCase
2424
{
25-
use Factories;
25+
use Factories, SkipWithPHPUnitExtension;
2626

2727
#[Test]
2828
public function should_not_throw(): void

tests/Integration/ForceFactoriesTraitUsage/KernelTestCaseWithOnlyResetDatabaseTraitTestWithoutFactoriesTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ final class KernelTestCaseWithOnlyResetDatabaseTraitTestWithoutFactoriesTest ext
2222
{
2323
use KernelTestCaseWithoutFactoriesTrait;
2424
use ResetDatabase;
25+
use SkipWithPHPUnitExtension;
2526
}

tests/Integration/ForceFactoriesTraitUsage/KernelTestWithoutFactoriesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
#[RequiresPhpunit('>=11.0')]
2020
final class KernelTestWithoutFactoriesTest extends KernelTestCase
2121
{
22-
use KernelTestCaseWithoutFactoriesTrait;
22+
use KernelTestCaseWithoutFactoriesTrait, SkipWithPHPUnitExtension;
2323
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Zenstruck\Foundry\Tests\Integration\ForceFactoriesTraitUsage;
4+
5+
use PHPUnit\Framework\Attributes\Before;
6+
use PHPUnit\Framework\TestCase;
7+
use Zenstruck\Foundry\PHPUnit\FoundryExtension;
8+
9+
/**
10+
* @phpstan-require-extends TestCase
11+
*/
12+
trait SkipWithPHPUnitExtension
13+
{
14+
#[Before]
15+
public function _skipWithPHPUnitExtension(): void
16+
{
17+
if (FoundryExtension::isEnabled()) {
18+
self::markTestSkipped('This test requires *NOT* using Foundry\'s PHUnit extension.');
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)