From 1473a3dcf6dd878ef9171a3099c88f7b78959d4a Mon Sep 17 00:00:00 2001 From: pascalbaljet Date: Mon, 16 May 2022 00:17:59 +0200 Subject: [PATCH 1/3] Boot test traits --- .../Foundation/Testing/TestCase.php | 8 +++++ tests/Foundation/Testing/BootTraitsTest.php | 36 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 tests/Foundation/Testing/BootTraitsTest.php diff --git a/src/Illuminate/Foundation/Testing/TestCase.php b/src/Illuminate/Foundation/Testing/TestCase.php index d7e92b557288..cb9810ebc3a2 100644 --- a/src/Illuminate/Foundation/Testing/TestCase.php +++ b/src/Illuminate/Foundation/Testing/TestCase.php @@ -143,6 +143,14 @@ protected function setUpTraits() $this->setUpFaker(); } + foreach ($uses as $trait) { + $method = 'boot'.class_basename($trait); + + if (method_exists($this, $method)) { + $this->{$method}(); + } + } + return $uses; } diff --git a/tests/Foundation/Testing/BootTraitsTest.php b/tests/Foundation/Testing/BootTraitsTest.php new file mode 100644 index 000000000000..dfce63472442 --- /dev/null +++ b/tests/Foundation/Testing/BootTraitsTest.php @@ -0,0 +1,36 @@ +booted = true; + } +} + +class TestCaseWithTrait extends FoundationTestCase +{ + use CreatesApplication; + use TestTrait; +} + +class BootTraitsTest extends TestCase +{ + public function testSetUpTraitsWithBootMethod() + { + $testCase = new TestCaseWithTrait; + + $method = new \ReflectionMethod(get_class($testCase), 'setUpTraits'); + tap($method)->setAccessible(true)->invoke($testCase); + + $this->assertTrue($testCase->booted); + } +} From c6c1651f525d585f242c191b7e9aeff6d2d1bd80 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 19 May 2022 09:42:47 -0500 Subject: [PATCH 2/3] use setUp --- src/Illuminate/Foundation/Testing/TestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Testing/TestCase.php b/src/Illuminate/Foundation/Testing/TestCase.php index cb9810ebc3a2..34aa06582d4d 100644 --- a/src/Illuminate/Foundation/Testing/TestCase.php +++ b/src/Illuminate/Foundation/Testing/TestCase.php @@ -144,7 +144,7 @@ protected function setUpTraits() } foreach ($uses as $trait) { - $method = 'boot'.class_basename($trait); + $method = 'setUp'.class_basename($trait); if (method_exists($this, $method)) { $this->{$method}(); From b835af11c49534ae743aeaa8fe3b89eeedf8bb4c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 19 May 2022 09:49:06 -0500 Subject: [PATCH 3/3] fix test --- tests/Foundation/Testing/BootTraitsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Foundation/Testing/BootTraitsTest.php b/tests/Foundation/Testing/BootTraitsTest.php index dfce63472442..b26d66481152 100644 --- a/tests/Foundation/Testing/BootTraitsTest.php +++ b/tests/Foundation/Testing/BootTraitsTest.php @@ -10,7 +10,7 @@ trait TestTrait { public $booted = false; - public function bootTestTrait() + public function setUpTestTrait() { $this->booted = true; }