![]() 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/rentpix.corals.io/vendor/orchestra/testbench-core/src/Concerns/ |
<?php namespace Orchestra\Testbench\Concerns; use Illuminate\Contracts\Console\Kernel; use Illuminate\Filesystem\Filesystem; use Illuminate\Foundation\Application as LaravelApplication; use Orchestra\Testbench\Attributes\DefineRoute; use Orchestra\Testbench\Features\TestingFeature; use Orchestra\Testbench\Foundation\Application; /** * @internal */ trait HandlesRoutes { /** * Setup routes requirements. * * @param \Illuminate\Foundation\Application $app */ protected function setUpApplicationRoutes($app): void { if ($app->routesAreCached()) { return; } /** @var \Illuminate\Routing\Router $router */ $router = $app['router']; TestingFeature::run( testCase: $this, default: function () use ($router) { $this->defineRoutes($router); $router->middleware('web') ->group(fn ($router) => $this->defineWebRoutes($router)); }, annotation: fn () => $this->parseTestMethodAnnotations($app, 'define-route', function ($method) use ($router) { $this->{$method}($router); }), attribute: fn () => $this->parseTestMethodAttributes($app, DefineRoute::class) ); $router->getRoutes()->refreshNameLookups(); } /** * Define routes setup. * * @param \Illuminate\Routing\Router $router * @return void */ protected function defineRoutes($router) { // Define routes. } /** * Define web routes setup. * * @param \Illuminate\Routing\Router $router * @return void */ protected function defineWebRoutes($router) { // Define routes. } /** * Define cache routes setup. * * @param string $route * @return void */ protected function defineCacheRoutes(string $route) { $files = new Filesystem(); $time = time(); $laravel = Application::create(static::applicationBasePath()); $files->put( $laravel->basePath("routes/testbench-{$time}.php"), $route ); $laravel->make(Kernel::class)->call('route:cache'); $this->assertTrue( $files->exists($laravel->bootstrapPath('cache/routes-v7.php')) ); if ($this->app instanceof LaravelApplication) { $this->reloadApplication(); } $this->requireApplicationCachedRoutes($files); } /** * Require application cached routes. */ protected function requireApplicationCachedRoutes(Filesystem $files): void { $this->afterApplicationCreated(function () { if ($this->app instanceof LaravelApplication) { require $this->app->getCachedRoutesPath(); } }); $this->beforeApplicationDestroyed(function () use ($files) { if ($this->app instanceof LaravelApplication) { $files->delete( $this->app->bootstrapPath('cache/routes-v7.php'), ...$files->glob($this->app->basePath('routes/testbench-*.php')) ); } sleep(1); }); } }