PsrServerRequestResolverTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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\Bridge\PsrHttpMessage\Tests\ArgumentValueResolver;
  11. use PHPUnit\Framework\TestCase;
  12. use Psr\Http\Message\MessageInterface;
  13. use Psr\Http\Message\RequestInterface;
  14. use Psr\Http\Message\ServerRequestInterface;
  15. use Symfony\Bridge\PsrHttpMessage\ArgumentValueResolver\PsrServerRequestResolver;
  16. use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
  19. /**
  20. * @author Alexander M. Turek <me@derrabus.de>
  21. */
  22. final class PsrServerRequestResolverTest extends TestCase
  23. {
  24. public function testServerRequest()
  25. {
  26. $symfonyRequest = $this->createMock(Request::class);
  27. $psrRequest = $this->createMock(ServerRequestInterface::class);
  28. $resolver = $this->bootstrapResolver($symfonyRequest, $psrRequest);
  29. self::assertSame([$psrRequest], $resolver->getArguments($symfonyRequest, static function (ServerRequestInterface $serverRequest): void {}));
  30. }
  31. public function testRequest()
  32. {
  33. $symfonyRequest = $this->createMock(Request::class);
  34. $psrRequest = $this->createMock(ServerRequestInterface::class);
  35. $resolver = $this->bootstrapResolver($symfonyRequest, $psrRequest);
  36. self::assertSame([$psrRequest], $resolver->getArguments($symfonyRequest, static function (RequestInterface $request): void {}));
  37. }
  38. public function testMessage()
  39. {
  40. $symfonyRequest = $this->createMock(Request::class);
  41. $psrRequest = $this->createMock(ServerRequestInterface::class);
  42. $resolver = $this->bootstrapResolver($symfonyRequest, $psrRequest);
  43. self::assertSame([$psrRequest], $resolver->getArguments($symfonyRequest, static function (MessageInterface $request): void {}));
  44. }
  45. private function bootstrapResolver(Request $symfonyRequest, ServerRequestInterface $psrRequest): ArgumentResolver
  46. {
  47. $messageFactory = $this->createMock(HttpMessageFactoryInterface::class);
  48. $messageFactory->expects(self::once())
  49. ->method('createRequest')
  50. ->with(self::identicalTo($symfonyRequest))
  51. ->willReturn($psrRequest);
  52. return new ArgumentResolver(null, [new PsrServerRequestResolver($messageFactory)]);
  53. }
  54. }