TraceableControllerResolverTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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\ControllerResolverInterface;
  14. use Symfony\Component\HttpKernel\Controller\TraceableControllerResolver;
  15. use Symfony\Component\Stopwatch\Stopwatch;
  16. use Symfony\Component\Stopwatch\StopwatchEvent;
  17. class TraceableControllerResolverTest 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 ControllerResolverInterface {
  26. public function getController(Request $request)
  27. {
  28. throw new \Exception();
  29. }
  30. };
  31. $traceableResolver = new TraceableControllerResolver($resolver, $stopwatch);
  32. try {
  33. $traceableResolver->getController(new Request());
  34. } catch (\Exception $ex) {
  35. }
  36. }
  37. }