<commit_before><?php

class Foo {
    public function give($amount)
    {
        return $amount;
    }
}

class Bar {
    protected $qux;

    public function __construct(\Foo $foo, $number = 1) {
        $this->set($foo->give($number));
    }

    public function get()
    {
        return $this->qux;
    }

    public function set($qux) {
        $this->qux = $qux;
    }
}

use Illusion\Container\Container;

class ContainerTest extends PHPUnit_Framework_TestCase
{
    private $c;

    public function setUp()
    {
        $this->c = new Container;
    }

    public function tearDown()
    {
        $this->c = new Container;
    }

    public function testOffsets()
    {
        $this->c['foo'] = 'bar';
        $this->assertInstanceOf('\Bar', $this->c['foo']);
        $this->assertTrue($this->c->has('foo'));
        unset($this->c['foo']);
        $this->assertFalse($this->c->has('foo'));
    }

    public function testDynamicallyCallingServices()
    {
        $this->c->foo = '\Foo';
        $this->c->bar = function($c) {
            return new \Bar($c->foo);
        };

        $this->assertTrue(isset($this->c->foo));
        $this->assertTrue(isset($this->c->bar));
        $this->assertInstanceOf('Foo', $this->c->foo);
        $this->assertInstanceOf('Bar', $this->c->bar);

        unset($this->c->foo, $this->c->bar);
        $this->assertFalse(isset($this->c->foo));
        $this->assertFalse(isset($this->c->bar));
    }

    public function testIfBindingExists()
    {
        $this->c->register('foo', 'Bar');
        $this->assertTrue($this->c->has('foo'));
    }

    public function testBindingValue()
    {
        $this->c->register('foo', 'Bar');
        $this->assertEquals(['value' => '\Bar', 'shared' => false], $this->c->get('foo'));
    }

    public function testReturningNullWhenBindingDoesnExist()
    {
        $this->assertNull($this->c->get('qux'));
    }

    public function testResolveBindingWithNoValue()
    {
        $this->c->register('Foo');
        $this->assertInstanceOf('Foo', $this->c->resolve('Foo'));
    }

    public function testDirectResolve()
    {
        $this->c->register('foo', 'Foo');
        $fooInstance = $this->c->resolve('foo');
        $this->assertInstanceOf('Foo', $fooInstance);

        $this->c->register('bar', 'Bar');
        $barInstance = $this->c->resolve('bar');
        $this->assertInstanceOf('Bar', $barInstance);
    }

    public function testClosureResolve()
    {
        $this->c->register('foo', function() {
            return new Foo;
        });

        $this->assertInstanceOf('Foo', $this->c->resolve('foo'));

        $this->c->register('bar', function() {
            $foo = new Foo;
            return new Bar($foo);
        });

        $this->assertInstanceOf('Bar', $this->c->resolve('bar'));
    }

    public function testClosureResolveWithParameter()
    {
        $this->c->register('bar', function($container) {
            $container->register('foo', 'Foo');
            return new Bar($container->resolve('foo'));
        });

        $this->assertInstanceOf('Bar', $this->c->resolve('bar'));
    }

    public function testSharedInstances()
    {
        $this->c->singleton('foo', '\Foo');
        $this->c->share('bar', '\Bar');

        $fooInstance  = $this->c->resolve('foo');
        $fooInstance2 = $this->c->resolve('foo');

        $barInstance  = $this->c->resolve('bar');
        $barInstance2 = $this->c->resolve('bar');

        $this->assertTrue($fooInstance === $fooInstance2);
        $this->assertTrue($barInstance === $barInstance2);
    }

    public function testBindAlreadyInstantiatedObject()
    {
        $foo = new \Foo;
        $this->c->instance('foo', $foo);
        $this->assertInstanceOf('Foo', $this->c->resolve('foo'));
    }

    public function testExtendingServices()
    {
        $this->c->register('bar', '\Bar');

        $this->c->resolve('bar');

        $this->c->extend('bar', function($bar, $c) {
            $bar->set(5);
            $c->register('foo', '\Foo');
            return $bar;
        });

        $this->assertInstanceOf('Foo', $this->c->resolve('foo'));
        $this->assertEquals(5, $this->c['bar']->get());
    }

    public function testPassingValuesThroughClosure()
    {
        $this->c->register('bar', function($number, $c) {
            $number *= 2;
            return new \Bar(new Foo, $number);
        });

        $this->assertEquals(4, $this->c->resolve('bar', [2])->get());
    }

    public function testProtectedParameters()
    {
        $this->c->protect('Foo', function() {
            return 'foo';
        });

        $this->assertEquals('foo', $this->c->getProtected('Foo'));
    }<commit_msg>Improve test readiblity.<commit_after><?php

class Foo {
    public function give($amount)
    {
        return $amount;
    }
}

class Bar {
    protected $qux;

    public function __construct(\Foo $foo, $number = 1) {
        $this->set($foo->give($number));
    }

    public function get()
    {
        return $this->qux;
    }

    public function set($qux) {
        $this->qux = $qux;
    }
}

use Illusion\Container\Container;

class ContainerTest extends PHPUnit_Framework_TestCase
{
    private $c;

    public function setUp()
    {
        $this->c = new Container;
    }

    public function tearDown()
    {
        $this->c = new Container;
    }

    public function testOffsets()
    {
        $this->c['foo'] = 'bar';
        $this->assertInstanceOf('\Bar', $this->c['foo']);
        $this->assertTrue($this->c->has('foo'));
        unset($this->c['foo']);
        $this->assertFalse($this->c->has('foo'));
    }

    public function testDynamicallyCallingServices()
    {
        $this->c->foo = '\Foo';
        $this->c->bar = function($c) {
            return new \Bar($c->foo);
        };

        $this->assertTrue(isset($this->c->foo));
        $this->assertTrue(isset($this->c->bar));
        $this->assertInstanceOf('Foo', $this->c->foo);
        $this->assertInstanceOf('Bar', $this->c->bar);

        unset($this->c->foo, $this->c->bar);
        $this->assertFalse(isset($this->c->foo));
        $this->assertFalse(isset($this->c->bar));
    }

    public function testIfBindingExists()
    {
        $this->c->register('foo', 'Bar');
        $this->assertTrue($this->c->has('foo'));
    }

    public function testBindingValue()
    {
        $this->c->register('foo', 'Bar');

        $expect = ['value' => '\Bar', 'shared' => false];

        $binding = $this->c->get('foo');

        $this->assertEquals($expect, $binding);
    }

    public function testReturningNullWhenBindingDoesnExist()
    {
        $binding = $this->c->get('qux');
        $this->assertNull($binding);
    }

    public function testResolveBindingWithNoValue()
    {
        $this->c->register('Foo');
        $resolve = $this->c->resolve('Foo');

        $this->assertInstanceOf('Foo', $resolve);
    }

    public function testDirectResolve()
    {
        $this->c->register('foo', 'Foo');
        $fooInstance = $this->c->resolve('foo');
        $this->assertInstanceOf('Foo', $fooInstance);

        $this->c->register('bar', 'Bar');
        $barInstance = $this->c->resolve('bar');
        $this->assertInstanceOf('Bar', $barInstance);
    }

    public function testClosureResolve()
    {
        $this->c->register('foo', function() {
            return new Foo;
        });

        $fooResolve = $this->c->resolve('foo');

        $this->assertInstanceOf('Foo', $fooResolve);

        $this->c->register('bar', function() {
            $foo = new Foo;
            return new Bar($foo);
        });

        $barResolve = $this->c->resolve('bar');

        $this->assertInstanceOf('Bar', $barResolve);
    }

    public function testClosureResolveWithParameter()
    {
        $this->c->register('bar', function($container) {
            $container->register('foo', 'Foo');
            return new Bar($container->resolve('foo'));
        });

        $resolve = $this->c->resolve('bar');

        $this->assertInstanceOf('Bar', $resolve);
    }

    public function testSharedInstances()
    {
        $this->c->singleton('foo', '\Foo');
        $this->c->share('bar', '\Bar');

        $fooInstance  = $this->c->resolve('foo');
        $fooInstance2 = $this->c->resolve('foo');

        $barInstance  = $this->c->resolve('bar');
        $barInstance2 = $this->c->resolve('bar');

        $this->assertTrue($fooInstance === $fooInstance2);
        $this->assertTrue($barInstance === $barInstance2);
    }

    public function testBindAlreadyInstantiatedObject()
    {
        $foo = new \Foo;
        $this->c->instance('foo', $foo);

        $resolve = $this->c->resolve('foo');
        $this->assertInstanceOf('Foo', $resolve);
    }

    public function testExtendingServices()
    {
        $this->c->register('bar', '\Bar');

        $this->c->resolve('bar');

        $this->c->extend('bar', function($bar, $c) {
            $bar->set(5);
            $c->register('foo', '\Foo');
            return $bar;
        });

        $resolve = $this->c->resolve('foo');
        $barGetValue = $this->c->bar->get();

        $this->assertInstanceOf('Foo', $resolve);
        $this->assertEquals(5, $barGetValue);
    }

    public function testPassingValuesThroughClosure()
    {
        $this->c->register('bar', function($number, $c) {
            $number *= 2;
            return new \Bar(new Foo, $number);
        });

        $barGetValue = $this->c->resolve('bar', [2])->get();

        $this->assertEquals(4, $barGetValue);
    }

    public function testProtectedParameters()
    {
        $this->c->protect('Foo', function() {
            return 'foo';
        });

        $protected = $this->c->getProtected('Foo');

        $this->assertEquals('foo', $protected);
    }
{'fraction_non_alphanumeric': 0.20059207839934667, 'fraction_numerical': 0.002041649652919559, 'mean_word_length': 2.3255261371350984, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 272, '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': '7038487', 'n_tokens_mistral': 3078, 'n_tokens_neox': 2968, 'n_words': 474}