![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/medad.corals.io/vendor/orchestra/testbench-core/src/Concerns/ |
<?php namespace Orchestra\Testbench\Concerns; use Carbon\Carbon; use Carbon\CarbonImmutable; use Illuminate\Console\Application as Artisan; use Illuminate\Database\Eloquent\Model; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Foundation\Testing\WithoutEvents; use Illuminate\Foundation\Testing\WithoutMiddleware; use Mockery; use Throwable; trait Testing { use CreatesApplication, WithFactories, WithLaravelMigrations, WithLoadMigrationsFrom; /** * The Illuminate application instance. * * @var \Illuminate\Foundation\Application */ protected $app; /** * The callbacks that should be run after the application is created. * * @var array */ protected $afterApplicationCreatedCallbacks = []; /** * The callbacks that should be run after the application is refreshed. * * @var array */ protected $afterApplicationRefreshedCallbacks = []; /** * The callbacks that should be run before the application is destroyed. * * @var array */ protected $beforeApplicationDestroyedCallbacks = []; /** * The exception thrown while running an application destruction callback. * * @var \Throwable */ protected $callbackException; /** * Indicates if we have made it through the base setUp function. * * @var bool */ protected $setUpHasRun = false; /** * Setup the test environment. * * @return void */ final protected function setUpTheTestEnvironment(): void { if (! $this->app) { $this->refreshApplication(); } foreach ($this->afterApplicationRefreshedCallbacks as $callback) { \call_user_func($callback); } $this->setUpTraits(); foreach ($this->afterApplicationCreatedCallbacks as $callback) { \call_user_func($callback); } Model::setEventDispatcher($this->app['events']); $this->setUpHasRun = true; } /** * Clean up the testing environment before the next test. * * @return void */ final protected function tearDownTheTestEnvironment(): void { if ($this->app) { $this->callBeforeApplicationDestroyedCallbacks(); $this->app->flush(); $this->app = null; } $this->setUpHasRun = false; if (\property_exists($this, 'serverVariables')) { $this->serverVariables = []; } if (\property_exists($this, 'defaultHeaders')) { $this->defaultHeaders = []; } if (\class_exists(Mockery::class)) { if ($container = Mockery::getContainer()) { $this->addToAssertionCount($container->mockery_getExpectationCount()); } Mockery::close(); } Carbon::setTestNow(); if (\class_exists(CarbonImmutable::class)) { CarbonImmutable::setTestNow(); } $this->afterApplicationCreatedCallbacks = []; $this->beforeApplicationDestroyedCallbacks = []; Artisan::forgetBootstrappers(); if ($this->callbackException) { throw $this->callbackException; } } /** * Boot the testing helper traits. * * @param array $uses * * @return array */ final protected function setUpTheTestEnvironmentTraits(array $uses): array { if (isset($uses[RefreshDatabase::class])) { $this->refreshDatabase(); } if (isset($uses[DatabaseMigrations::class])) { $this->runDatabaseMigrations(); } if (isset($uses[DatabaseTransactions::class])) { $this->beginDatabaseTransaction(); } if (isset($uses[WithoutMiddleware::class])) { $this->disableMiddlewareForAllTests(); } if (isset($uses[WithoutEvents::class])) { $this->disableEventsForAllTests(); } if (isset($uses[WithFaker::class])) { $this->setUpFaker(); } return $uses; } /** * Register a callback to be run after the application is refreshed. * * @param callable $callback * * @return void */ protected function afterApplicationRefreshed(callable $callback): void { $this->afterApplicationRefreshedCallbacks[] = $callback; if ($this->setUpHasRun) { \call_user_func($callback); } } /** * Register a callback to be run after the application is created. * * @param callable $callback * * @return void */ protected function afterApplicationCreated(callable $callback): void { $this->afterApplicationCreatedCallbacks[] = $callback; if ($this->setUpHasRun) { \call_user_func($callback); } } /** * Register a callback to be run before the application is destroyed. * * @param callable $callback * * @return void */ protected function beforeApplicationDestroyed(callable $callback): void { \array_unshift($this->beforeApplicationDestroyedCallbacks, $callback); } /** * Execute the application's pre-destruction callbacks. * * @return void */ protected function callBeforeApplicationDestroyedCallbacks() { foreach ($this->beforeApplicationDestroyedCallbacks as $callback) { try { \call_user_func($callback); } catch (Throwable $e) { if (! $this->callbackException) { $this->callbackException = $e; } } } } /** * Boot the testing helper traits. * * @return array */ abstract protected function setUpTraits(); /** * Refresh the application instance. * * @return void */ abstract protected function refreshApplication(); }