Please try it and leave your feedback. The module is based on the Laravel 4 module by Davert. ## Demo project ## Status * Maintainer: **Jan-Henk Gerritsen** * Stability: **dev** * Contact: janhenkgerritsen@gmail.com ## Example modules: enabled: - Laravel5 ## Config * cleanup: boolean, default true - all db queries will be run in transaction, which will be rolled back at the end of test. * environment_file: string, default .env - The .env file to load for the tests. * bootstrap: string, default bootstrap/app.php - Relative path to app.php config file. * root: string, default - Root path of our application. * packages: string, default workbench - Root path of application packages (if any). ## API * app - Illuminate\Foundation\Application instance * client - BrowserKit` client ## Parts * ORM - include only haveRecord/grabRecord/seeRecord/dontSeeRecord actions
Inheritance: extends Codeception\Lib\Framework, implements Codeception\Lib\Interfaces\ActiveRecord, implements Codeception\Lib\Interfaces\PartedModule
Beispiel #1
3
 /**
  * Initialize the Laravel framework.
  * @param SymfonyRequest $request
  */
 private function initialize($request = null)
 {
     // Store a reference to the database object
     // so the database connection can be reused during tests
     $this->oldDb = null;
     if ($this->app['db'] && $this->app['db']->connection()) {
         $this->oldDb = $this->app['db'];
     }
     // The module can login a user with the $I->amLoggedAs() method,
     // but this is not persisted between requests. Store a reference
     // to the logged in user to simulate this.
     $loggedInUser = null;
     if ($this->app['auth'] && $this->app['auth']->check()) {
         $loggedInUser = $this->app['auth']->user();
     }
     // Load the application object
     $this->app = $this->kernel = $this->loadApplication();
     // Set the request instance for the application
     if (is_null($request)) {
         $appConfig = (require $this->module->config['project_dir'] . 'config/app.php');
         $request = SymfonyRequest::create($appConfig['url']);
     }
     $this->app->instance('request', Request::createFromBase($request));
     $this->app->instance('middleware.disable', $this->module->config['disable_middleware']);
     // Reset the old database after the DatabaseServiceProvider ran.
     // This way other service providers that rely on the $app['db'] entry
     // have the correct instance available.
     if ($this->oldDb) {
         $this->app['events']->listen('Illuminate\\Database\\DatabaseServiceProvider', function () {
             $this->app->singleton('db', function () {
                 return $this->oldDb;
             });
         });
     }
     $this->app->make('Illuminate\\Contracts\\Http\\Kernel')->bootstrap();
     // If events should be disabled mock the event dispatcher instance
     if ($this->module->config['disable_events']) {
         $this->mockEventDispatcher();
     }
     // Setup an event listener to listen for all events that are triggered
     $this->setupEventListener();
     // If there was a user logged in restore this user.
     // Also reload the user object from the user provider to prevent stale user data.
     if ($loggedInUser) {
         $refreshed = $this->app['auth']->getProvider()->retrieveById($loggedInUser->getAuthIdentifier());
         $this->app['auth']->setUser($refreshed ?: $loggedInUser);
     }
     $this->module->setApplication($this->app);
 }
Beispiel #2
3
 /**
  * Initialize the Laravel framework.
  * @param SymfonyRequest $request
  */
 private function initialize($request = null)
 {
     // Store a reference to the database object
     // so the database connection can be reused during tests
     $oldDb = null;
     if ($this->app['db'] && $this->app['db']->connection()) {
         $oldDb = $this->app['db'];
     }
     // The module can login a user with the $I->amLoggedAs() method,
     // but this is not persisted between requests. Store a reference
     // to the logged in user to simulate this.
     $loggedInUser = null;
     if ($this->app['auth'] && $this->app['auth']->check()) {
         $loggedInUser = $this->app['auth']->user();
     }
     // Load the application object
     $this->app = $this->kernel = $this->loadApplication();
     // Set the request instance for the application
     if (is_null($request)) {
         $appConfig = (require $this->module->config['project_dir'] . 'config/app.php');
         $request = SymfonyRequest::create($appConfig['url']);
     }
     $this->app->instance('request', Request::createFromBase($request));
     $this->app->instance('middleware.disable', $this->module->config['disable_middleware']);
     // Bootstrap the application
     $this->app->make('Illuminate\\Contracts\\Http\\Kernel')->bootstrap();
     // Restore the old database object if available
     if ($oldDb) {
         $this->app['db'] = $oldDb;
         Model::setConnectionResolver($this->app['db']);
     }
     // If there was a user logged in restore this user.
     // Also reload the user object from the user provider to prevent stale user data.
     if ($loggedInUser) {
         $refreshed = $this->app['auth']->getProvider()->retrieveById($loggedInUser->getAuthIdentifier());
         $this->app['auth']->setUser($refreshed ?: $loggedInUser);
     }
     $this->module->setApplication($this->app);
 }
Beispiel #3
1
 /**
  * Initialize the Laravel framework.
  */
 private function initialize()
 {
     // Store a reference to the database object
     // so the database connection can be reused during tests
     $oldDb = null;
     if ($this->app['db'] && $this->app['db']->connection()) {
         $oldDb = $this->app['db'];
     }
     // The module can login a user with the $I->amLoggedAs() method,
     // but this is not persisted between requests. Store a reference
     // to the logged in user to simulate this.
     $loggedInUser = null;
     if ($this->app['auth'] && $this->app['auth']->check()) {
         $loggedInUser = $this->app['auth']->user();
     }
     $this->app = $this->kernel = $this->loadApplication();
     $this->app->make('Illuminate\\Contracts\\Http\\Kernel')->bootstrap();
     // Set the base url for the Request object
     $url = $this->app['config']->get('app.url', 'http://localhost');
     $this->app->instance('request', Request::createFromBase(SymfonyRequest::create($url)));
     if ($oldDb) {
         $this->app['db'] = $oldDb;
         Model::setConnectionResolver($this->app['db']);
     }
     // If there was a user logged in restore this user.
     // Also reload the user object from the user provider to prevent stale user data.
     if ($loggedInUser) {
         $refreshed = $this->app['auth']->getProvider()->retrieveById($loggedInUser->getAuthIdentifier());
         $this->app['auth']->setUser($refreshed ?: $loggedInUser);
     }
     $this->module->setApplication($this->app);
 }
Beispiel #4
0
 /**
  * Initialize the Laravel framework.
  *
  * @param SymfonyRequest $request
  */
 private function initialize($request = null)
 {
     // Store a reference to the database object
     // so the database connection can be reused during tests
     $this->oldDb = null;
     if (isset($this->app['db']) && $this->app['db']->connection()) {
         $this->oldDb = $this->app['db'];
     }
     $this->app = $this->kernel = $this->loadApplication();
     // Set the request instance for the application,
     if (is_null($request)) {
         $appConfig = (require $this->module->config['project_dir'] . 'config/app.php');
         $request = SymfonyRequest::create($appConfig['url']);
     }
     $this->app->instance('request', Request::createFromBase($request));
     // Reset the old database after the DatabaseServiceProvider ran.
     // This way other service providers that rely on the $app['db'] entry
     // have the correct instance available.
     if ($this->oldDb) {
         $this->app['events']->listen('Illuminate\\Database\\DatabaseServiceProvider', function () {
             $this->app->singleton('db', function () {
                 return $this->oldDb;
             });
         });
     }
     $this->app->make('Illuminate\\Contracts\\Http\\Kernel')->bootstrap();
     // Record all triggered events by adding a wildcard event listener
     $this->app['events']->listen('*', function () {
         $this->triggeredEvents[] = $this->normalizeEvent($this->app['events']->firing());
     });
     // Replace the Laravel exception handler with our decorated exception handler,
     // so exceptions can be intercepted for the disable_exception_handling functionality.
     $decorator = new ExceptionHandlerDecorator($this->app['Illuminate\\Contracts\\Debug\\ExceptionHandler']);
     $decorator->exceptionHandlingDisabled($this->exceptionHandlingDisabled);
     $this->app->instance('Illuminate\\Contracts\\Debug\\ExceptionHandler', $decorator);
     if ($this->module->config['disable_middleware'] || $this->middlewareDisabled) {
         $this->app->instance('middleware.disable', true);
     }
     if ($this->module->config['disable_events'] || $this->eventsDisabled) {
         $this->mockEventDispatcher();
     }
     if ($this->module->config['disable_model_events'] || $this->modelEventsDisabled) {
         Model::unsetEventDispatcher();
     }
     $this->applyBindings();
     $this->applyContextualBindings();
     $this->applyInstances();
     $this->module->setApplication($this->app);
 }