<commit_before><?php

/**
 * States.
 *
 * LICENSE
 *
 * This source file is subject to the MIT license and the version 3 of the GPL3
 * license that are bundled with this package in the folder licences
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @copyright   Copyright (c) 2009-2015 Uni Alteri (http://agence.net.ua)
 *
 * @link        http://teknoo.it/states Project website
 *
 * @license     http://teknoo.it/states/license/mit         MIT License
 * @license     http://teknoo.it/states/license/gpl-3.0     GPL v3 License
 * @author      <NAME> <<EMAIL>>
 *
 * @version     1.1.1
 */

namespace UniAlteri\Tests\States\DI;

use UniAlteri\States\DI;
use UniAlteri\States\DI\Exception;
use UniAlteri\Tests\Support;

/**
 * Class InjectionClosureTest
 * Check if the Injection Closure class has the excepted behavior defined by the DI\InjectionClosureInterface.
 *
 * @copyright   Copyright (c) 2009-2015 Uni Alteri (http://agence.net.ua)
 *
 * @link        http://teknoo.it/states Project website
 *
 * @license     http://teknoo.it/states/license/mit         MIT License
 * @license     http://teknoo.it/states/license/gpl-3.0     GPL v3 License
 * @author      <NAME> <<EMAIL>>
 */
class InjectionClosureTest extends \PHPUnit_Framework_TestCase
{
    protected function setUp()
    {
        parent::setUp();
    }

    protected function tearDown()
    {
        parent::tearDown();
    }

    /**
     * Return a valid InjectionClosureInterface object.
     *
     * @param callable $closure
     *
     * @return DI\InjectionClosure
     */
    protected function buildClosure(\Closure $closure = null)
    {
        if (null === $closure) {
            $closure = function () {
                return array_reverse(func_get_args());
            };
        }

        $injectionClosureObject = new DI\InjectionClosure();
        $injectionClosureObject->setClosure($closure);

        return $injectionClosureObject;
    }

    /**
     * Test behavior for methods Set And GetDiContainer.
     */
    public function testSetAndGetDiContainer()
    {
        $object = new DI\InjectionClosure();
        $this->assertNull($object->getDIContainer());
        $virtualContainer = new Support\MockDIContainer();
        $this->assertSame($object, $object->setDIContainer($virtualContainer));
        $this->assertSame($virtualContainer, $object->getDIContainer());
    }

    /**
     * The Injection Closure object must not accept object who not implement \Closure.
     *
     * @return bool
     */
    public function testBadClosureConstruct()
    {
        try {
            $a = new DI\InjectionClosure();
            $a->setClosure(new \stdClass());
        } catch (Exception\InvalidArgument $e) {
            return;
        } catch (\Exception $e) {
        }

        $this->fail('Error, the Injection closure object must throw an exception if the object is not a closure');
    }

    /**
     * Test Injection closure creation.
     */
    public function testCreateClosure()
    {
        $closure = $this->buildClosure();
        $this->assertInstanceOf('\UniAlteri\States\DI\InjectionClosureInterface', $closure);
    }

    /**
     * Test invoking from injection with the closure, execute the closure (the closure test returns arguments order.
     */
    public function testInvokeWithArgsInvokeMagic()
    {
        $closure = $this->buildClosure();
        $return = $closure('foo', 'boo', 'hello', 'world');
        $this->assertSame(
            array(
                'world',
                'hello',
                'boo',
                'foo',
            ),
            $return,
            'Error, the closure is not called by the injector '
        );
    }

    /**
     * Test invoking from injection with the closure, execute the closure (the closure test returns arguments order.
     */
    public function testInvokeWithArgs()
    {
        $closure = $this->buildClosure();
        $args = ['foo', 'boo', 'hello', 'world'];
        $return = $closure->invoke($args);
        $this->assertSame(
            array(
                'world',
                'hello',
                'boo',
                'foo',
            ),
            $return,
            'Error, the closure is not called by the injector '
        );
    }

    /**
     * Test invoke behavior with different number of arguments.
     */
    public function testInvokeCallSeveralArgs()
    {
        $closure = $this->buildClosure();
        $args = [];
        $result = $closure->invoke($args);
        $this->assertEquals(array(), $result);

        $args = [1];
        $result = $closure->invoke($args);<commit_msg>To get a great error message parsable by phpstorm<commit_after><?php

/**
 * States.
 *
 * LICENSE
 *
 * This source file is subject to the MIT license and the version 3 of the GPL3
 * license that are bundled with this package in the folder licences
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @copyright   Copyright (c) 2009-2015 Uni Alteri (http://agence.net.ua)
 *
 * @link        http://teknoo.it/states Project website
 *
 * @license     http://teknoo.it/states/license/mit         MIT License
 * @license     http://teknoo.it/states/license/gpl-3.0     GPL v3 License
 * @author      <NAME> <<EMAIL>>
 *
 * @version     1.1.1
 */

namespace UniAlteri\Tests\States\DI;

use UniAlteri\States\DI;
use UniAlteri\States\DI\Exception;
use UniAlteri\Tests\Support;

/**
 * Class InjectionClosureTest
 * Check if the Injection Closure class has the excepted behavior defined by the DI\InjectionClosureInterface.
 *
 * @copyright   Copyright (c) 2009-2015 Uni Alteri (http://agence.net.ua)
 *
 * @link        http://teknoo.it/states Project website
 *
 * @license     http://teknoo.it/states/license/mit         MIT License
 * @license     http://teknoo.it/states/license/gpl-3.0     GPL v3 License
 * @author      <NAME> <<EMAIL>>
 */
class InjectionClosureTest extends \PHPUnit_Framework_TestCase
{
    protected function setUp()
    {
        parent::setUp();
    }

    protected function tearDown()
    {
        parent::tearDown();
    }

    /**
     * Return a valid InjectionClosureInterface object.
     *
     * @param callable $closure
     *
     * @return DI\InjectionClosure
     */
    protected function buildClosure(\Closure $closure = null)
    {
        if (null === $closure) {
            $closure = function () {
                return array_reverse(func_get_args());
            };
        }

        $injectionClosureObject = new DI\InjectionClosure();
        $injectionClosureObject->setClosure($closure);

        return $injectionClosureObject;
    }

    /**
     * Test behavior for methods Set And GetDiContainer.
     */
    public function testSetAndGetDiContainer()
    {
        $object = new DI\InjectionClosure();
        $this->assertNull($object->getDIContainer());
        $virtualContainer = new Support\MockDIContainer();
        $this->assertSame($object, $object->setDIContainer($virtualContainer));
        $this->assertSame($virtualContainer, $object->getDIContainer());
    }

    /**
     * The Injection Closure object must not accept object who not implement \Closure.
     *
     * @return bool
     */
    public function testBadClosureConstruct()
    {
        try {
            $a = new DI\InjectionClosure();
            $a->setClosure(new \stdClass());
        } catch (Exception\InvalidArgument $e) {
            return;
        } catch (\Exception $e) {
        }

        $this->fail('Error, the Injection closure object must throw an exception if the object is not a closure');
    }

    /**
     * Test Injection closure creation.
     */
    public function testCreateClosure()
    {
        $closure = $this->buildClosure();
        $this->assertInstanceOf('\UniAlteri\States\DI\InjectionClosureInterface', $closure);
    }

    /**
     * Test invoking from injection with the closure, execute the closure (the closure test returns arguments order.
     */
    public function testInvokeWithArgsInvokeMagic()
    {
        $closure = $this->buildClosure();
        $return = $closure('foo', 'boo', 'hello', 'world');
        $this->assertSame(
            array(
                'world',
                'hello',
                'boo',
                'foo',
            ),
            $return,
            'Error, the closure is not called by the injector '
        );
    }

    /**
     * Test invoking from injection with the closure, execute the closure (the closure test returns arguments order.
     */
    public function testInvokeWithArgs()
    {
        $closure = $this->buildClosure();
        $args = ['foo', 'boo', 'hello', 'world'];
        $return = $closure->invoke($args);
        $this->assertEquals(
            array(
                'world',
                'hello',
                'boo',
                'foo',
            ),
            $return,
            'Error, the closure is not called by the injector '
        );
    }

    /**
     * Test invoke behavior with different number of arguments.
     */
    public function testInvokeCallSeveralArgs()
    {
        $closure = $this->buildClosure();
        $args = [];
        $result = $closure->invoke($args);
        $this->assertEquals(array(), $result);

        $args = [1];
        $result = $closure->invoke($args);
{'fraction_non_alphanumeric': 0.11915692821368948, 'fraction_numerical': 0.005843071786310518, 'mean_word_length': 2.1415929203539825, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 57, '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': '7656972', 'n_tokens_mistral': 2810, 'n_tokens_neox': 2669, 'n_words': 729}