<commit_before><?php
/**
 * This file is a part of the Event-Band project
 * @author <NAME>
 * @author <NAME> Kulakov <<EMAIL>>
 */

namespace EventBand\Bundle\Tests\DependencyInjection;

use EventBand\Bundle\DependencyInjection\AmqpConfiguration;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;

/**
 * Class AmqpConfigurationTest
 *
 * @author <NAME> <<EMAIL>>
 */
class AmqpConfigurationTest extends SectionConfigurationTestCase
{
    /**
     * {@inheritDoc}
     */
    protected function createSection()
    {
        return new AmqpConfiguration();
    }

    /**
     * @test default values for empty config
     */
    public function defaultValues()
    {
        $config = $this->processSection([]);

        $this->assertEquals(
            [
                'driver' => 'amqplib',
                'use_tracer_interceptor' => false,
                'connections' => [
                    'default' => AmqpConfiguration::getDefaultConnection()
                ],
                'converters' => [
                    'default' => [
                        'type' => 'serialize',
                        'parameters' => [
                            'serializer' => 'default'
                        ]
                    ]
                ]
            ],
            $config
        );
    }

    /**
     * @test all connection options can be set
     */
    public function connectionOptions()
    {
        $connections = [
            'default' => [
                'host' => 'def',
                'port' => '100',
                'virtual_host' => 'vh',
                'user' => 'user',
                'password' => '<PASSWORD>',
                'exchanges' => [],
                'queues' => []
            ],
            'foo' => [
                'host' => 'foo',
                'port' => '200',
                'virtual_host' => 'vh_foo',
                'user' => 'user_foo',
                'password' => '<PASSWORD>',
                'exchanges' => [],
                'queues' => []
            ]
        ];
        $config = $this->processSection([
            'connections' => $connections
        ]);

        $this->assertEquals($connections, $config['connections']);
    }

    /**
     * @test drivers are amqplib and pecl
     * @dataProvider drivers
     */
    public function driverRestrictions($value, $valid)
    {
        try {
            $config = $this->processSection([
                'driver' => $value
            ]);
        } catch (InvalidConfigurationException $e) {
            if ($valid) {
                $this->fail('Valid driver failed');
            }

            $this->assertTrue(true);

            return;
        }

        if (!$valid) {
            $this->fail('Invalid driver passed');
        }

        $this->assertEquals($value, $config['driver']);
    }

    public function drivers()
    {
        return [
            ['amqplib', true],
            ['pecl', true],
            ['foo', false]
        ];
    }

    /**
     * @test connections..exchanges with default values
     */
    public function amqpExchangesDefaultConfig()
    {
        $config = [
            'connections' => [
                'default' => [
                    'exchanges' => [
                        'foo.bar' => []<commit_msg>Skip unnecessary test<commit_after><?php
/**
 * This file is a part of the Event-Band project
 * @author <NAME>
 * @author <NAME> Kulakov <<EMAIL>>
 */

namespace EventBand\Bundle\Tests\DependencyInjection;

use EventBand\Bundle\DependencyInjection\AmqpConfiguration;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;

/**
 * Class AmqpConfigurationTest
 *
 * @author <NAME> <<EMAIL>>
 */
class AmqpConfigurationTest extends SectionConfigurationTestCase
{
    /**
     * {@inheritDoc}
     */
    protected function createSection()
    {
        return new AmqpConfiguration();
    }

    /**
     * @test default values for empty config
     */
    public function defaultValues()
    {
        $config = $this->processSection([]);

        $this->assertEquals(
            [
                'driver' => 'amqplib',
                'use_tracer_interceptor' => false,
                'connections' => [
                    'default' => AmqpConfiguration::getDefaultConnection()
                ],
                'converters' => [
                    'default' => [
                        'type' => 'serialize',
                        'parameters' => [
                            'serializer' => 'default'
                        ]
                    ]
                ]
            ],
            $config
        );
    }

    /**
     * @test all connection options can be set
     */
    public function connectionOptions()
    {
        $connections = [
            'default' => [
                'host' => 'def',
                'port' => '100',
                'virtual_host' => 'vh',
                'user' => 'user',
                'password' => '<PASSWORD>',
                'exchanges' => [],
                'queues' => []
            ],
            'foo' => [
                'host' => 'foo',
                'port' => '200',
                'virtual_host' => 'vh_foo',
                'user' => 'user_foo',
                'password' => '<PASSWORD>',
                'exchanges' => [],
                'queues' => []
            ]
        ];
        $config = $this->processSection([
            'connections' => $connections
        ]);

        $this->assertEquals($connections, $config['connections']);
    }

    /**
     * @test drivers are amqplib and pecl
     * @dataProvider drivers
     */
    public function driverRestrictions($value, $valid)
    {
        try {
            $config = $this->processSection([
                'driver' => $value
            ]);
        } catch (InvalidConfigurationException $e) {
            if ($valid) {
                $this->fail('Valid driver failed');
            } else {
                $this->markTestSkipped();
            }

            return;
        }

        if (!$valid) {
            $this->fail('Invalid driver passed');
        }

        $this->assertEquals($value, $config['driver']);
    }

    public function drivers()
    {
        return [
            ['amqplib', true],
            ['pecl', true],
            ['foo', false]
        ];
    }

    /**
     * @test connections..exchanges with default values
     */
    public function amqpExchangesDefaultConfig()
    {
        $config = [
            'connections' => [
                'default' => [
                    'exchanges' => [
                        'foo.bar' => []
{'fraction_non_alphanumeric': 0.13893473368342085, 'fraction_numerical': 0.001800450112528132, 'mean_word_length': 1.3250784792465993, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 101, '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': '2557769', 'n_tokens_mistral': 1767, 'n_tokens_neox': 1676, 'n_words': 333}