Example #1
0
 public function testCompileMethodWithoutRouteName()
 {
     $expectedService = "controller.sample_classwithoutcontaineraware";
     //Setup and run class annotation to ensure global state
     $reflClass = new \ReflectionClass('Sample\\ClassWithoutContainerAware');
     $classAnnotations = [];
     $classAnnotations[] = $classAnnotation = new Annotation\Route();
     $classAnnotation->path = "/foo";
     $this->compiler->compileClass($reflClass, $classAnnotations);
     //Setup method annotations
     $reflMethod = $reflClass->getMethod('fooMethod');
     $annotations = [];
     $annotations[] = $routeAnnotation = new Annotation\Route();
     //No name given, expecting a defualt name
     $routeAnnotation->path = "/baz";
     $routeAnnotation->methods = ["PUT"];
     $this->compiler->compileMethod($reflClass, $reflMethod, $annotations);
     /** @var $controllerCollection \Silex\ControllerCollection */
     $controllerCollection = $this->app['controllers'];
     $routes = $controllerCollection->flush();
     $route = $routes->get("sample_classwithoutcontaineraware_foomethod");
     $this->assertNotNull($route, 'Found route with expected name');
     $this->assertEquals('/foo/baz', $route->getPath(), 'Path includes parent path from controller annotation');
     $this->assertEquals(["PUT"], $route->getMethods(), 'Expected methods set');
     $this->assertEquals('bar', $route->getDefault('foo'), 'Default value inferred from reflection method');
 }