Example #1
2
 /**
  * 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);
 }
Example #2
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);
 }
Example #3
0
 public function register()
 {
     $this->app->instance(__CLASS__, $this);
     $this->app->alias(__CLASS__, $this->containerName);
     $this->blade->directive('include_layout', function ($expr) {
         return "<?php echo app('{$this->containerName}')->renderLayout{$expr} ?>";
     });
 }
 /**
  * Create a fresh mock instance for the given class.
  *
  * @param  string  $name
  * @return \Mockery\Expectation
  */
 protected static function createFreshMockInstance($name)
 {
     static::$resolvedInstance[$name] = $mock = static::createMockByName($name);
     if (isset(static::$app)) {
         static::$app->instance($name, $mock);
     }
     return $mock;
 }
 /**
  * Bootstrap the given application.
  *
  * @param  \Illuminate\Contracts\Foundation\Application $app
  * @return void
  */
 public function bootstrap(Application $app)
 {
     $this->app = $app;
     $this->app->setBasePath($this->basePath);
     $this->app->instance('path', $this->getPath());
     foreach (['config', 'database', 'lang', 'public', 'storage'] as $path) {
         $this->app->instance('path.' . $path, $this->getPath($path));
     }
 }
 /**
  * Setup application.
  *
  * @return Application
  */
 protected function setupApplication()
 {
     // Create the application such that the config is loaded
     $app = new Application();
     $app->instance('path', 'foobar');
     $app->instance('files', new Filesystem());
     $app->instance('config', new Repository($app->getConfigLoader(), 'foobar'));
     return $app;
 }
 /**
  * Create an barebones Laravel application.
  */
 protected function createApplication()
 {
     $this->app = new Application(__DIR__ . '/../../..');
     $this->app->instance('config', new Repository([]));
     $this->app['config']->set('session.driver', 'array');
     $this->app['config']->set('database', ['fetch' => PDO::FETCH_CLASS, 'default' => 'sqlite', 'connections' => ['sqlite' => ['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '']], 'migrations' => 'migrations']);
     $this->app['config']->set('app', ['providers' => [FilesystemServiceProvider::class, FoundationServiceProvider::class, PipelineServiceProvider::class, SessionServiceProvider::class, ViewServiceProvider::class, DatabaseServiceProvider::class, MigrationServiceProvider::class]]);
     $this->app->registerConfiguredProviders();
     $this->app->boot();
 }
Example #8
0
 public function createApplication()
 {
     $app = new Application(__DIR__ . '/../stub');
     $app->instance('path', '');
     $app->instance('path.base', '');
     $app->instance('path.storage', '');
     $app->instance('config', new Config());
     $app->loadEnvironmentFrom(__DIR__ . '/../examples/' . '.env');
     (new DetectEnvironment())->bootstrap($app);
     return $app;
 }
Example #9
0
 /**
  * Initiate a mock expectation on the facade.
  *
  * @param  dynamic
  * @return \Mockery\Expectation
  */
 public static function shouldReceive()
 {
     $name = static::getFacadeAccessor();
     if (static::isMock()) {
         $mock = static::$resolvedInstance[$name];
     } else {
         static::$resolvedInstance[$name] = $mock = \Mockery::mock(static::getMockableClass($name));
         static::$app->instance($name, $mock);
     }
     return call_user_func_array(array($mock, 'shouldReceive'), func_get_args());
 }
Example #10
0
 public function setupApplication($config = true)
 {
     $app = new Application();
     $app->instance('path', 'foobar');
     $app->instance('files', new Filesystem());
     $app->instance('config', new Repository($app->getConfigLoader(), 'foobar'));
     if ($config) {
         $app['config']->set('statsd', array('host' => "localhost", 'port' => 7890, 'namespace' => 'test_namespace'));
     }
     return $app;
 }
Example #11
0
 /**
  * Constructor.
  *
  * @param Application $app
  */
 public function __construct(Application $app)
 {
     $this->app = $app;
     $this->httpKernel = $this->app->make('Illuminate\\Contracts\\Http\\Kernel');
     $this->httpKernel->bootstrap();
     $this->app->boot();
     $url = $this->app->config->get('app.url', 'http://localhost');
     $this->app->instance('request', Request::createFromBase(SyfmonyRequest::create($url)));
     $components = parse_url($url);
     $host = isset($components['host']) ? $components['host'] : 'localhost';
     parent::__construct($this, ['HTTP_HOST' => $host]);
     $this->followRedirects(true);
     // Parent constructor sets this to false by default
 }
 private function setupApplication()
 {
     $app = new Application();
     $app->setBasePath(sys_get_temp_dir());
     $app->instance('config', new Repository());
     return $app;
 }
Example #13
0
 /**
  * Bootstrap the test environemnt:
  * - Create an application instance and register it within itself.
  * - Register the package service provider with the app.
  * - Set the APP facade.
  *
  * @return void
  */
 public function setUp()
 {
     $app = new Application();
     $app->instance('app', $app);
     $app->register('Ideil\\LaravelFileOre\\LaravelFileOreServiceProvider');
     Facade::setFacadeApplication($app);
 }
Example #14
0
 public function getApplication()
 {
     $app = new Application();
     $app->instance('path', __DIR__);
     $app['path.storage'] = __DIR__ . '/storage';
     // Monolog
     $log = m::mock('Illuminate\\Log\\Writer');
     $log->shouldReceive('getMonolog')->andReturn(m::mock('Monolog\\Logger'));
     $app['log'] = $log;
     // Config
     $config = new Repository(m::mock('Illuminate\\Config\\LoaderInterface'), 'production');
     $config->getLoader()->shouldReceive('addNamespace')->with('laravel-sentry', __DIR__);
     $config->getLoader()->shouldReceive('cascadePackage')->andReturnUsing(function ($env, $package, $group, $items) {
         return $items;
     });
     $config->getLoader()->shouldReceive('exists')->with('environments', 'laravel-sentry')->andReturn(false);
     $config->getLoader()->shouldReceive('exists')->with('dsn', 'laravel-sentry')->andReturn(false);
     $config->getLoader()->shouldReceive('exists')->with('level', 'laravel-sentry')->andReturn(false);
     $config->getLoader()->shouldReceive('load')->with('production', 'config', 'laravel-sentry')->andReturn(array('environments' => array('prod', 'production'), 'dsn' => '', 'level' => 'error'));
     $config->package('foo/laravel-sentry', __DIR__);
     $app['config'] = $config;
     // Env
     $app['env'] = 'production';
     return $app;
 }
Example #15
0
File: Base.php Project: tureki/rrs
 protected function getApplication($customConfig = [])
 {
     $app = new Application();
     $app->instance('path', __DIR__);
     $app['env'] = 'production';
     $app['path.config'] = $this->root . '/config';
     // Filesystem
     $files = m::mock('Illuminate\\Filesystem\\Filesystem');
     $app['files'] = $files;
     // View
     // $finder = m::mock('Illuminate\View\ViewFinderInterface');
     // $finder->shouldReceive('addExtension');
     // $app['view'] = new Factory(
     // new EngineResolver(),
     // $finder,
     // m::mock('Illuminate\Events\Dispatcher')
     // );
     // $config_data = include $config_file;
     // Config
     $app['config'] = new Repository([]);
     $app->bind('\\Illuminate\\Config\\Repository', function () use($app) {
         return $app['config'];
     });
     return $app;
 }
Example #16
0
 /**
  * Bootstrap the test environemnt:
  * - Create an application instance and register it within itself.
  * - Register the package service provider with the app.
  * - Set the APP facade.
  *
  * @return void
  */
 public function setUp()
 {
     $app = new Application();
     $app->instance('app', $app);
     $app->register('Codesleeve\\LaravelStapler\\LaravelStaplerServiceProvider');
     Facade::setFacadeApplication($app);
 }
Example #17
0
 /**
  * Initialize the Laravel framework.
  *
  * @throws ModuleConfig
  */
 protected function initializeLaravel()
 {
     $this->app = $this->bootApplication();
     $this->app->instance('request', new Request());
     $this->client = new LaravelConnector($this->app);
     $this->client->followRedirects(true);
 }
 /**
  * setUp method.
  */
 public function setUp()
 {
     // Bootstrap the application container
     $app = new Application();
     $app->instance('app', $app);
     $app->register('Codesleeve\\FixtureL4\\FixtureL4ServiceProvider');
     Facade::setFacadeApplication($app);
 }
 /**
  * @return Application
  */
 private function setupApplication()
 {
     // Create the application such that the config is loaded.
     $app = new Application();
     $app->setBasePath(sys_get_temp_dir());
     $app->instance('config', new Repository());
     return $app;
 }
Example #20
0
 public function testThatProfilerCanRegisterModules()
 {
     $p = new Profiler(new Repo());
     $p->setDefaultModules(['FirstDummyModule', 'SecondDummyModule']);
     $a = new Application();
     $c = M::mock('Illuminate\\Config\\Repository');
     $c->shouldReceive('get')->once()->andReturn([]);
     $a->instance('config', $c);
     $p->registerModules($a);
 }
Example #21
0
 /**
  * Specify a list of jobs that should be dispatched for the given operation.
  *
  * These jobs will be mocked, so that handlers will not actually be executed.
  *
  * @param  array|mixed $jobs
  * @return $this
  */
 protected function expectsJobs($jobs)
 {
     $jobs = is_array($jobs) ? $jobs : func_get_args();
     $mock = Mockery::mock('Illuminate\\Bus\\Dispatcher[dispatch]', [$this->app]);
     foreach ($jobs as $job) {
         $mock->shouldReceive('dispatch')->atLeast()->once()->with(Mockery::type($job));
     }
     $this->app->instance('Illuminate\\Contracts\\Bus\\Dispatcher', $mock);
     return $this;
 }
Example #22
0
 protected function makeApp($env)
 {
     $app = new App();
     $app['path'] = dirname(__DIR__) . '/mockApp';
     $app['env'] = $env;
     $app->bindIf('config.loader', function ($app) {
         return new FileLoader(new Filesystem(), $app['path'] . '/config');
     }, true);
     $app->instance('config', new Config($app['config.loader'], $app['env']));
     return $app;
 }
Example #23
0
 /**
  * Creates the application.
  *
  * Needs to be implemented by subclasses.
  *
  * @return \Symfony\Component\HttpKernel\HttpKernelInterface
  */
 public function createApplication()
 {
     $app = new Application();
     $app->detectEnvironment(array('local' => array('your-machine-name')));
     $app->bindInstallPaths($this->getApplicationPaths());
     $app['env'] = 'testing';
     $app->instance('app', $app);
     Facade::clearResolvedInstances();
     Facade::setFacadeApplication($app);
     $app->registerCoreContainerAliases();
     with($envVariables = new EnvironmentVariables($app->getEnvironmentVariablesLoader()))->load($app['env']);
     $app->instance('config', $config = new Repository($app->getConfigLoader(), $app['env']));
     $app->startExceptionHandling();
     date_default_timezone_set($this->getApplicationTimezone());
     $aliases = array_merge($this->getApplicationAliases(), $this->getPackageAliases());
     AliasLoader::getInstance($aliases)->register();
     Request::enableHttpMethodParameterOverride();
     $providers = array_merge($this->getApplicationProviders(), $this->getPackageProviders());
     $app->getProviderRepository()->load($app, $providers);
     $this->registerBootedCallback($app);
     return $app;
 }
 private function getApplication(array $paths = array(), array $hints = array())
 {
     $app = new Application();
     $app['env'] = 'testing';
     $app->instance('path', __DIR__ . '/../fixtures/Console/');
     // Storage path
     $app['path.storage'] = __DIR__;
     // Finder
     $finder = new FileViewFinder(new Filesystem(), $paths);
     if (count($hints) > 0) {
         foreach ($hints as $namespace => $namespace_paths) {
             $finder->addNamespace($namespace, $namespace_paths);
             $paths = array_merge($paths, $namespace_paths);
         }
     }
     // Total number of files across all paths
     $file_finder = new Finder();
     $file_finder->files()->in($paths)->name('*.twig');
     // View
     $view = m::mock('Illuminate\\View\\Environment');
     $view->shouldReceive('addExtension');
     $view->shouldReceive('getFinder')->andReturn($finder);
     $engine = m::mock('Illuminate\\View\\View');
     $engine->shouldReceive('render');
     $view->shouldReceive('make')->andReturn($engine);
     $app['view'] = $view;
     // Config
     $config = m::mock('Illuminate\\Container\\Container');
     $config->shouldReceive('get')->andReturnUsing(function ($x) {
         $args = func_get_args();
         if ($args[0] == 'twigbridge::extension') {
             return 'twig';
         }
         return array_pop($args);
     });
     $app['config'] = $config;
     return $app;
 }
 private function getLoader()
 {
     // Mock application
     $functions = array('functions' => array('array_get', 'fooBar' => function () {
         return 'FOOBAR';
     }));
     $filters = array('filters' => array('camel_case', 'snakeCase' => function () {
         return 'snakeCASE';
     }));
     $app = new Application();
     $app->instance('path', __DIR__);
     $config = new Repository(m::mock('Illuminate\\Config\\LoaderInterface'), 'production');
     $config->getLoader()->shouldReceive('addNamespace')->with('twigbridge', __DIR__);
     $config->getLoader()->shouldReceive('cascadePackage')->andReturnUsing(function ($env, $package, $group, $items) {
         return $items;
     });
     $config->getLoader()->shouldReceive('exists')->with('functions', 'twigbridge')->andReturn(false);
     $config->getLoader()->shouldReceive('exists')->with('filters', 'twigbridge')->andReturn(false);
     $config->getLoader()->shouldReceive('load')->with('production', 'config', 'twigbridge')->andReturn(array_merge($functions, $filters));
     $config->package('foo/twigbridge', __DIR__);
     $app['config'] = $config;
     // Get instance of HelperLoader
     return new HelperLoader($app, new Twig_Environment());
 }
Example #26
0
 /**
  * Register an existing instance as shared in the container.
  *
  * @param string $abstract
  * @param mixed $instance
  * @return void 
  * @static 
  */
 public static function instance($abstract, $instance)
 {
     //Method inherited from \Illuminate\Container\Container
     \Illuminate\Foundation\Application::instance($abstract, $instance);
 }
 /**
  * @param \Illuminate\Foundation\Application $app
  */
 private function setUpHttpKernel($app)
 {
     $app->instance('request', (new \Illuminate\Http\Request())->instance());
     $app->make('Illuminate\\Foundation\\Http\\Kernel', [$app, $this->getRouter()])->bootstrap();
 }
 /**
  * Disable middleware for the test.
  *
  * @return $this
  */
 public function withoutMiddleware()
 {
     $this->app->instance('middleware.disable', true);
     return $this;
 }
Example #29
0
 /**
  * Replace the Laravel event dispatcher with a mock.
  */
 private function mockEventDispatcher()
 {
     $mockGenerator = new \PHPUnit_Framework_MockObject_Generator();
     $mock = $mockGenerator->getMock('Illuminate\\Contracts\\Events\\Dispatcher');
     $this->app->instance('events', $mock);
 }
 public function getApplication(array $twig_options = array(), array $paths = array(), array $hints = array())
 {
     $app = new Application();
     $app->instance('path', __DIR__);
     $app['path.storage'] = __DIR__ . '/storage';
     $finder = m::mock('Illuminate\\View\\ViewFinderInterface');
     $finder->shouldReceive('getPaths')->andReturn($paths);
     $finder->shouldReceive('getHints')->andReturn($hints);
     $app['view'] = new Environment(m::mock('Illuminate\\View\\Engines\\EngineResolver'), $finder, m::mock('Illuminate\\Events\\Dispatcher'));
     $config = new Repository(m::mock('Illuminate\\Config\\LoaderInterface'), 'production');
     $twig_options or $twig_options = array('egg' => 'fried');
     $config->getLoader()->shouldReceive('addNamespace')->with('twigbridge', __DIR__);
     $config->getLoader()->shouldReceive('cascadePackage')->andReturnUsing(function ($env, $package, $group, $items) {
         return $items;
     });
     $config->getLoader()->shouldReceive('exists')->with('extension', 'twigbridge')->andReturn(false);
     $config->getLoader()->shouldReceive('exists')->with('extensions', 'twigbridge')->andReturn(false);
     $config->getLoader()->shouldReceive('exists')->with('delimiters', 'twigbridge')->andReturn(false);
     $config->getLoader()->shouldReceive('exists')->with('twig', 'twigbridge')->andReturn(false);
     $config->getLoader()->shouldReceive('load')->with('production', 'config', 'twigbridge')->andReturn(array('extension' => 'twig', 'twig' => $twig_options, 'extensions' => array('TwigBridge\\Extensions\\Html')));
     $config->package('foo/twigbridge', __DIR__);
     $app['config'] = $config;
     return $app;
 }