diff --git a/src/Illuminate/Contracts/Testing/InitializeTraits.php b/src/Illuminate/Contracts/Testing/InitializeTraits.php new file mode 100644 index 000000000000..f558b6630d03 --- /dev/null +++ b/src/Illuminate/Contracts/Testing/InitializeTraits.php @@ -0,0 +1,8 @@ +initializeFirstLevelTraits(); + } + Model::setEventDispatcher($this->app['events']); $this->setUpHasRun = true; @@ -145,6 +150,24 @@ protected function setUpTraits() return $uses; } + /** + * Initialize first-level testing traits and register their tear-down callbacks. + * + * @return void + */ + protected function initializeFirstLevelTraits() + { + foreach (class_uses(static::class) as $trait) { + if (method_exists($this, $setUpMethod = 'setUp'.class_basename($trait))) { + $this->{$setUpMethod}(); + } + + if (method_exists($this, $tearDownMethod = 'tearDown'.class_basename($trait))) { + $this->beforeApplicationDestroyed([$this, $tearDownMethod]); + } + } + } + /** * Clean up the testing environment before the next test. *