Exemplo n.º 1
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);
 }
Exemplo n.º 2
1
 /**
  * Creates new instance.
  *
  * @param  \Illuminate\Foundation\Application                          $app
  * @param  \Arcanedev\Localization\Contracts\RouteTranslatorInterface  $routeTranslator
  * @param  \Arcanedev\Localization\Contracts\LocalesManagerInterface   $localesManager
  */
 public function __construct(Application $app, RouteTranslatorInterface $routeTranslator, LocalesManagerInterface $localesManager)
 {
     $this->app = $app;
     $this->routeTranslator = $routeTranslator;
     $this->localesManager = $localesManager;
     $this->localesManager->setDefaultLocale($this->app->getLocale());
 }
Exemplo n.º 3
0
 public function createApplication()
 {
     $app = new Application();
     $app->register(\Illuminate\Database\DatabaseServiceProvider::class);
     $app->register(\ShiftOneLabs\LaravelNomad\LaravelNomadServiceProvider::class);
     return $app;
 }
 public function testMethodCalls()
 {
     $id = uniqid('testMethodCallId');
     $pass = [$id];
     $expect = [$id, $this];
     $this->applicationMock->expects($this->any())->method('make')->will($this->returnCallback(function ($make) {
         switch ($make) {
             case 'request':
                 return $this->requestMock;
             case 'commode.common.resolver':
                 return $this->resolver;
             case 'LaravelCommode\\Common\\Controllers\\CommodeControllerTest':
                 return $this;
         }
         dd(func_get_args());
     }));
     $this->requestMock->expects($this->at(0))->method('ajax')->will($this->returnValue(false));
     $this->requestMock->expects($this->at(1))->method('ajax')->will($this->returnValue(false));
     $this->requestMock->expects($this->at(2))->method('ajax')->will($this->returnValue(true));
     $resolveMethodsReflection = new ReflectionProperty($this->controller, 'resolveMethods');
     $resolveMethodsReflection->setAccessible(true);
     $resolveMethodsReflection->setValue($this->controller, false);
     $this->assertSame($pass, $this->controller->callAction('getSomeMethod', $pass));
     $resolveMethodsReflection->setValue($this->controller, true);
     $this->assertSame($expect, $this->controller->callAction('getSomeMethodResolve', $pass));
     $separateRequestsReflection = new ReflectionProperty($this->controller, 'separateRequests');
     $separateRequestsReflection->setAccessible(true);
     $separateRequestsReflection->setValue($this->controller, true);
     $this->requestMock->expects($this->any())->method('ajax')->will($this->returnValue(true));
     $this->assertSame($expect, $this->controller->callAction('getSomeMethodResolve', $pass));
 }
Exemplo n.º 5
0
 /**
  * Refresh the application instance.
  *
  * @return void
  */
 protected function refreshApplication()
 {
     $this->app = $this->createApplication();
     $this->client = $this->createClient();
     $this->app->setRequestForConsoleEnvironment();
     $this->app->boot();
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
0
 /**
  * Execute the console command.
  *
  * @throws \Bmartel\Transient\Exception\InvalidObjectTypeException
  * @return mixed
  */
 public function fire()
 {
     // If user provided a class as an argument,
     // ensure its a valid class which implments \Bmartel\Transient\TransientPropertyInterface.
     if ($class = $this->argument('modelClass')) {
         // Parse the class
         $model = $this->inputParser->parse($class);
         $modelType = $this->app->make($model);
         if (!$modelType instanceof TransientPropertyInterface) {
             throw new InvalidObjectTypeException('Class does not implement \\Bmartel\\Transient\\TransientPropertyInterface');
         }
     }
     // If user provided property options, parse them into an array for querying.
     if ($properties = $this->option('properties')) {
         $transientProperties = $this->inputParser->parseProperties($properties);
     }
     $result = null;
     // Determine what parameters to base the transient removal on.
     if (isset($transientProperties) && isset($modelType)) {
         $result = $this->transient->deleteByModelProperty($modelType, $transientProperties);
     } elseif (isset($modelType)) {
         $result = $this->transient->deleteByModelType($modelType);
     } elseif (isset($transientProperties)) {
         $result = $this->transient->deleteByProperty($transientProperties);
     } else {
         $result = $this->transient->deleteAll();
     }
     $propertiesName = str_plural('property', $result);
     // Report the result of the command
     $this->info("All done! Removed {$result} transient {$propertiesName}.");
 }
Exemplo n.º 8
0
 /**
  * Handle a request.
  *
  * @param SyfmonyRequest $request
  * @param int $type
  * @param bool $catch
  * @return Response
  */
 public function handle(SyfmonyRequest $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     $request = Request::createFromBase($request);
     $request->enableHttpMethodParameterOverride();
     $this->app->bind('request', $request);
     return $this->httpKernel->handle($request);
 }
Exemplo n.º 9
0
 /**
  * Register the module service provider.
  *
  * @param  string $properties
  * @return string
  * @throws \Caffeinated\Modules\Exception\FileMissingException
  */
 protected function registerServiceProvider($properties)
 {
     $namespace = $this->resolveNamespace($properties);
     $file = $this->repository->getPath() . "/{$namespace}/Providers/{$namespace}ServiceProvider.php";
     $serviceProvider = $this->repository->getNamespace() . "\\" . $namespace . "\\Providers\\{$namespace}ServiceProvider";
     $this->app->register($serviceProvider);
 }
Exemplo n.º 10
0
 /**
  * @param $request
  * @param callable $next
  * @return mixed
  */
 public function handle($request, \Closure $next)
 {
     if ($this->auth->check()) {
         $this->app->setLocale($this->auth->user()->getLocale());
     }
     return $next($request);
 }
Exemplo n.º 11
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;
 }
Exemplo n.º 12
0
 public function setupServiceProvider(Application $app)
 {
     $provider = new StatsdServiceProvider($app);
     $app->register($provider);
     $provider->boot();
     return $provider;
 }
 function it_should_run(Application $application, ApiValidator $validator, IApiControllerGenerator $apiControllerGenerator)
 {
     $application->make('Jdecano\\Api\\ApiValidator')->willReturn($validator);
     $validator->validate()->willReturn(null);
     $application->make('Jdecano\\Api\\IApiControllerGenerator')->willReturn($apiControllerGenerator);
     $apiControllerGenerator->make('User')->willReturn(null);
 }
 /**
  * Execute the command.
  *
  * @param Filesystem $fileSystem
  * @param Application $app
  * @param TranslationRepositoryInterface $repository
  * @param Dispatcher $event
  * @return Collection of Group
  */
 public function handle(Filesystem $fileSystem, Application $app, TranslationRepositoryInterface $repository, Dispatcher $event)
 {
     $files = $fileSystem->allFiles($app->langPath());
     /**
      * Retrieves all local languages
      */
     $languages = collect($files)->transform(function ($file) {
         return $file->getRelativePath();
     })->unique();
     /**
      * Save Database instance with all languages
      */
     $database = $repository->languages();
     /**
      * List Only names
      */
     $names = $database->pluck('name');
     /**
      * Create New Language for those which has been set locally
      * but was not present yet on the database
      */
     $newLanguages = $languages->merge($names)->diff($names)->map(function ($name) {
         return $this->dispatch(new CreateLanguageCommand($name));
     });
     /**
      * Announce LanguagesWasCreated
      */
     if (!$newLanguages->isEmpty()) {
         $event->fire(new LanguagesWasCreated($newLanguages));
     }
     /**
      * Returns All languages
      */
     return $database->merge($newLanguages);
 }
 public function testRegistering()
 {
     $singletonChecks = function ($serviceName, $callable) {
         switch ($serviceName) {
             case ValidationLocatorServiceProvider::PROVIDES_LOCATOR:
                 $this->testCreated = $callable();
                 break;
             case ValidationLocatorServiceProvider::PROVIDES_LOCATOR_INTERFACE:
                 $callable();
                 break;
         }
     };
     $makeCallback = function ($makingOf) {
         switch ($makingOf) {
             case 'db':
                 return $this->dbMock;
             case 'translator':
                 return $this->translatorMock;
             case 'laravel-commode.validation-locator':
                 return $this->testCreated;
         }
     };
     $this->application->expects($this->any())->method('singleton')->will($this->returnCallback($singletonChecks));
     $this->application->expects($this->any())->method('make')->will($this->returnCallback($makeCallback));
     $this->testInstance->registering();
 }
Exemplo n.º 16
0
 /**
  * @param Post $post
  *
  * @return string
  */
 public function renderFromPost(Post $post)
 {
     $post = $this->app->make('MyBB\\Core\\Presenters\\Post', [$post]);
     $message = $post->content;
     // TODO: MarkdownQuoteRenderer
     return "> {$message}\n\n";
 }
 private function setupServiceProvider(Application $app)
 {
     $provider = new ApaiIOServiceProvider($app);
     $app->register($provider);
     $provider->boot();
     return $provider;
 }
Exemplo n.º 18
0
 /**
  * Initialize the Laravel Framework.
  *
  * @throws ModuleConfig
  */
 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'];
     }
     // Store the current value for the router filters
     // so it can be reset after reloading the application
     $oldFiltersEnabled = null;
     if ($router = $this->app['router']) {
         $property = new \ReflectionProperty(get_class($router), 'filtering');
         $property->setAccessible(true);
         $oldFiltersEnabled = $property->getValue($router);
     }
     $this->app = $this->loadApplication();
     $this->kernel = $this->getStackedClient();
     $this->app->boot();
     // Reset the booted flag of the Application object
     // so the app will be booted again if it receives a new Request
     $property = new \ReflectionProperty(get_class($this->app), 'booted');
     $property->setAccessible(true);
     $property->setValue($this->app, false);
     if ($oldDb) {
         $this->app['db'] = $oldDb;
         Model::setConnectionResolver($this->app['db']);
     }
     if (!is_null($oldFiltersEnabled)) {
         $oldFiltersEnabled ? $this->app['router']->enableFilters() : $this->app['router']->disableFilters();
     }
     $this->module->setApplication($this->app);
 }
Exemplo n.º 19
0
 /**
  * Register the module service provider.
  *
  * @param  string $properties
  * @return string
  * @throws \Fabriciorabelo\Modules\Exception\FileMissingException
  */
 protected function registerServiceProvider($properties)
 {
     $module = studly_case($properties['slug']);
     $file = $this->repository->getPath() . "/{$module}/Providers/{$module}ServiceProvider.php";
     $namespace = $this->repository->getNamespace() . "\\" . $module . "\\Providers\\{$module}ServiceProvider";
     $this->app->register($namespace);
 }
 /**
  * Setup the test application
  *
  * @return \Illuminate\Foundation\Application
  */
 public function createApplication()
 {
     $app = new Application();
     $app->register(\Illuminate\Database\DatabaseServiceProvider::class);
     $app->register(\SeBuDesign\SqlServerGrammar\SqlServerGrammarServiceProvider::class);
     return $app;
 }
Exemplo n.º 21
0
 public function testRegisterAbstract()
 {
     $boundWith = function () {
         return true;
     };
     $boundWill = function ($serviceName) {
         switch ($serviceName) {
             case 'commode.common.loaded':
                 return false;
         }
         dd('bound', $serviceName);
         return true;
     };
     $makeWill = function ($make) {
         switch ($make) {
             case 'commode.common.ghostservice':
                 return $this->ghostServices;
                 break;
             case 'commode.common.resolver':
                 return $this->resolver;
                 break;
         }
         dd('make', func_get_args());
     };
     $this->applicationMock->expects($this->any())->method('getLoadedProviders')->will($this->returnValue([]));
     $this->applicationMock->expects($this->any())->method('bound')->with($this->callback($boundWith))->will($this->returnCallback($boundWill));
     $this->applicationMock->expects($this->any())->method('make')->will($this->returnCallback($makeWill));
     $this->ghostService->register();
     $this->commonGhostService->register();
 }
Exemplo n.º 22
0
 /**
  * @param $method
  * @param $resourceName
  * @param $uri
  * @param $inputs
  * @param $key
  * @param $signature
  * @throws APIException
  * @return mixed
  */
 public function call($method, $resourceName, $uri, $inputs, $key, $signature)
 {
     // Get resource data containing: action and arguments
     $resourceData = ResourceData::make($uri, $method);
     // If can't get resource by name from the respoitory throw an exception because resource doesn't exists
     if (!($resource = $this->app->make('Lifeentity\\Api\\ResourceRepository')->getByName($resourceName))) {
         throw new APIException("We can't find this resource in our application: {{$resourceName}}");
     }
     // Get application by the api key
     if (!($application = $this->app->make('Lifeentity\\Api\\APIApplication')->byApiKey($key)->first())) {
         throw new APIPermissionException("The api key is incorrect.");
     }
     // Check signature
     if (!$application->checkSignature($signature)) {
         throw new APIPermissionException("The api signature is incorrect.");
     }
     // Check if this application has permissions to access this resource and action
     if (!$application->checkPermissions($resource->name(), $resourceData->getAction())) {
         throw new APIPermissionException("You don't have permissions to request `{$resourceData->getAction()}` on this resource: {{$resource->name()}}");
     }
     // Set inputs for this resource
     $resource->setInputs(new InputData($inputs));
     // Now every thing is ready, call this resource
     return $resource->call($resourceData);
 }
 public function testRegister()
 {
     $provider = new InlinerServiceProvider($this->app);
     $provider->register();
     $this->assertTrue($this->app->bound('Chromabits\\Illuminated\\Contracts\\Inliner\\StyleInliner'));
     $this->assertInstanceOf('Chromabits\\Illuminated\\Contracts\\Inliner\\StyleInliner', $this->app->make('Chromabits\\Illuminated\\Contracts\\Inliner\\StyleInliner'));
 }
Exemplo n.º 24
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);
 }
Exemplo n.º 25
0
 /**
  * Create a new Console application.
  *
  * @param  \Illuminate\Foundation\Application  $app
  * @return \Illuminate\Console\Application
  */
 public static function make($app)
 {
     $app->boot();
     $console = with($console = new static('Laravel Framework', $app::VERSION))->setLaravel($app)->setExceptionHandler($app['exception'])->setAutoExit(false);
     $app->instance('artisan', $console);
     return $console;
 }
Exemplo n.º 26
0
 /**
  * Register the module service provider.
  *
  * @param array $module
  *
  * @return void
  */
 private function registerServiceProvider($module)
 {
     $serviceProvider = module_class($module['slug'], 'Providers\\ModuleServiceProvider');
     if (class_exists($serviceProvider)) {
         $this->app->register($serviceProvider);
     }
 }
Exemplo n.º 27
0
 public function getReset($token = null)
 {
     if (is_null($token)) {
         $this->application->abort(404);
     }
     return $this->view->make('UserManagement::password.reset')->with('token', $token);
 }
Exemplo n.º 28
0
 /**
  * Handle the event.
  */
 public function handle()
 {
     if ($locale = $this->preferences->get('streams::locale')) {
         $this->application->setLocale($locale);
         $this->config->set('app.locale', $locale);
     }
 }
 public function process(LocalezeRequest $request)
 {
     $username = $this->app->make('config')->get('laravel-localeze::username');
     $password = $this->app->make('config')->get('laravel-localeze::password');
     $response = $this->soap->query(["origination" => $this->setupOrigination($username, $password), "transId" => 1, "serviceId" => $this->serviceId, "elements" => $request->elements, "serviceKeys" => $request->serviceKeys]);
     return new LocalezeResponse($response);
 }
Exemplo n.º 30
0
 function it_handles_a_command(Application $app, CommandStub $command, CommandTranslator $translator, CommandHandlerStub $handler)
 {
     $translator->toCommandHandler($command)->willReturn('CommandHandler');
     $app->make('CommandHandler')->willReturn($handler);
     $handler->handle($command)->shouldBeCalled();
     $this->execute($command);
 }