1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12use Twig\RuntimeLoader\ContainerRuntimeLoader;
13
14class Twig_Tests_ContainerRuntimeLoaderTest extends \PHPUnit\Framework\TestCase
15{
16    /**
17     * @requires PHP 5.3
18     */
19    public function testLoad()
20    {
21        $container = $this->getMockBuilder('Psr\Container\ContainerInterface')->getMock();
22        $container->expects($this->once())->method('has')->with('stdClass')->willReturn(true);
23        $container->expects($this->once())->method('get')->with('stdClass')->willReturn(new \stdClass());
24
25        $loader = new ContainerRuntimeLoader($container);
26
27        $this->assertInstanceOf('stdClass', $loader->load('stdClass'));
28    }
29
30    /**
31     * @requires PHP 5.3
32     */
33    public function testLoadUnknownRuntimeReturnsNull()
34    {
35        $container = $this->getMockBuilder('Psr\Container\ContainerInterface')->getMock();
36        $container->expects($this->once())->method('has')->with('Foo');
37        $container->expects($this->never())->method('get');
38
39        $loader = new ContainerRuntimeLoader($container);
40        $this->assertNull($loader->load('Foo'));
41    }
42}
43