<commit_before><?php

namespace Dhii\Di\FuncTest;

use Dhii\Di\CompositeContainer;
use Dhii\Di\ParentAwareContainerInterface;
use Dhii\Di\ServiceProvider as ServiceProvider2;
use Interop\Container\ContainerInterface;
use Interop\Container\ServiceProvider;
use Xpmock\TestCase;

/**
 * Tests {@see \Dhii\Di\CompositeContainer} and related classes.
 *
 * @since 0.1
 */
class CompositeContainerTest extends TestCase
{
    /**
     * The class name of the test subject.
     *
     * @since 0.1
     */
    const TEST_SUBJECT_CLASSNAME = 'Dhii\\Di\\CompositeContainer';

    /**
     * Creates a new instance of the test subject.
     *
     * @since 0.1
     *
     * @param ContainerInterface $parent The container, which is to become this container's parent.
     *
     * @return CompositeContainer
     */
    public function createInstance(ContainerInterface $parent = null)
    {
        $mock = $this->mock(static::TEST_SUBJECT_CLASSNAME)
                ->new($parent);

        return $mock;
    }

    /**
     * Creates a new service provider instance.
     *
     * @since 0.1
     *
     * @param array $definitions An array of service definitions.
     *
     * @return ServiceProvider2
     */
    public function createServiceProvider($definitions)
    {
        return new ServiceProvider2($definitions);
    }

    /**
     * Creates a new container instance.
     *
     * @since 0.1
     *
     * @param ServiceProvider $definitions The service provider.
     * @param ContainerInterface $parent The container instance which is the be the parent container.
     * @param bool $isMutable If true, the container will have its parent container be mutable; immutable if false.
     *
     * @return ParentAwareContainerInterface
     */
    public function createContainer(ServiceProvider $definitions, ContainerInterface $parent = null, $isMutable = true)
    {
        $className = $isMutable
                ? 'Dhii\\Di\\ContainerWithMutableParent'
                : 'Dhii\\Di\\ContainerWithImmutableParent';
        $mock = $this->mock($className)
                ->new($definitions, $parent);

        return $mock;
    }

    /**
     * Creates an instance of the most basic interop container.
     *
     * @since [*next-version*]
     *
     * @return ContainerInterface The new instance.
     */
    public function createBaseContainer()
    {
        $instance = $this->mock('Interop\\Container\\ContainerInterface')
                ->get()
                ->has()
                ->new();

        return $instance;
    }

    /**
     * Create a service definition that returns a simple value.
     *
     * @since 0.1
     *
     * @param mixed $value The value that the service definition will return.
     *
     * @return callable A service definition that will return the given value.
     */
    public function createDefinition($value)
    {
        return function(ContainerInterface $container, $previous = null) use ($value) {
            return $value;
        };
    }

    /**
     * Tests whether a valid instance of the test subject can be created.
     *
     * @since [*next-version*]
     */
    public function testCanBeCreated()
    {
        $subject = $this->createInstance();
        $this->assertInstanceOf('Dhii\\Di\\CompositeContainerInterface', $subject, 'A valid instance of the test subject could not be created');
        $this->assertInstanceOf('Dhii\\Di\\WritableCompositeContainerInterface', $subject, 'Test subject does not implement required interface');
        $this->assertInstanceOf('Dhii\\Di\\ParentAwareContainerInterface', $subject, 'Test subject does not implement required interface');
        $this->assertInstanceOf('Interop\\Container\\ContainerInterface', $subject, 'Test subject does not implement required interface');
    }

    /**
     * Tests whether an interop container can get added to the composite container.
     *
     * @since [*next-version*]
     */
    public function testAdd()
    {
        $subject = $this->createInstance();
        $child = $this->createBaseContainer();

        $subject->add($child);
        $this->assertContains($child, $subject->getContainers(), 'Added container is not in the resulting container set');
    }

    /**
     * Tests that the constructor accepts correct args.
     *
     * @since [*next-version*]<commit_msg>Replaced next version placeholders in tests<commit_after><?php

namespace Dhii\Di\FuncTest;

use Dhii\Di\CompositeContainer;
use Dhii\Di\ParentAwareContainerInterface;
use Dhii\Di\ServiceProvider as ServiceProvider2;
use Interop\Container\ContainerInterface;
use Interop\Container\ServiceProvider;
use Xpmock\TestCase;

/**
 * Tests {@see \Dhii\Di\CompositeContainer} and related classes.
 *
 * @since 0.1
 */
class CompositeContainerTest extends TestCase
{
    /**
     * The class name of the test subject.
     *
     * @since 0.1
     */
    const TEST_SUBJECT_CLASSNAME = 'Dhii\\Di\\CompositeContainer';

    /**
     * Creates a new instance of the test subject.
     *
     * @since 0.1
     *
     * @param ContainerInterface $parent The container, which is to become this container's parent.
     *
     * @return CompositeContainer
     */
    public function createInstance(ContainerInterface $parent = null)
    {
        $mock = $this->mock(static::TEST_SUBJECT_CLASSNAME)
                ->new($parent);

        return $mock;
    }

    /**
     * Creates a new service provider instance.
     *
     * @since 0.1
     *
     * @param array $definitions An array of service definitions.
     *
     * @return ServiceProvider2
     */
    public function createServiceProvider($definitions)
    {
        return new ServiceProvider2($definitions);
    }

    /**
     * Creates a new container instance.
     *
     * @since 0.1
     *
     * @param ServiceProvider $definitions The service provider.
     * @param ContainerInterface $parent The container instance which is the be the parent container.
     * @param bool $isMutable If true, the container will have its parent container be mutable; immutable if false.
     *
     * @return ParentAwareContainerInterface
     */
    public function createContainer(ServiceProvider $definitions, ContainerInterface $parent = null, $isMutable = true)
    {
        $className = $isMutable
                ? 'Dhii\\Di\\ContainerWithMutableParent'
                : 'Dhii\\Di\\ContainerWithImmutableParent';
        $mock = $this->mock($className)
                ->new($definitions, $parent);

        return $mock;
    }

    /**
     * Creates an instance of the most basic interop container.
     *
     * @since 0.1.1
     *
     * @return ContainerInterface The new instance.
     */
    public function createBaseContainer()
    {
        $instance = $this->mock('Interop\\Container\\ContainerInterface')
                ->get()
                ->has()
                ->new();

        return $instance;
    }

    /**
     * Create a service definition that returns a simple value.
     *
     * @since 0.1
     *
     * @param mixed $value The value that the service definition will return.
     *
     * @return callable A service definition that will return the given value.
     */
    public function createDefinition($value)
    {
        return function(ContainerInterface $container, $previous = null) use ($value) {
            return $value;
        };
    }

    /**
     * Tests whether a valid instance of the test subject can be created.
     *
     * @since 0.1.1
     */
    public function testCanBeCreated()
    {
        $subject = $this->createInstance();
        $this->assertInstanceOf('Dhii\\Di\\CompositeContainerInterface', $subject, 'A valid instance of the test subject could not be created');
        $this->assertInstanceOf('Dhii\\Di\\WritableCompositeContainerInterface', $subject, 'Test subject does not implement required interface');
        $this->assertInstanceOf('Dhii\\Di\\ParentAwareContainerInterface', $subject, 'Test subject does not implement required interface');
        $this->assertInstanceOf('Interop\\Container\\ContainerInterface', $subject, 'Test subject does not implement required interface');
    }

    /**
     * Tests whether an interop container can get added to the composite container.
     *
     * @since 0.1.1
     */
    public function testAdd()
    {
        $subject = $this->createInstance();
        $child = $this->createBaseContainer();

        $subject->add($child);
        $this->assertContains($child, $subject->getContainers(), 'Added container is not in the resulting container set');
    }

    /**
     * Tests that the constructor accepts correct args.
     *
     * @since 0.1.1
{'fraction_non_alphanumeric': 0.1061130334486736, 'fraction_numerical': 0.004844290657439446, 'mean_word_length': 2.479534510433387, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '1875878', 'n_tokens_mistral': 2348, 'n_tokens_neox': 2272, 'n_words': 674}