Phalcon\Test\Unit\DiTest::testComplexInjection PHP Method

testComplexInjection() public method

Tests resolving a services via array access
Since: 2016-01-29
Author: Serghei Iakovlev ([email protected])
    public function testComplexInjection()
    {
        $this->specify("Resolving a services via array access does now work correctly", function () {
            $response = new Response();
            $this->phDi->set('response', $response);
            // Injection of parameters in the constructor
            $this->phDi->set('simpleConstructor', ['className' => 'InjectableComponent', 'arguments' => [['type' => 'parameter', 'value' => 'response']]]);
            // Injection of simple setters
            $this->phDi->set('simpleSetters', ['className' => 'InjectableComponent', 'calls' => [['method' => 'setResponse', 'arguments' => [['type' => 'parameter', 'value' => 'response']]]]]);
            // Injection of properties
            $this->phDi->set('simpleProperties', ['className' => 'InjectableComponent', 'properties' => [['name' => 'response', 'value' => ['type' => 'parameter', 'value' => 'response']]]]);
            // Injection of parameters in the constructor resolving the service parameter
            $this->phDi->set('complexConstructor', ['className' => 'InjectableComponent', 'arguments' => [['type' => 'service', 'name' => 'response']]]);
            // Injection of simple setters resolving the service parameter
            $this->phDi->set('complexSetters', ['className' => 'InjectableComponent', 'calls' => [['method' => 'setResponse', 'arguments' => [['type' => 'service', 'name' => 'response']]]]]);
            // Injection of properties resolving the service parameter
            $this->phDi->set('complexProperties', ['className' => 'InjectableComponent', 'properties' => [['name' => 'response', 'value' => ['type' => 'service', 'name' => 'response']]]]);
            $component = $this->phDi->get('simpleConstructor');
            expect(is_string($component->getResponse()))->true();
            expect($component->getResponse())->equals('response');
            $component = $this->phDi->get('simpleSetters');
            expect(is_string($component->getResponse()))->true();
            expect($component->getResponse())->equals('response');
            $component = $this->phDi->get('simpleProperties');
            expect(is_string($component->getResponse()))->true();
            expect($component->getResponse())->equals('response');
            $component = $this->phDi->get('complexConstructor');
            expect(is_object($component->getResponse()))->true();
            expect($component->getResponse())->equals($response);
            $component = $this->phDi->get('complexSetters');
            expect(is_object($component->getResponse()))->true();
            expect($component->getResponse())->equals($response);
            $component = $this->phDi->get('complexProperties');
            expect(is_object($component->getResponse()))->true();
            expect($component->getResponse())->equals($response);
        });
    }