refreshContainer(); $this->setUpTraits(); foreach ($this->afterApplicationCreatedCallbacks as $callback) { $callback(); } } protected function tearDown(): void { $this->flushContainer(); $this->callBeforeApplicationDestroyedCallbacks(); try { m::close(); } catch (Throwable $e) { } if ($this->callbackException) { throw $this->callbackException; } } /** * Boot the testing helper traits. * * @return array */ protected function setUpTraits() { $uses = array_flip(class_uses_recursive(static::class)); foreach ($uses as $trait) { if (method_exists($this, $method = 'setUp' . class_basename($trait))) { $this->{$method}(); } if (method_exists($this, $method = 'tearDown' . class_basename($trait))) { $this->beforeApplicationDestroyed(fn () => $this->{$method}()); } } return $uses; } /** * Register a callback to be run before the application is destroyed. */ protected function beforeApplicationDestroyed(callable $callback) { $this->beforeApplicationDestroyedCallbacks[] = $callback; } /** * Execute the application's pre-destruction callbacks. */ protected function callBeforeApplicationDestroyedCallbacks() { foreach ($this->beforeApplicationDestroyedCallbacks as $callback) { try { $callback(); } catch (Throwable $e) { if (! $this->callbackException) { $this->callbackException = $e; } } } } }