<commit_before><?php

/*
 * This file is part of the Assetic package, an OpenSky project.
 *
 * (c) 2010-2014 OpenSky Project Inc
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Assetic\Test\Extension\Twig;

use Assetic\Extension\Twig\TwigResource;

class TwigResourceTest extends \PHPUnit_Framework_TestCase
{
    protected function setUp()
    {
        if (!class_exists('Twig_Environment')) {
            $this->markTestSkipped('Twig is not installed.');
        }
    }

    public function testInvalidTemplateNameGetContent()
    {
        if (!method_exists('Twig_LoaderInterface', 'getSource'))
        {
            $this->markTestSkipped('Twig_LoaderInterface does not have method getSource');
        }

        $loader = $this->getMock('Twig_LoaderInterface');
        $loader->expects($this->once())
            ->method('getSource')
            ->with('asdf')
            ->will($this->throwException(new \Twig_Error_Loader('')));

        $resource = new TwigResource($loader, 'asdf');
        $this->assertEquals('', $resource->getContent());
    }

    public function testInvalidTemplateNameIsFresh()
    {
        $loader = $this->getMock('Twig_LoaderInterface');
        $loader->expects($this->once())
            ->method('isFresh')
            ->with('asdf', 1234)
            ->will($this->throwException(new \Twig_Error_Loader('')));

        $resource = new TwigResource($loader, 'asdf');<commit_msg>minor #822 Clean tests for the TwigResource (stof)<commit_after><?php

/*
 * This file is part of the Assetic package, an OpenSky project.
 *
 * (c) 2010-2014 OpenSky Project Inc
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Assetic\Test\Extension\Twig;

use Assetic\Extension\Twig\TwigResource;

class TwigResourceTest extends \PHPUnit_Framework_TestCase
{
    protected function setUp()
    {
        if (!class_exists('Twig_Environment')) {
            $this->markTestSkipped('Twig is not installed.');
        }
    }

    public function testInvalidTemplateNameGetContent()
    {
        $loader = $this->prophesize('Twig_LoaderInterface');
        if (!method_exists('Twig_LoaderInterface', 'getSourceContext')) {
            $loader->willImplement('Twig_SourceContextLoaderInterface');
        }

        $loader->getSourceContext('asdf')->willThrow(new \Twig_Error_Loader(''));

        $resource = new TwigResource($loader->reveal(), 'asdf');
        $this->assertEquals('', $resource->getContent());
    }

    /**
     * @group legacy
     */
    public function testInvalidTemplateNameGetContentWithLegacyLoader()
    {
        if (!method_exists('Twig_LoaderInterface', 'getSource')) {
            $this->markTestSkipped('This test does not make sense on Twig 2.x.');
        }

        $loader = $this->getMock('Twig_LoaderInterface');
        $loader->expects($this->once())
            ->method('getSource')
            ->with('asdf')
            ->will($this->throwException(new \Twig_Error_Loader('')));

        $resource = new TwigResource($loader, 'asdf');
        $this->assertEquals('', $resource->getContent());
    }

    public function testInvalidTemplateNameIsFresh()
    {
        $loader = $this->getMock('Twig_LoaderInterface');
        $loader->expects($this->once())
            ->method('isFresh')
            ->with('asdf', 1234)
            ->will($this->throwException(new \Twig_Error_Loader('')));

        $resource = new TwigResource($loader, 'asdf');
{'fraction_non_alphanumeric': 0.14004982009410463, 'fraction_numerical': 0.0077497924162745644, 'mean_word_length': 2.988962472406181, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7055486', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1009, 'n_words': 214}