Skip to content

Commit f76cba2

Browse files
authored
fix: fix deprecation message for Factories trait (#806)
1 parent 636cedd commit f76cba2

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/Exception/FactoriesTraitNotUsed.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public static function throwIfClassDoesNotHaveFactoriesTrait(string $class): voi
5757
trigger_deprecation(
5858
'zenstruck/foundry',
5959
'2.4',
60-
'In order to use Foundry, you must use the trait "%s" in your "%s" tests. This will throw an exception in 3.0.',
61-
KernelTestCase::class,
60+
'In order to use Foundry correctly, you must use the trait "%s" in your "%s" tests. This will throw an exception in 3.0.',
61+
Factories::class,
6262
$class
6363
);
6464
}

tests/Integration/ForceFactoriesTraitUsage/KernelTestCaseWithoutFactoriesTraitTestCase.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function not_using_foundry_should_not_throw_even_when_container_is_used()
4444
#[IgnoreDeprecations]
4545
public function using_foundry_without_trait_should_throw(): void
4646
{
47-
$this->expectUserDeprecationMessageMatches('/In order to use Foundry, you must use the trait/');
47+
$this->assertDeprecation();
4848

4949
Object1Factory::createOne();
5050
}
@@ -53,7 +53,7 @@ public function using_foundry_without_trait_should_throw(): void
5353
#[IgnoreDeprecations]
5454
public function using_foundry_without_trait_should_throw_even_when_kernel_is_booted(): void
5555
{
56-
$this->expectUserDeprecationMessageMatches('/In order to use Foundry, you must use the trait/');
56+
$this->assertDeprecation();
5757

5858
self::getContainer()->get('.zenstruck_foundry.configuration');
5959

@@ -65,7 +65,7 @@ public function using_foundry_without_trait_should_throw_even_when_kernel_is_boo
6565
#[IgnoreDeprecations]
6666
public function using_a_story_without_factories_trait_should_throw(): void
6767
{
68-
$this->expectUserDeprecationMessageMatches('/In order to use Foundry, you must use the trait/');
68+
$this->assertDeprecation();
6969

7070
ObjectStory::load();
7171
}
@@ -88,4 +88,9 @@ public static function _shutdownFoundry(): void
8888
{
8989
Configuration::shutdown();
9090
}
91+
92+
private function assertDeprecation(): void
93+
{
94+
$this->expectUserDeprecationMessageMatches('/In order to use Foundry correctly, you must use the trait "Zenstruck\\\\Foundry\\\\Test\\\\Factories/');
95+
}
9196
}

0 commit comments

Comments
 (0)