OpcacheResetCommandTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 7
dl 0
loc 41
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B testExecute() 0 38 1
1
<?php
2
3
namespace Timegryd\OpcacheResetBundle\Tests\Command;
4
5
use Symfony\Component\Console\Application;
6
use Symfony\Component\Console\Tester\CommandTester;
7
use Symfony\Component\HttpFoundation\Response;
8
use GuzzleHttp\Client as HttpClient;
9
use GuzzleHttp\Psr7\Response as HttpResponse;
10
use Timegryd\OpcacheResetBundle\Helper\OpcacheResetCommandHelper;
11
use Timegryd\OpcacheResetBundle\Command\OpcacheResetCommand;
12
13
class OpcacheResetCommandTest extends \PHPUnit\Framework\TestCase
14
{
15
    public function testExecute()
16
    {
17
        $helper = \Mockery::mock(OpcacheResetCommandHelper::class)
18
            ->shouldReceive('createFile')->once()
19
            ->shouldReceive('generateUrl')->once()
20
            ->shouldReceive('clean')->once()
21
            ->shouldReceive('handleResponse')->once()
22
            ->getMock()
23
        ;
24
25
        $response = \Mockery::mock(HttpResponse::class)
26
            ->shouldReceive('getStatusCode')
27
                ->andReturn(Response::HTTP_OK)
28
            ->shouldReceive('getBody')
29
                ->andReturn('{"success": "true", "message": "Success"}')
30
            ->getMock()
31
        ;
32
33
        $httpClient = \Mockery::mock(HttpClient::class)
34
            ->shouldReceive('request')->once()
35
            ->andReturn($response)
36
            ->getMock()
37
        ;
38
39
        $application = new Application();
40
        $application->add(new OpcacheResetCommand(
41
            'default-host.com',
42
            '/default-dir',
43
            $helper,
44
            $httpClient
45
        ));
46
47
        $command = $application->find('opcache:reset');
48
        $commandTester = new CommandTester($command);
49
        $commandTester->execute(['command' => $command->getName()]);
50
51
        $this->assertEquals('', $commandTester->getDisplay());
52
    }
53
}
54