File tree Expand file tree Collapse file tree 2 files changed +21
-8
lines changed
src/Illuminate/Foundation/Testing Expand file tree Collapse file tree 2 files changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -144,11 +144,13 @@ protected function setUpTraits()
144144 }
145145
146146 foreach ($ uses as $ trait ) {
147- $ method = 'setUp ' .class_basename ($ trait );
148-
149- if (method_exists ($ this , $ method )) {
147+ if (method_exists ($ this , $ method = 'setUp ' .class_basename ($ trait ))) {
150148 $ this ->{$ method }();
151149 }
150+
151+ if (method_exists ($ this , $ method = 'tearDown ' .class_basename ($ trait ))) {
152+ $ this ->beforeApplicationDestroyed (fn () => $ this ->{$ method }());
153+ }
152154 }
153155
154156 return $ uses ;
Original file line number Diff line number Diff line change 88
99trait TestTrait
1010{
11- public $ booted = false ;
11+ public $ setUp = false ;
12+ public $ tearDown = false ;
1213
1314 public function setUpTestTrait ()
1415 {
15- $ this ->booted = true ;
16+ $ this ->setUp = true ;
17+ }
18+
19+ public function tearDownTestTrait ()
20+ {
21+ $ this ->tearDown = true ;
1622 }
1723}
1824
@@ -24,13 +30,18 @@ class TestCaseWithTrait extends FoundationTestCase
2430
2531class BootTraitsTest extends TestCase
2632{
27- public function testSetUpTraitsWithBootMethod ()
33+ public function testSetUpAndTearDownTraits ()
2834 {
2935 $ testCase = new TestCaseWithTrait ;
3036
31- $ method = new \ReflectionMethod (get_class ($ testCase ), 'setUpTraits ' );
37+ $ method = new \ReflectionMethod ($ testCase , 'setUpTraits ' );
38+ tap ($ method )->setAccessible (true )->invoke ($ testCase );
39+
40+ $ this ->assertTrue ($ testCase ->setUp );
41+
42+ $ method = new \ReflectionMethod ($ testCase , 'callBeforeApplicationDestroyedCallbacks ' );
3243 tap ($ method )->setAccessible (true )->invoke ($ testCase );
3344
34- $ this ->assertTrue ($ testCase ->booted );
45+ $ this ->assertTrue ($ testCase ->tearDown );
3546 }
3647}
You can’t perform that action at this time.
0 commit comments