public function testValidObject()
 {
     $object = $this->getMock('Object', array('getId'));
     $validator = new CommentObjectValidator();
     $this->assertEquals($object, $validator->validObject($object), 'Method did not return valid object');
     $invalidObject = $this->getMockClass('Object');
     try {
         $validator->validObject($invalidObject);
         $this->fail('Exception did not thrown for invalid object');
     } catch (\InvalidArgumentException $e) {
         $this->assertEquals(0, $e->getCode(), 'Wrong code');
         $this->assertEquals('Non correct object giving', $e->getMessage(), 'Wrong message for exception');
     }
     $invalidObject = '';
     try {
         $validator->validObject($invalidObject);
         $this->fail('Exception did not thrown for invalid object');
     } catch (\InvalidArgumentException $e) {
         $this->assertEquals(0, $e->getCode(), 'Wrong code');
         $this->assertEquals('Non correct object giving', $e->getMessage(), 'Wrong message for exception');
     }
 }
Exemple #2
0
 public function onKernelController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     if (!is_array($controller)) {
         return;
     }
     list($controllerObject, $method) = $controller;
     $classAnnotation = $this->reader->getClassAnnotation(new ReflectionClass(ClassUtils::getClass($controllerObject)), $this->annotation);
     if ($classAnnotation) {
         // do something
     }
     $reflectionObject = new ReflectionObject($controllerObject);
     $reflectionMethod = $reflectionObject->getMethod($method);
     $methodAnnotation = $this->reader->getMethodAnnotation($reflectionMethod, $this->annotation);
     if ($methodAnnotation) {
         $objName = $methodAnnotation->post;
         $request = $event->getRequest();
         $post = $request->get($objName);
         CommentObjectValidator::validObject($post);
     }
 }