RequestApiCommandTest::testExecute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 15
rs 9.9
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AtlassianConnectBundle\Tests\Command;
6
7
use AtlassianConnectBundle\Command\RequestAPICommand;
8
use AtlassianConnectBundle\Entity\TenantInterface;
9
use AtlassianConnectBundle\Repository\TenantRepositoryInterface;
10
use AtlassianConnectBundle\Service\AtlassianRestClientInterface;
11
use PHPUnit\Framework\MockObject\MockObject;
12
use PHPUnit\Framework\TestCase;
13
use Symfony\Component\Console\Application;
14
use Symfony\Component\Console\Tester\CommandTester;
15
16
final class RequestApiCommandTest extends TestCase
17
{
18
    private TenantRepositoryInterface|MockObject $tenantRepository;
19
    private AtlassianRestClientInterface|MockObject$restClient;
20
    private CommandTester $commandTester;
21
22
    protected function setUp(): void
23
    {
24
        $this->tenantRepository = $this->createMock(TenantRepositoryInterface::class);
25
        $this->restClient = $this->createMock(AtlassianRestClientInterface::class);
26
        $application = new Application();
27
        $application->add(new RequestAPICommand($this->tenantRepository, $this->restClient));
28
        $this->commandTester = new CommandTester($application->find('ac:request-api'));
29
    }
30
31
    public function testExecute(): void
32
    {
33
        $this->tenantRepository->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on AtlassianConnectBundle\R...nantRepositoryInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to AtlassianConnectBundle\R...nantRepositoryInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        $this->tenantRepository->/** @scrutinizer ignore-call */ 
34
                                 expects($this->once())
Loading history...
34
            ->method('findById')
35
            ->with('1')
36
            ->willReturn($this->createMock(TenantInterface::class));
37
38
        $this->restClient
39
            ->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on AtlassianConnectBundle\S...sianRestClientInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
            ->/** @scrutinizer ignore-call */ 
40
              expects($this->once())

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
            ->method('get')
41
            ->with('/resource')
42
            ->willReturn('{"message": "ok"}');
43
44
        $this->commandTester->execute(['rest-url' => '/resource', '--tenant-id' => '1'], []);
45
        $this->assertStringContainsString('{"message": "ok"}', $this->commandTester->getDisplay());
46
    }
47
48
    public function testByClientKey(): void
49
    {
50
        $this->tenantRepository->expects($this->once())
51
            ->method('findByClientKey')
52
            ->with('key')
53
            ->willReturn($this->createMock(TenantInterface::class));
54
55
        $this->restClient
56
            ->expects($this->once())
57
            ->method('get')
58
            ->with('/resource')
59
            ->willReturn('{"message": "ok"}');
60
61
        $this->commandTester->execute(['rest-url' => '/resource', '--client-key' => 'key'], []);
62
        $this->assertStringContainsString('{"message": "ok"}', $this->commandTester->getDisplay());
63
    }
64
65
    public function testFails(): void
66
    {
67
        $this->expectException(\RuntimeException::class);
68
        $this->commandTester->execute(['rest-url' => '/resource'], []);
69
    }
70
}
71