Вход Регистрация
Файл: symfony-2.7/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TimedPhpEngineTest.php
Строк: 177
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SymfonyBundleFrameworkBundleTestsTemplating;

use 
SymfonyBundleFrameworkBundleTemplatingTimedPhpEngine;
use 
SymfonyComponentDependencyInjectionContainer;
use 
SymfonyBundleFrameworkBundleTemplatingGlobalVariables;
use 
SymfonyBundleFrameworkBundleTestsTestCase;

class 
TimedPhpEngineTest extends TestCase
{
    public function 
testThatRenderLogsTime()
    {
        
$container $this->getContainer();
        
$templateNameParser $this->getTemplateNameParser();
        
$globalVariables $this->getGlobalVariables();
        
$loader $this->getLoader($this->getStorage());

        
$stopwatch $this->getStopwatch();
        
$stopwatchEvent $this->getStopwatchEvent();

        
$stopwatch->expects($this->once())
            ->
method('start')
            ->
with('template.php (index.php)''template')
            ->
will($this->returnValue($stopwatchEvent));

        
$stopwatchEvent->expects($this->once())->method('stop');

        
$engine = new TimedPhpEngine($templateNameParser$container$loader$stopwatch$globalVariables);
        
$engine->render('index.php');
    }

    
/**
     * @return Container
     */
    
private function getContainer()
    {
        return 
$this->getMock('SymfonyComponentDependencyInjectionContainer');
    }

    
/**
     * @return SymfonyComponentTemplatingTemplateNameParserInterface
     */
    
private function getTemplateNameParser()
    {
        
$templateReference $this->getMock('SymfonyComponentTemplatingTemplateReferenceInterface');
        
$templateNameParser $this->getMock('SymfonyComponentTemplatingTemplateNameParserInterface');
        
$templateNameParser->expects($this->any())
            ->
method('parse')
            ->
will($this->returnValue($templateReference));

        return 
$templateNameParser;
    }

    
/**
     * @return GlobalVariables
     */
    
private function getGlobalVariables()
    {
        return 
$this->getMockBuilder('SymfonyBundleFrameworkBundleTemplatingGlobalVariables')
            ->
disableOriginalConstructor()
            ->
getMock();
    }

    
/**
     * @return SymfonyComponentTemplatingStorageStringStorage
     */
    
private function getStorage()
    {
        return 
$this->getMockBuilder('SymfonyComponentTemplatingStorageStringStorage')
            ->
disableOriginalConstructor()
            ->
getMockForAbstractClass();
    }

    
/**
     * @param SymfonyComponentTemplatingStorageStringStorage $storage
     *
     * @return SymfonyComponentTemplatingLoaderLoader
     */
    
private function getLoader($storage)
    {
        
$loader $this->getMockForAbstractClass('SymfonyComponentTemplatingLoaderLoader');
        
$loader->expects($this->once())
            ->
method('load')
            ->
will($this->returnValue($storage));

        return 
$loader;
    }

    
/**
     * @return SymfonyComponentStopwatchStopwatchEvent
     */
    
private function getStopwatchEvent()
    {
        return 
$this->getMockBuilder('SymfonyComponentStopwatchStopwatchEvent')
            ->
disableOriginalConstructor()
            ->
getMock();
    }

    
/**
     * @return SymfonyComponentStopwatchStopwatch
     */
    
private function getStopwatch()
    {
        return 
$this->getMock('SymfonyComponentStopwatchStopwatch');
    }
}
Онлайн: 2
Реклама