/**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app['parameters'] = $this->app->share(function ($app) {
         return new Parameters();
     });
     // Find the default Controller class of the current Laravel application
     $controllerClass = $this->app['config']->get('authority-controller.controllerClass', 'Illuminate\\Routing\\Controller');
     $this->app->resolving(function ($object) use($controllerClass) {
         // Check if the current $object class is a Controller class and if it responds to paramsBeforeFilter method
         if (is_a($object, $controllerClass) && respond_to($object, 'paramsBeforeFilter')) {
             // Fill $params properties of the current controller
             $this->app['parameters']->fillController($object);
         }
     });
     $this->app['authority'] = $this->app->share(function ($app) {
         $user = $app['auth']->user();
         $authority = new Authority($user);
         $fn = $app['config']->get('authority-controller.initialize');
         $serializer = new Serializer();
         if (is_string($fn)) {
             $fn = $serializer->unserialize($fn);
         }
         if ($fn) {
             $fn($authority);
         }
         return $authority;
     });
     $this->app->bind('Efficiently\\AuthorityController\\ControllerResource', function ($app, $parameters) {
         list($controller, $resourceName, $resourceOptions) = $parameters;
         return new ControllerResource($controller, $resourceName, $resourceOptions);
     });
 }
 public function testRespondTo()
 {
     $mock = m::mock('Project');
     $this->assertFalse(method_exists($mock, 'toto'));
     $this->assertFalse(respond_to($mock, 'toto'));
     $mock->shouldReceive('toto');
     $this->assertFalse(method_exists($mock, 'toto'));
     $this->assertTrue(respond_to($mock, 'toto'));
 }
 protected function mock($className)
 {
     $mock = m::mock($className);
     App::bind($className, function ($app, $parameters = []) use($mock) {
         if (is_array($parameters) && is_array($attributes = array_get($parameters, 0, [])) && respond_to($mock, "fill")) {
             $mock = $this->fillMock($mock, $attributes);
         }
         return $mock;
     });
     return $mock;
 }
 /**
  * Like method_exists function but compatible with Mockery
  *
  * @param  mixed   $object
  * @param  string  $methodName
  * @return boolean
  */
 function respond_to($object, $methodName)
 {
     if (method_exists($object, $methodName)) {
         return true;
     } elseif (is_a($object, '\\Mockery\\MockInterface') && ($expectationDirector = array_get($object->mockery_getExpectations(), $methodName))) {
         foreach ((array) $expectationDirector->getExpectations() as $expectation) {
             if ($expectation->isEligible()) {
                 return true;
             }
         }
     } elseif (is_string($object) && class_exists($object) && is_a($instance = app($object), '\\Mockery\\MockInterface')) {
         // Check if a mocked static method exists or not. You need to do:
         //
         //   $category = Mockery::mock('alias:Category', ['getProducts'=>'products']);
         //   App::instance('Category', $category);
         //   respond_to('Category', 'getProducts');//-> true
         return respond_to($instance, $methodName);
     }
     return false;
 }
 protected function fetchParent($name)
 {
     $name = camel_case($name);
     if (property_exists($this->controller, $name)) {
         return get_property($this->controller, $name);
     } elseif (respond_to($this->controller, "get" . studly_case($name))) {
         $name = "get" . studly_case($name);
         return $this->controller->{$name}();
     } elseif (respond_to($this->controller, $name)) {
         return $this->controller->{$name}();
     }
 }