<commit_before><?php

use Berny\Bundle\TagBundle\DependencyInjection\Compiler\TagInjectablePass;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

class InjectablePassTest extends \PHPUnit_Framework_TestCase
{
    public function test_set_injectable_as_dependency()
    {
        $cb = $this->getContainer(new TagInjectablePass(), array(
            'my_injectable' => $this->getInjectableDefinition()->addTag('tag.injectable', array(
                'tag' => 'injectable_aware',
                'method' => 'setInjectable'
            )),
            'my_dep_1' => $this->getInjectableAwareDefinition()->addTag('injectable_aware'),
            'my_dep_2' => $this->getInjectableAwareDefinition()->addTag('not_injectable_aware'),
            'my_dep_3' => $this->getInjectableAwareDefinition()->addTag('injectable_aware'),
        ));

        $dep1 = $cb->get('my_dep_1');
        $dep2 = $cb->get('my_dep_2');
        $dep3 = $cb->get('my_dep_3');

        $this->assertNull($dep2->getInjectable());
        $this->assertInstanceOf('StdClass', $dep1->getInjectable());
        $this->assertSame($dep1->getInjectable(), $dep3->getInjectable());
    }

    /**
     * @return Definition
     */
    protected function getInjectableDefinition()
    {
        return new Definition('StdClass');
    }

    /**
     * @return Definition
     */
    protected function getInjectableAwareDefinition()
    {
        return new Definition('MockedInjectableAwareService');
    }

    /**
     * @param CompilerPassInterface $compilerPass
     *
     * @param array $definitions
     *
     * @return ContainerBuilder
     */
    protected function getContainer(CompilerPassInterface $compilerPass, array $definitions)
    {
        $containerBuilder = new ContainerBuilder();
        $containerBuilder->addDefinitions($definitions);
        $compilerPass->process($containerBuilder);
        $containerBuilder->compile();

        return $containerBuilder;
    }
}

class MockedInjectableAwareService
{
    protected $injectable;

    public function setInjectable($injectable)
    {
        $this->injectable = $injectable;
    }

    public function getInjectable()
    {
        return $this->injectable;
    }
}
<commit_msg>test: set custom injectable_tag<commit_after><?php

use Berny\Bundle\TagBundle\DependencyInjection\Compiler\TagInjectablePass;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

class InjectablePassTest extends \PHPUnit_Framework_TestCase
{
    public function test_set_injectable_as_dependency()
    {
        $cb = $this->getContainer(new TagInjectablePass(), array(
            'my_injectable' => $this->getInjectableDefinition()->addTag('tag.injectable', array(
                'tag' => 'injectable_aware',
                'method' => 'setInjectable'
            )),
            'my_dep_1' => $this->getInjectableAwareDefinition()->addTag('injectable_aware'),
            'my_dep_2' => $this->getInjectableAwareDefinition()->addTag('not_injectable_aware'),
            'my_dep_3' => $this->getInjectableAwareDefinition()->addTag('injectable_aware'),
        ));

        $dep1 = $cb->get('my_dep_1');
        $dep2 = $cb->get('my_dep_2');
        $dep3 = $cb->get('my_dep_3');

        $this->assertNull($dep2->getInjectable());
        $this->assertInstanceOf('StdClass', $dep1->getInjectable());
        $this->assertSame($dep1->getInjectable(), $dep3->getInjectable());
    }

    public function test_custom_injectable_tag()
    {
        $cb = $this->getContainer(new TagInjectablePass('custom.injectable_tag'), array(
            'my_injectable' => $this->getInjectableDefinition()->addTag('custom.injectable_tag', array(
                    'tag' => 'injectable_aware',
                    'method' => 'setInjectable'
                )),
            'my_dep_1' => $this->getInjectableAwareDefinition()->addTag('injectable_aware'),
            'my_dep_2' => $this->getInjectableAwareDefinition()->addTag('not_injectable_aware'),
            'my_dep_3' => $this->getInjectableAwareDefinition()->addTag('injectable_aware'),
        ));

        $dep1 = $cb->get('my_dep_1');
        $dep2 = $cb->get('my_dep_2');
        $dep3 = $cb->get('my_dep_3');

        $this->assertNull($dep2->getInjectable());
        $this->assertInstanceOf('StdClass', $dep1->getInjectable());
        $this->assertSame($dep1->getInjectable(), $dep3->getInjectable());
    }

    /**
     * @return Definition
     */
    protected function getInjectableDefinition()
    {
        return new Definition('StdClass');
    }

    /**
     * @return Definition
     */
    protected function getInjectableAwareDefinition()
    {
        return new Definition('MockedInjectableAwareService');
    }

    /**
     * @param CompilerPassInterface $compilerPass
     *
     * @param array $definitions
     *
     * @return ContainerBuilder
     */
    protected function getContainer(CompilerPassInterface $compilerPass, array $definitions)
    {
        $containerBuilder = new ContainerBuilder();
        $containerBuilder->addDefinitions($definitions);
        $compilerPass->process($containerBuilder);
        $containerBuilder->compile();

        return $containerBuilder;
    }
}

class MockedInjectableAwareService
{
    protected $injectable;

    public function setInjectable($injectable)
    {
        $this->injectable = $injectable;
    }

    public function getInjectable()
    {
        return $this->injectable;
    }
}

{'fraction_non_alphanumeric': 0.13580679033951698, 'fraction_numerical': 0.006825341267063354, 'mean_word_length': 3.1443074691805655, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 88, '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': '107343', 'n_tokens_mistral': 1643, 'n_tokens_neox': 1655, 'n_words': 226}