init without trunk

This commit is contained in:
Kevin Adametz 2020-07-09 12:49:32 +02:00
parent ed24ac4994
commit bb809e7233
14652 changed files with 177862 additions and 94817 deletions

View file

@ -0,0 +1,66 @@
<?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 Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Compiler;
use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\AddProcessorsPass;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
class AddProcessorsPassTest extends \PHPUnit_Framework_TestCase
{
public function testHandlerProcessors()
{
$container = $this->getContainer();
$service = $container->getDefinition('monolog.handler.test');
$calls = $service->getMethodCalls();
$this->assertCount(1, $calls);
$this->assertEquals(array('pushProcessor', array(new Reference('test'))), $calls[0]);
$service = $container->getDefinition('handler_test');
$calls = $service->getMethodCalls();
$this->assertCount(1, $calls);
$this->assertEquals(array('pushProcessor', array(new Reference('test2'))), $calls[0]);
}
protected function getContainer()
{
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config'));
$loader->load('monolog.xml');
$definition = $container->getDefinition('monolog.logger_prototype');
$container->setDefinition('monolog.handler.test', new Definition('%monolog.handler.null.class%', array (100, false)));
$container->setDefinition('handler_test', new Definition('%monolog.handler.null.class%', array (100, false)));
$container->setAlias('monolog.handler.test2', 'handler_test');
$definition->addMethodCall('pushHandler', array(new Reference('monolog.handler.test')));
$definition->addMethodCall('pushHandler', array(new Reference('monolog.handler.test2')));
$service = new Definition('TestClass', array('false', new Reference('logger')));
$service->addTag('monolog.processor', array ('handler' => 'test'));
$container->setDefinition('test', $service);
$service = new Definition('TestClass', array('false', new Reference('logger')));
$service->addTag('monolog.processor', array ('handler' => 'test2'));
$container->setDefinition('test2', $service);
$container->getCompilerPassConfig()->setOptimizationPasses(array());
$container->getCompilerPassConfig()->setRemovingPasses(array());
$container->addCompilerPass(new AddProcessorsPass());
$container->compile();
return $container;
}
}

View file

@ -0,0 +1,87 @@
<?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 Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Compiler;
use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\AddSwiftMailerTransportPass;
use Symfony\Component\DependencyInjection\Reference;
/**
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
class AddSwiftMailerTransportPassTest extends \PHPUnit_Framework_TestCase
{
private $compilerPass;
private $container;
private $definition;
protected function setUp()
{
$this->compilerPass = new AddSwiftMailerTransportPass();
$this->definition = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Definition')->getMock();
$this->definition->expects($this->any())
->method('getArgument')
->with(0)
->will($this->returnValue(new Reference('swiftmailer')));
$this->container = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerBuilder')
->setMethods(array('getParameter', 'getDefinition', 'hasDefinition', 'addMethodCall'))->getMock();
$this->container->expects($this->any())
->method('getParameter')
->with('monolog.swift_mailer.handlers')
->will($this->returnValue(array('foo')));
$this->container->expects($this->any())
->method('getDefinition')
->with('foo')
->will($this->returnValue($this->definition));
}
public function testWithRealTransport()
{
$this->container
->expects($this->any())
->method('hasDefinition')
->with('swiftmailer.transport.real')
->will($this->returnValue(true));
$this->definition
->expects($this->once())
->method('addMethodCall')
->with(
'setTransport',
$this->equalTo(array(new Reference('swiftmailer.transport.real')))
);
$this->compilerPass->process($this->container);
}
public function testWithoutRealTransport()
{
$this->container
->expects($this->any())
->method('hasDefinition')
->will($this->returnValueMap(
array(
array('swiftmailer.transport.real', false),
array('swiftmailer.transport', true),
)
));
$this->definition
->expects($this->once())
->method('addMethodCall')
->with(
'setTransport',
$this->equalTo(array(new Reference('swiftmailer.transport')))
);
$this->compilerPass->process($this->container);
}
}

View file

@ -0,0 +1,39 @@
<?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 Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Compiler;
use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\FixEmptyLoggerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class FixEmptyLoggerPassTest extends \PHPUnit_Framework_TestCase
{
public function testProcess()
{
$loggerChannelPass = $this->getMockBuilder('Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass')->getMock();
$loggerChannelPass->expects($this->any())->method('getChannels')->will($this->returnValue(array('foo', 'bar')));
$container = new ContainerBuilder();
$container->register('monolog.logger.foo', 'Monolog\Logger');
$container->register('monolog.logger.bar', 'Monolog\Logger')->addMethodCall('pushHandler');
$pass = new FixEmptyLoggerPass($loggerChannelPass);
$pass->process($container);
$calls = $container->getDefinition('monolog.logger.foo')->getMethodCalls();
$this->assertCount(1, $calls);
$this->assertSame('pushHandler', $calls[0][0]);
$this->assertSame('monolog.handler.null_internal', (string) $calls[0][1][0]);
$calls = $container->getDefinition('monolog.logger.bar')->getMethodCalls();
$this->assertCount(1, $calls);
}
}

View file

@ -0,0 +1,132 @@
<?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 Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
class LoggerChannelPassTest extends \PHPUnit_Framework_TestCase
{
public function testProcess()
{
$container = $this->getContainer();
$this->assertTrue($container->hasDefinition('monolog.logger.test'), '->process adds a logger service for tagged service');
$service = $container->getDefinition('test');
$this->assertEquals('monolog.logger.test', (string) $service->getArgument(1), '->process replaces the logger by the new one');
// pushHandlers for service "test"
$expected = array(
'test' => array('monolog.handler.a', 'monolog.handler.b', 'monolog.handler.c'),
'foo' => array('monolog.handler.b'),
'bar' => array('monolog.handler.b', 'monolog.handler.c'),
);
foreach ($expected as $serviceName => $handlers) {
$service = $container->getDefinition($serviceName);
$channel = $container->getDefinition((string) $service->getArgument(1));
$calls = $channel->getMethodCalls();
$this->assertCount(count($handlers), $calls);
foreach ($handlers as $i => $handler) {
list($methodName, $arguments) = $calls[$i];
$this->assertEquals('pushHandler', $methodName);
$this->assertCount(1, $arguments);
$this->assertEquals($handler, (string) $arguments[0]);
}
}
$this->assertNotNull($container->getDefinition('monolog.logger.manualchan'));
}
public function testProcessSetters()
{
$container = $this->getContainerWithSetter();
$this->assertTrue($container->hasDefinition('monolog.logger.test'), '->process adds a logger service for tagged service');
$service = $container->getDefinition('foo');
$calls = $service->getMethodCalls();
$this->assertEquals('monolog.logger.test', (string) $calls[0][1][0], '->process replaces the logger by the new one in setters');
}
protected function getContainer()
{
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config'));
$loader->load('monolog.xml');
$definition = $container->getDefinition('monolog.logger_prototype');
$container->set('monolog.handler.test', new Definition('%monolog.handler.null.class%', array (100, false)));
$definition->addMethodCall('pushHandler', array(new Reference('monolog.handler.test')));
// Handlers
$container->set('monolog.handler.a', new Definition('%monolog.handler.null.class%', array (100, false)));
$container->set('monolog.handler.b', new Definition('%monolog.handler.null.class%', array (100, false)));
$container->set('monolog.handler.c', new Definition('%monolog.handler.null.class%', array (100, false)));
// Channels
foreach (array('test', 'foo', 'bar') as $name) {
$service = new Definition('TestClass', array('false', new Reference('logger')));
$service->addTag('monolog.logger', array ('channel' => $name));
$container->setDefinition($name, $service);
}
$container->setParameter('monolog.additional_channels', array('manualchan'));
$container->setParameter('monolog.handlers_to_channels', array(
'monolog.handler.a' => array(
'type' => 'inclusive',
'elements' => array('test')
),
'monolog.handler.b' => null,
'monolog.handler.c' => array(
'type' => 'exclusive',
'elements' => array('foo')
)
));
$container->getCompilerPassConfig()->setOptimizationPasses(array());
$container->getCompilerPassConfig()->setRemovingPasses(array());
$container->addCompilerPass(new LoggerChannelPass());
$container->compile();
return $container;
}
protected function getContainerWithSetter()
{
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config'));
$loader->load('monolog.xml');
$definition = $container->getDefinition('monolog.logger_prototype');
$container->set('monolog.handler.test', new Definition('%monolog.handler.null.class%', array (100, false)));
$definition->addMethodCall('pushHandler', array(new Reference('monolog.handler.test')));
// Channels
$service = new Definition('TestClass');
$service->addTag('monolog.logger', array ('channel' => 'test'));
$service->addMethodCall('setLogger', array(new Reference('logger')));
$container->setDefinition('foo', $service);
$container->setParameter('monolog.additional_channels', array('manualchan'));
$container->setParameter('monolog.handlers_to_channels', array());
$container->getCompilerPassConfig()->setOptimizationPasses(array());
$container->getCompilerPassConfig()->setRemovingPasses(array());
$container->addCompilerPass(new LoggerChannelPass());
$container->compile();
return $container;
}
}