summaryrefslogtreecommitdiff
path: root/tests/Unit/Http/Psr7ServiceProviderTest.php
blob: b4c3c042b00254950f80ac134092e05a916e28dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php

namespace Engelsystem\Test\Unit\Http;

use Engelsystem\Http\Psr7ServiceProvider;
use Engelsystem\Http\Request;
use Engelsystem\Http\Response;
use Engelsystem\Test\Unit\ServiceProviderTest;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as RequestInterface;
use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;

class Psr7ServiceProviderTest extends ServiceProviderTest
{
    /**
     * @covers \Engelsystem\Http\Psr7ServiceProvider::register()
     */
    public function testRegister()
    {
        /** @var MockObject|DiactorosFactory $psr7Factory */
        $psr7Factory = $this->createMock(DiactorosFactory::class);
        /** @var MockObject|Request $request */
        $request = $this->createMock(Request::class);
        /** @var MockObject|Response $response */
        $response = $this->createMock(Response::class);
        /** @var MockObject|RequestInterface $psr7request */
        $psr7request = $this->createMock(Request::class);
        /** @var MockObject|ResponseInterface $psr7response */
        $psr7response = $this->createMock(Response::class);

        $app = $this->getApp(['make', 'instance', 'get', 'bind']);
        $this->setExpects($app, 'make', [DiactorosFactory::class], $psr7Factory);

        $app->expects($this->atLeastOnce())
            ->method('get')
            ->withConsecutive(['request'], ['response'])
            ->willReturnOnConsecutiveCalls($request, $response);
        $app->expects($this->atLeastOnce())
            ->method('instance')
            ->withConsecutive(
                ['psr7.factory', $psr7Factory],
                ['psr7.request', $psr7request],
                ['psr7.response', $psr7response]
            );
        $app->expects($this->atLeastOnce())
            ->method('bind')
            ->withConsecutive(
                [RequestInterface::class, 'psr7.request'],
                [ResponseInterface::class, 'psr7.response']
            );

        $psr7Factory->expects($this->once())
            ->method('createRequest')
            ->with($request)
            ->willReturn($psr7request);
        $psr7Factory->expects($this->once())
            ->method('createResponse')
            ->with($response)
            ->willReturn($psr7response);

        $serviceProvider = new Psr7ServiceProvider($app);
        $serviceProvider->register();
    }
}