ContainerAwareRuntimeLoaderTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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\TwigBundle\Tests;
  11. use Psr\Log\LoggerInterface;
  12. use Symfony\Component\DependencyInjection\ContainerInterface;
  13. use Symfony\Bundle\TwigBundle\ContainerAwareRuntimeLoader;
  14. class ContainerAwareRuntimeLoaderTest extends TestCase
  15. {
  16. public function testLoad()
  17. {
  18. $container = $this->getMockBuilder(ContainerInterface::class)->getMock();
  19. $container->expects($this->once())->method('get')->with('foo');
  20. $loader = new ContainerAwareRuntimeLoader($container, array(
  21. 'FooClass' => 'foo',
  22. ));
  23. $loader->load('FooClass');
  24. }
  25. public function testLoadWithoutAMatch()
  26. {
  27. $logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
  28. $logger->expects($this->once())->method('warning')->with('Class "BarClass" is not configured as a Twig runtime. Add the "twig.runtime" tag to the related service in the container.');
  29. $loader = new ContainerAwareRuntimeLoader($this->getMockBuilder(ContainerInterface::class)->getMock(), array(), $logger);
  30. $this->assertNull($loader->load('BarClass'));
  31. }
  32. }