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));
 }
 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();
 }
 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();
 }
 public function testProvides()
 {
     $this->application->expects($this->any())->method('bind')->with(ResolverServiceProvider::PROVIDES_RESOLVER, $this->callback(function ($closure) {
         return $closure($this->application) instanceof Resolver;
     }));
     $this->application->expects($this->any())->method('alias')->with('CommodeResolver', ResolverFacade::class);
     $this->assertContains(ResolverServiceProvider::PROVIDES_RESOLVER, $this->testInstance->provides());
 }
 public function testRegistering()
 {
     $registeringMethodReflection = new \ReflectionMethod($this->commodeService, 'registering');
     $registeringMethodReflection->setAccessible(true);
     $this->applicationMock->expects($this->at(0))->method('bindShared')->with($this->anything(), $this->callback(function ($closure) {
         $this->assertInstanceOf('LaravelCommode\\Common\\Resolver\\Resolver', $closure());
         return true;
     }));
     $this->applicationMock->expects($this->at(1))->method('bindShared')->with($this->anything(), $this->callback(function ($closure) {
         $this->assertInstanceOf('LaravelCommode\\Common\\GhostService\\GhostServices', $closure());
         return true;
     }));
     $registeringMethodReflection->invoke($this->commodeService);
 }
 protected function prepareApplication()
 {
     /**
      * @param $whatToMake
      * @return $this
      * @throws Exception
      */
     $makeWill = function ($whatToMake) {
         switch ($whatToMake) {
             case 'LaravelCommode\\Resolver\\ResolverTest':
                 return $this;
             default:
                 throw new Exception("Unexpected {$whatToMake}");
         }
     };
     $this->applicationMock->expects($this->any())->method('make')->will($this->returnCallback($makeWill));
 }
 public function testRegister()
 {
     $filterRegistry = new FilterRegistry($this->routingMock, $this->resolverMock);
     $this->applicationMock->expects($this->once())->method('bind')->with(FiltersServiceProvider::InterfaceName, FiltersServiceProvider::ConcreteName);
     $this->applicationMock->expects($this->any())->method('make')->with(FiltersServiceProvider::InterfaceName)->will($this->returnCallback(function () use($filterRegistry) {
         return $filterRegistry;
     }));
     $this->applicationMock->expects($this->once())->method('bindShared')->with(FiltersServiceProvider::ServiceName, $this->callback(function ($callback) {
         $fR = $callback($this->applicationMock);
         $isok = $fR instanceof FilterRegistry;
         return true;
     }));
     $this->applicationMock->expects($this->once())->method('before')->will($this->returnCallback(function ($callback) {
         $callback();
         return null;
     }));
     $reflectionMethod = new \ReflectionMethod($this->testedService, 'registering');
     $reflectionMethod->setAccessible(true);
     $reflectionMethod->invokeArgs($this->testedService, []);
     $reflectionMethod = new \ReflectionMethod($this->testedService, 'launching');
     $reflectionMethod->setAccessible(true);
     $reflectionMethod->invokeArgs($this->testedService, []);
 }
 public function testExtract()
 {
     $this->applicationMock->expects($this->at(0))->method('make')->with(get_class($this->testSubject))->will($this->returnValue($this->testSubject));
     $this->filterRegistry->extractArray([get_class($this->testSubject)]);
 }