HttpKernelTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\HttpKernel;
  11. use Symfony\Component\HttpKernel\HttpKernel;
  12. use Symfony\Component\HttpKernel\HttpKernelInterface;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\EventDispatcher\EventDispatcher;
  16. class HttpKernelTest extends \PHPUnit_Framework_TestCase
  17. {
  18. public function testHandleGetsTheRequestFromTheContainer()
  19. {
  20. $request = Request::create('/');
  21. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  22. $container->expects($this->any())
  23. ->method('get')
  24. ->will($this->returnValue($request))
  25. ;
  26. $kernel = new HttpKernel($container, new EventDispatcher(), $this->getResolver());
  27. $kernel->handle();
  28. $this->assertEquals($request, $kernel->getRequest());
  29. }
  30. public function testHandleSetsTheRequestIfPassed()
  31. {
  32. $request = Request::create('/');
  33. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  34. $container->expects($this->exactly(2))
  35. ->method('set')
  36. ->with('request', $request)
  37. ;
  38. $kernel = new HttpKernel($container, new EventDispatcher(), $this->getResolver());
  39. $kernel->handle($request);
  40. }
  41. protected function getResolver($controller = null)
  42. {
  43. if (null === $controller) {
  44. $controller = function () { return new Response('Hello'); };
  45. }
  46. $resolver = $this->getMock('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface');
  47. $resolver->expects($this->any())
  48. ->method('getController')
  49. ->will($this->returnValue($controller))
  50. ;
  51. $resolver->expects($this->any())
  52. ->method('getArguments')
  53. ->will($this->returnValue(array()))
  54. ;
  55. return $resolver;
  56. }
  57. }