TraceableArgumentResolverTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 Controller;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
  14. use Symfony\Component\HttpKernel\Controller\TraceableArgumentResolver;
  15. use Symfony\Component\Stopwatch\Stopwatch;
  16. use Symfony\Component\Stopwatch\StopwatchEvent;
  17. class TraceableArgumentResolverTest extends TestCase
  18. {
  19. public function testStopwatchEventIsStoppedWhenResolverThrows()
  20. {
  21. $stopwatchEvent = $this->createMock(StopwatchEvent::class);
  22. $stopwatchEvent->expects(self::once())->method('stop');
  23. $stopwatch = $this->createStub(Stopwatch::class);
  24. $stopwatch->method('start')->willReturn($stopwatchEvent);
  25. $resolver = new class() implements ArgumentResolverInterface {
  26. public function getArguments(Request $request, callable $controller)
  27. {
  28. throw new \Exception();
  29. }
  30. };
  31. $traceableResolver = new TraceableArgumentResolver($resolver, $stopwatch);
  32. try {
  33. $traceableResolver->getArguments(new Request(), function () {});
  34. } catch (\Exception $ex) {
  35. }
  36. }
  37. }