public function testNamespacesOverridePackages() { $finder = new IlluminateViewFinder($filesystem = m::mock('Illuminate\\Filesystem\\Filesystem'), array(__DIR__)); $finder->setThemeBag($bag = $this->getMockThemeBag()); $finder->addNamespace('foo', __DIR__ . '/namespaces/foo'); $bag->shouldReceive('getCascadedNamespaceViewPaths')->with('foo')->once()->andReturn($paths = array('foo/1', 'foo/2')); $filesystem->shouldReceive('exists')->with('foo/1/bar.blade.php')->once()->andReturn(false); $filesystem->shouldReceive('exists')->with('foo/1/bar.php')->once()->andReturn(false); $filesystem->shouldReceive('exists')->with($path = 'foo/2/bar.blade.php')->once()->andReturn(true); // Because we use mocks, we know the package method calls are ever made $this->assertEquals($path, $finder->find('foo::bar')); }
/** * Override the view finder used by Laravel to be our Theme view finder. * * @return void */ protected function overrideViewFinder() { $originalViewFinder = $this->app['view.finder']; $this->app['view.finder'] = $this->app->share(function ($app) use($originalViewFinder) { $paths = array_merge($app['config']['view.paths'], $originalViewFinder->getPaths()); $viewFinder = new IlluminateViewFinder($app['files'], $paths, $originalViewFinder->getExtensions()); $viewFinder->setThemeBag($app['themes']); foreach ($originalViewFinder->getPaths() as $location) { $viewFinder->addLocation($location); } foreach ($originalViewFinder->getHints() as $namespace => $hints) { $viewFinder->addNamespace($namespace, $hints); } return $viewFinder; }); // Now that we have overridden the "view.finder" IoC offest, we // need to re-register the factory as we cannot reset it // on the Factory at runtime, yet. $viewServiceProvider = new ViewServiceProvider($this->app); $viewServiceProvider->registerFactory(); }