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
![]() |
|||||||
34 | ->method('findById') |
||||||
35 | ->with('1') |
||||||
36 | ->willReturn($this->createMock(TenantInterface::class)); |
||||||
37 | |||||||
38 | $this->restClient |
||||||
39 | ->expects($this->once()) |
||||||
0 ignored issues
–
show
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
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. ![]() |
|||||||
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 |