TimedPhpEngineTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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\Bundle\FrameworkBundle\Tests\Templating;
  11. use Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables;
  12. use Symfony\Bundle\FrameworkBundle\Templating\TimedPhpEngine;
  13. use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
  14. use Symfony\Component\DependencyInjection\Container;
  15. class TimedPhpEngineTest extends TestCase
  16. {
  17. public function testThatRenderLogsTime()
  18. {
  19. $container = $this->getContainer();
  20. $templateNameParser = $this->getTemplateNameParser();
  21. $globalVariables = $this->getGlobalVariables();
  22. $loader = $this->getLoader($this->getStorage());
  23. $stopwatch = $this->getStopwatch();
  24. $stopwatchEvent = $this->getStopwatchEvent();
  25. $stopwatch->expects($this->once())
  26. ->method('start')
  27. ->with('template.php (index.php)', 'template')
  28. ->will($this->returnValue($stopwatchEvent));
  29. $stopwatchEvent->expects($this->once())->method('stop');
  30. $engine = new TimedPhpEngine($templateNameParser, $container, $loader, $stopwatch, $globalVariables);
  31. $engine->render('index.php');
  32. }
  33. /**
  34. * @return Container
  35. */
  36. private function getContainer()
  37. {
  38. return $this->getMockBuilder('Symfony\Component\DependencyInjection\Container')->getMock();
  39. }
  40. /**
  41. * @return \Symfony\Component\Templating\TemplateNameParserInterface
  42. */
  43. private function getTemplateNameParser()
  44. {
  45. $templateReference = $this->getMockBuilder('Symfony\Component\Templating\TemplateReferenceInterface')->getMock();
  46. $templateNameParser = $this->getMockBuilder('Symfony\Component\Templating\TemplateNameParserInterface')->getMock();
  47. $templateNameParser->expects($this->any())
  48. ->method('parse')
  49. ->will($this->returnValue($templateReference));
  50. return $templateNameParser;
  51. }
  52. /**
  53. * @return GlobalVariables
  54. */
  55. private function getGlobalVariables()
  56. {
  57. return $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables')
  58. ->disableOriginalConstructor()
  59. ->getMock();
  60. }
  61. /**
  62. * @return \Symfony\Component\Templating\Storage\StringStorage
  63. */
  64. private function getStorage()
  65. {
  66. return $this->getMockBuilder('Symfony\Component\Templating\Storage\StringStorage')
  67. ->disableOriginalConstructor()
  68. ->getMockForAbstractClass();
  69. }
  70. /**
  71. * @param \Symfony\Component\Templating\Storage\StringStorage $storage
  72. *
  73. * @return \Symfony\Component\Templating\Loader\Loader
  74. */
  75. private function getLoader($storage)
  76. {
  77. $loader = $this->getMockForAbstractClass('Symfony\Component\Templating\Loader\Loader');
  78. $loader->expects($this->once())
  79. ->method('load')
  80. ->will($this->returnValue($storage));
  81. return $loader;
  82. }
  83. /**
  84. * @return \Symfony\Component\Stopwatch\StopwatchEvent
  85. */
  86. private function getStopwatchEvent()
  87. {
  88. return $this->getMockBuilder('Symfony\Component\Stopwatch\StopwatchEvent')
  89. ->disableOriginalConstructor()
  90. ->getMock();
  91. }
  92. /**
  93. * @return \Symfony\Component\Stopwatch\Stopwatch
  94. */
  95. private function getStopwatch()
  96. {
  97. return $this->getMockBuilder('Symfony\Component\Stopwatch\Stopwatch')->getMock();
  98. }
  99. }