ClosureLoaderTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\Component\DependencyInjection\Tests\Loader;
  11. use Symfony\Component\DependencyInjection\ContainerBuilder;
  12. use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
  13. class ClosureLoaderTest extends \PHPUnit_Framework_TestCase
  14. {
  15. protected function setUp()
  16. {
  17. if (!class_exists('Symfony\Component\Config\Loader\Loader')) {
  18. $this->markTestSkipped('The "Config" component is not available');
  19. }
  20. }
  21. /**
  22. * @covers Symfony\Component\DependencyInjection\Loader\ClosureLoader::supports
  23. */
  24. public function testSupports()
  25. {
  26. $loader = new ClosureLoader(new ContainerBuilder());
  27. $this->assertTrue($loader->supports(function ($container) {}), '->supports() returns true if the resource is loadable');
  28. $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
  29. }
  30. /**
  31. * @covers Symfony\Component\DependencyInjection\Loader\ClosureLoader::load
  32. */
  33. public function testLoad()
  34. {
  35. $loader = new ClosureLoader($container = new ContainerBuilder());
  36. $loader->load(function ($container) {
  37. $container->setParameter('foo', 'foo');
  38. });
  39. $this->assertEquals('foo', $container->getParameter('foo'), '->load() loads a \Closure resource');
  40. }
  41. }