/**
  * @expectedException \LogicException
  * @expectedExceptionMessage The SecurityBundle is not registered in your application.
  */
 public function testGetUserWithEmptyContainer()
 {
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $container->expects($this->once())->method('has')->with('security.token_storage')->will($this->returnValue(false));
     $controller = new TestController();
     $controller->setContainer($container);
     $controller->getUser();
 }
 public function testIsCsrfTokenValid()
 {
     $tokenManager = $this->getMock('Symfony\\Component\\Security\\Csrf\\CsrfTokenManagerInterface');
     $tokenManager->expects($this->once())->method('isTokenValid')->willReturn(true);
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $container->expects($this->at(0))->method('has')->will($this->returnValue(true));
     $container->expects($this->at(1))->method('get')->will($this->returnValue($tokenManager));
     $controller = new TestController();
     $controller->setContainer($container);
     $this->assertTrue($controller->isCsrfTokenValid('foo', 'bar'));
 }
Esempio n. 3
0
 public function testGetDoctrine()
 {
     $doctrine = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ManagerRegistry')->getMock();
     $container = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\ContainerInterface')->getMock();
     $container->expects($this->at(0))->method('has')->will($this->returnValue(true));
     $container->expects($this->at(1))->method('get')->will($this->returnValue($doctrine));
     $controller = new TestController();
     $controller->setContainer($container);
     $this->assertEquals($doctrine, $controller->getDoctrine());
 }
Esempio n. 4
0
 public function testJsonWithSerializerContextOverride()
 {
     $container = $this->getMock(ContainerInterface::class);
     $container->expects($this->once())->method('has')->with('serializer')->will($this->returnValue(true));
     $serializer = $this->getMock(SerializerInterface::class);
     $serializer->expects($this->once())->method('serialize')->with(array(), 'json', array('json_encode_options' => 0, 'other' => 'context'))->will($this->returnValue('[]'));
     $container->expects($this->once())->method('get')->with('serializer')->will($this->returnValue($serializer));
     $controller = new TestController();
     $controller->setContainer($container);
     $response = $controller->json(array(), 200, array(), array('json_encode_options' => 0, 'other' => 'context'));
     $this->assertInstanceOf(JsonResponse::class, $response);
     $this->assertEquals('[]', $response->getContent());
     $response->setEncodingOptions(JSON_FORCE_OBJECT);
     $this->assertEquals('{}', $response->getContent());
 }