/**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function settingUp(array $annotations = null)
 {
     $this->requestHelper = new RequestHelperFixture();
     InvokerConfig::setRequestHelper($this->requestHelper);
     $reflMethod = new ReflectionMethod(InvokeParameterHandlerFixture::class, 'invokedMethod');
     if ($annotations === null) {
         $annotations = array(new Autowired(array()), new RequestParam(array('value' => 'id')));
     }
     $this->object = new InvokeParameterHandler($annotations, $reflMethod);
 }
Example #2
0
 public static function invoke($instance, $methodName, $args = array())
 {
     $className = get_class($instance);
     $reflClass = new ReflectionClass($className);
     if (!$reflClass->hasMethod($methodName)) {
         throw new BadMethodCallException("The '{$methodName}' method is not exists in {$className}");
     }
     $reflMethod = $reflClass->getMethod($methodName);
     $annotations = $reflMethod->getAnnotations();
     foreach (InvokerConfig::getMethodBeforeHandlers($reflMethod) as $methodAnnotationHandler) {
         $methodAnnotationHandler->run($reflMethod, $instance);
     }
     $expectedParameterSize = sizeof($reflMethod->getParameters());
     $invokeParams = (new InvokeParameterHandler($annotations, $reflMethod, $args))->run();
     if ($expectedParameterSize > sizeof($invokeParams)) {
         throw new BadMethodCallException("Not found all expected method parameter: {$className}::{$methodName}()");
     }
     return $reflMethod->invokeArgs($instance, $invokeParams);
 }
Example #3
0
 public function __construct()
 {
     $this->helper = InvokerConfig::getRequestHelper();
 }
 /**
  * 
  * @param ReflectionParameter $parameter
  * @void
  */
 private function handleRequestParam(ReflectionParameter $parameter)
 {
     $parameterName = $parameter->getName();
     if ($this->hasAnnotation(RequestParam::class, array('value' => $parameterName))) {
         $annotation = $this->getAnnotation(RequestParam::class, array('value' => $parameterName));
         if ($annotation instanceof RequestBody) {
             $value = trim(trim(file_get_contents('php://input'), '"'));
         } else {
             $value = InvokerConfig::getRequestHelper()->getParam($parameterName);
         }
         $this->handleRequiredRequestParam($parameter, $annotation, $value);
         if ($annotation->defaultValue !== '****UNDEFINED****' && $value === null) {
             $value = $annotation->defaultValue;
         }
         $this->invokeParams[$parameter->getPosition()] = $value;
     }
 }
Example #5
0
 /**
  * @test
  */
 public function testValidationErrorNotBlankAddressStreet()
 {
     $this->markTestIncomplete('This test has not been implemented yet.');
     $request = InvokerConfig::getRequestHelper();
     $request->setParam('firstName', 'Lobi');
     $request->setParam('lastName', 'Lobi');
     $request->setParam('phones', array('+31644449576', '+36209820644'));
     $request->setParam('address', array('street' => null));
     $ref = new ReflectionClass(ClassInvokerFixture::class);
     $instance = $ref->newInstanceWithoutConstructor();
     MethodInvoker::invoke($instance, 'indexAction');
     $bindingResultProperty = $ref->getProperty('bindingResult');
     $bindingResultProperty->setAccessible(true);
     /* @var $bindingResult BindingResult */
     $bindingResult = $bindingResultProperty->getValue($instance);
     $this->assertEquals(1, count($bindingResult), (string) $bindingResult);
     /* @var $current ConstraintViolation */
     $current = $bindingResult->getIterator()->current();
     $this->assertEquals('address.street', $current->getPropertyPath());
     $this->assertEquals((new NotBlank())->message, $current->getMessage());
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $helper = new RequestHelperFixture();
     $helper->setMethod(RequestMethod::POST | RequestMethod::XMLHTTPREQUEST);
     InvokerConfig::setRequestHelper($helper);
 }