Вход Регистрация
Файл: symfony-2.7/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php
Строк: 327
<?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 SymfonyBundleFrameworkBundleTestsConsoleDescriptor;

use 
SymfonyComponentConsoleOutputBufferedOutput;
use 
SymfonyComponentDependencyInjectionAlias;
use 
SymfonyComponentDependencyInjectionContainerBuilder;
use 
SymfonyComponentDependencyInjectionDefinition;
use 
SymfonyComponentDependencyInjectionParameterBagParameterBag;
use 
SymfonyComponentEventDispatcherEventDispatcher;
use 
SymfonyComponentRoutingRoute;
use 
SymfonyComponentRoutingRouteCollection;

abstract class 
AbstractDescriptorTest extends PHPUnit_Framework_TestCase
{
    
/** @dataProvider getDescribeRouteCollectionTestData */
    
public function testDescribeRouteCollection(RouteCollection $routes$expectedDescription)
    {
        
$this->assertDescription($expectedDescription$routes);
    }

    public function 
getDescribeRouteCollectionTestData()
    {
        return 
$this->getDescriptionTestData(ObjectsProvider::getRouteCollections());
    }

    
/** @dataProvider getDescribeRouteTestData */
    
public function testDescribeRoute(Route $route$expectedDescription)
    {
        
$this->assertDescription($expectedDescription$route);
    }

    public function 
getDescribeRouteTestData()
    {
        return 
$this->getDescriptionTestData(ObjectsProvider::getRoutes());
    }

    
/** @dataProvider getDescribeContainerParametersTestData */
    
public function testDescribeContainerParameters(ParameterBag $parameters$expectedDescription)
    {
        
$this->assertDescription($expectedDescription$parameters);
    }

    public function 
getDescribeContainerParametersTestData()
    {
        return 
$this->getDescriptionTestData(ObjectsProvider::getContainerParameters());
    }

    
/** @dataProvider getDescribeContainerBuilderTestData */
    
public function testDescribeContainerBuilder(ContainerBuilder $builder$expectedDescription, array $options)
    {
        
$this->assertDescription($expectedDescription$builder$options);
    }

    public function 
getDescribeContainerBuilderTestData()
    {
        return 
$this->getContainerBuilderDescriptionTestData(ObjectsProvider::getContainerBuilders());
    }

    
/** @dataProvider provideLegacySynchronizedServiceDefinitionTestData */
    
public function testLegacyDescribeSynchronizedServiceDefinition(Definition $definition$expectedDescription)
    {
        
$this->iniSet('error_reporting', -& ~E_USER_DEPRECATED);

        
$this->assertDescription($expectedDescription$definition);
    }

    public function 
provideLegacySynchronizedServiceDefinitionTestData()
    {
        
$this->iniSet('error_reporting', -& ~E_USER_DEPRECATED);

        return 
$this->getDescriptionTestData(ObjectsProvider::getLegacyContainerDefinitions());
    }

    
/** @dataProvider getDescribeContainerDefinitionTestData */
    
public function testDescribeContainerDefinition(Definition $definition$expectedDescription)
    {
        
$this->assertDescription($expectedDescription$definition);
    }

    public function 
getDescribeContainerDefinitionTestData()
    {
        return 
$this->getDescriptionTestData(ObjectsProvider::getContainerDefinitions());
    }

    
/** @dataProvider getDescribeContainerAliasTestData */
    
public function testDescribeContainerAlias(Alias $alias$expectedDescription)
    {
        
$this->assertDescription($expectedDescription$alias);
    }

    public function 
getDescribeContainerAliasTestData()
    {
        return 
$this->getDescriptionTestData(ObjectsProvider::getContainerAliases());
    }

    
/** @dataProvider getDescribeContainerParameterTestData */
    
public function testDescribeContainerParameter($parameter$expectedDescription, array $options)
    {
        
$this->assertDescription($expectedDescription$parameter$options);
    }

    public function 
getDescribeContainerParameterTestData()
    {
        
$data $this->getDescriptionTestData(ObjectsProvider::getContainerParameter());

        
array_push($data[0], array('parameter' => 'database_name'));

        return 
$data;
    }

    
/** @dataProvider getDescribeEventDispatcherTestData */
    
public function testDescribeEventDispatcher(EventDispatcher $eventDispatcher$expectedDescription, array $options)
    {
        
$this->assertDescription($expectedDescription$eventDispatcher$options);
    }

    public function 
getDescribeEventDispatcherTestData()
    {
        return 
$this->getEventDispatcherDescriptionTestData(ObjectsProvider::getEventDispatchers());
    }

    
/** @dataProvider getDescribeCallableTestData */
    
public function testDescribeCallable($callable$expectedDescription)
    {
        
$this->assertDescription($expectedDescription$callable);
    }

    public function 
getDescribeCallableTestData()
    {
        return 
$this->getDescriptionTestData(ObjectsProvider::getCallables());
    }

    abstract protected function 
getDescriptor();
    abstract protected function 
getFormat();

    private function 
assertDescription($expectedDescription$describedObject, array $options = array())
    {
        
$options['raw_output'] = true;
        
$output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMALtrue);
        
$this->getDescriptor()->describe($output$describedObject$options);

        if (
'json' === $this->getFormat()) {
            
$this->assertEquals(json_decode($expectedDescription), json_decode($output->fetch()));
        } else {
            
$this->assertEquals(trim($expectedDescription), trim(str_replace(PHP_EOL"n"$output->fetch())));
        }
    }

    private function 
getDescriptionTestData(array $objects)
    {
        
$data = array();
        foreach (
$objects as $name => $object) {
            
$description file_get_contents(sprintf('%s/../../Fixtures/Descriptor/%s.%s'__DIR__$name$this->getFormat()));
            
$data[] = array($object$description);
        }

        return 
$data;
    }

    private function 
getContainerBuilderDescriptionTestData(array $objects)
    {
        
$variations = array(
            
'services' => array('show_private' => true),
            
'public' => array('show_private' => false),
            
'tag1' => array('show_private' => true'tag' => 'tag1'),
            
'tags' => array('group_by' => 'tags''show_private' => true),
        );

        
$data = array();
        foreach (
$objects as $name => $object) {
            foreach (
$variations as $suffix => $options) {
                
$description file_get_contents(sprintf('%s/../../Fixtures/Descriptor/%s_%s.%s'__DIR__$name$suffix$this->getFormat()));
                
$data[] = array($object$description$options);
            }
        }

        return 
$data;
    }

    private function 
getEventDispatcherDescriptionTestData(array $objects)
    {
        
$variations = array(
            
'events' => array(),
            
'event1' => array('event' => 'event1'),
        );

        
$data = array();
        foreach (
$objects as $name => $object) {
            foreach (
$variations as $suffix => $options) {
                
$description file_get_contents(sprintf('%s/../../Fixtures/Descriptor/%s_%s.%s'__DIR__$name$suffix$this->getFormat()));
                
$data[] = array($object$description$options);
            }
        }

        return 
$data;
    }
}
Онлайн: 0
Реклама