<commit_before><?php

namespace Bauhaus\DependencyInjection;

use Bauhaus\DependencyInjection\FakeService;

class DependencyInjectionTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @test
     * @testdox When a service is registered, a new container is returned with the service added
     */
    public function whenAServiceIsRegisteredANewContainerIsReturnedWithTheServiceAdded()
    {
        $oldDiContainer = (new DependencyInjection())
            ->withService('service', function () {
                return 'result of the service';
            });

        $newDiContainer = $oldDiContainer->withService('newService', function () {
            return 'result of the new service';
        });

        // assert that new container was created
        $this->assertNotSame($oldDiContainer, $newDiContainer);

        // assert that the new container contains the new service registered and
        // the old ones
        $servicesOfTheOldDiContainer = $oldDiContainer->all();
        $servicesOfTheNewDiContainer = $newDiContainer->all();

        $this->assertArrayHasKey('newService', $servicesOfTheNewDiContainer);
        unset($servicesOfTheNewDiContainer['newService']);
        $this->assertEquals($servicesOfTheOldDiContainer, $servicesOfTheNewDiContainer);
    }

    /**
     * @test
     * @dataProvider availableServiceTypes
     */
    public function theResultOfTheAnonymousFunctionUsedToRegisterAServiceIsReturnedWhenThisServiceIsCalled(
        string $serviceType
    ) {
        $expectedResult = 'expected result';

        $diContainer = (new DependencyInjection())
            ->withService('service', function () use ($expectedResult) {
                return $expectedResult;
            }, $serviceType);

        $this->assertEquals($expectedResult, $diContainer->service);
    }<commit_msg>Rename variables to avoid long names<commit_after><?php

namespace Bauhaus\DependencyInjection;

use Bauhaus\DependencyInjection\FakeService;

class DependencyInjectionTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @test
     * @testdox When a service is registered, a new container is returned with the service added
     */
    public function whenAServiceIsRegisteredANewContainerIsReturnedWithTheServiceAdded()
    {
        $oldDiContainer = (new DependencyInjection())
            ->withService('service', function () {
                return 'result of the service';
            });

        $newDiContainer = $oldDiContainer->withService('newService', function () {
            return 'result of the new service';
        });

        // assert that new container was created
        $this->assertNotSame($oldDiContainer, $newDiContainer);

        // assert that the new container contains the new service registered and
        // the old ones
        $oldServices = $oldDiContainer->all();
        $newServices = $newDiContainer->all();

        $this->assertArrayHasKey('newService', $newServices);
        unset($newServices['newService']);
        $this->assertEquals($oldServices, $newServices);
    }

    /**
     * @test
     * @dataProvider availableServiceTypes
     */
    public function theResultOfTheAnonymousFunctionUsedToRegisterAServiceIsReturnedWhenThisServiceIsCalled(
        string $serviceType
    ) {
        $expectedResult = 'expected result';

        $diContainer = (new DependencyInjection())
            ->withService('service', function () use ($expectedResult) {
                return $expectedResult;
            }, $serviceType);

        $this->assertEquals($expectedResult, $diContainer->service);
    }
{'fraction_non_alphanumeric': 0.09908154745338157, 'fraction_numerical': 0.0, 'mean_word_length': 2.984478935698448, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '1544962', 'n_tokens_mistral': 899, 'n_tokens_neox': 881, 'n_words': 207}