Code Duplication    Length = 56-57 lines in 2 locations

tests/Component/EngineInConstructorInKernelControllerTest.php 1 location

@@ 76-132 (lines=57) @@
73
        );
74
    }
75
76
    public function testControllerResponse()
77
    { // From: https://symfony.com/doc/current/create_framework/unit_testing.html
78
        // TODO: Try with a real matcher
79
        // TODO: Use real controller to be tested!
80
        $matcher = $this->createMock(UrlMatcherInterface::class);
81
        // use getMock() on PHPUnit 5.3 or below
82
        // $matcher = $this->getMock(UrlMatcherInterface::class);
83
84
        $matcher
85
            ->expects($this->once())
86
            ->method('match')
87
            ->will($this->returnValue([
88
                '_route' => 'foo',
89
                'name' => 'Fabien',
90
                // '_controller' => function ($name) {
91
                //     return new Response('Hello '.$name);
92
                // },
93
                '_controller' => EngineInConstructorController::class,
94
            ]))
95
        ;
96
        $matcher
97
            ->expects($this->once())
98
            ->method('getContext')
99
            ->will($this->returnValue($this->createMock(RequestContext::class)))
100
        ;
101
102
        $c = $this->container();
103
        $c->compile();
104
        $requestStack = new RequestStack();
105
        $dispatcher = new EventDispatcher();
106
        $dispatcher->addSubscriber(new RouterListener(
107
            $matcher,
108
            $requestStack
109
        )); // Returns nothing.
110
        $dispatcher->addSubscriber(new ResponseListener('UTF-8'));
111
        $response = (new HttpKernel(
112
            $dispatcher,
113
            new ContainerControllerResolver($c),
114
            // new ControllerResolver(),
115
            $requestStack,
116
            new ArgumentResolver(
117
                new ArgumentMetadataFactory(),
118
                [
119
                    new RequestAttributeValueResolver(),
120
                    new RequestValueResolver(),
121
                    new SessionValueResolver(),
122
                    new ServiceValueResolver($c),
123
                    new DefaultValueResolver(),
124
                    new VariadicValueResolver(),
125
                ]
126
            )
127
        // ))->handle(Request::create('/', 'GET'));
128
        ))->handle(new Request());
129
130
        $this->assertSame(200, $response->getStatusCode());
131
        $this->assertContains('Hello Component!', $response->getContent());
132
    }
133
134
    public function testContainerCanBeCreated()
135
    {

tests/Component/EngineAsArgumentInKernelControllerTest.php 1 location

@@ 75-130 (lines=56) @@
72
        );
73
    }
74
75
    public function testControllerResponse()
76
    { // From: https://symfony.com/doc/current/create_framework/unit_testing.html
77
        // TODO: Try with a real matcher
78
        // TODO: Use real controller to be tested!
79
        $matcher = $this->createMock(UrlMatcherInterface::class);
80
        // use getMock() on PHPUnit 5.3 or below
81
        // $matcher = $this->getMock(UrlMatcherInterface::class);
82
83
        $matcher
84
            ->expects($this->once())
85
            ->method('match')
86
            ->will($this->returnValue([
87
                '_route' => 'foo',
88
                'name' => 'Fabien',
89
                '_controller' => function ($name) {
90
                    return new Response('Hello '.$name);
91
                },
92
            ]))
93
        ;
94
        $matcher
95
            ->expects($this->once())
96
            ->method('getContext')
97
            ->will($this->returnValue($this->createMock(RequestContext::class)))
98
        ;
99
100
        $c = $this->container();
101
        $c->compile();
102
        $requestStack = new RequestStack();
103
        $dispatcher = new EventDispatcher();
104
        $dispatcher->addSubscriber(new RouterListener(
105
            $matcher,
106
            $requestStack
107
        )); // Returns nothing.
108
        $dispatcher->addSubscriber(new ResponseListener('UTF-8'));
109
        $response = (new HttpKernel(
110
            $dispatcher,
111
            new ContainerControllerResolver($c),
112
            // new ControllerResolver(),
113
            $requestStack,
114
            new ArgumentResolver(
115
                new ArgumentMetadataFactory(),
116
                [
117
                    new RequestAttributeValueResolver(),
118
                    new RequestValueResolver(),
119
                    new SessionValueResolver(),
120
                    new ServiceValueResolver($c),
121
                    new DefaultValueResolver(),
122
                    new VariadicValueResolver(),
123
                ]
124
            )
125
        // ))->handle(Request::create('/', 'GET'));
126
        ))->handle(new Request());
127
128
        $this->assertSame(200, $response->getStatusCode());
129
        $this->assertContains('Hello Fabien', $response->getContent());
130
    }
131
132
    public function testContainerCanBeCreated()
133
    {