|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Buddy\Repman\Tests\Functional\Command; |
| 6 | + |
| 7 | +use Buddy\Repman\Command\SynchronizeAllPackagesCommand; |
| 8 | +use Buddy\Repman\Message\Security\ScanPackage; |
| 9 | +use Buddy\Repman\Tests\Functional\FunctionalTestCase; |
| 10 | +use Symfony\Component\Console\Tester\CommandTester; |
| 11 | +use Symfony\Component\Messenger\Transport\InMemoryTransport; |
| 12 | + |
| 13 | +final class SynchronizeAllPackagesCommandTest extends FunctionalTestCase |
| 14 | +{ |
| 15 | + private string $buddyId; |
| 16 | + |
| 17 | + protected function setUp(): void |
| 18 | + { |
| 19 | + parent::setUp(); |
| 20 | + |
| 21 | + $userId = $this->createAndLoginAdmin(); |
| 22 | + $this->buddyId = $this->fixtures->createOrganization('buddy', $userId); |
| 23 | + |
| 24 | + $packageId = $this->fixtures->addPackage($this->buddyId, 'https://buddy.com'); |
| 25 | + $this->fixtures->syncPackageWithData($packageId, 'buddy-works/buddy', 'Test', '1.1.1', new \DateTimeImmutable()); |
| 26 | + } |
| 27 | + |
| 28 | + public function testSynchronizeAllSuccess(): void |
| 29 | + { |
| 30 | + /** @var InMemoryTransport $transport */ |
| 31 | + $transport = $this->container()->get('messenger.transport.async'); |
| 32 | + $transport->reset(); |
| 33 | + |
| 34 | + $commandTester = new CommandTester($this->container()->get(SynchronizeAllPackagesCommand::class)); |
| 35 | + $result = $commandTester->execute([]); |
| 36 | + |
| 37 | + self::assertCount(1, $transport->getSent()); |
| 38 | + self::assertInstanceOf(ScanPackage::class, $transport->getSent()[0]->getMessage()); |
| 39 | + self::assertEquals($result, 0); |
| 40 | + } |
| 41 | + |
| 42 | + public function testSynchronizeAllOrganizationSuccess(): void |
| 43 | + { |
| 44 | + $alias = 'buddy'; |
| 45 | + /** @var InMemoryTransport $transport */ |
| 46 | + $transport = $this->container()->get('messenger.transport.async'); |
| 47 | + $transport->reset(); |
| 48 | + |
| 49 | + $commandTester = new CommandTester($this->container()->get(SynchronizeAllPackagesCommand::class)); |
| 50 | + $result = $commandTester->execute(['organization' => $alias]); |
| 51 | + |
| 52 | + self::assertCount(1, $transport->getSent()); |
| 53 | + self::assertInstanceOf(ScanPackage::class, $transport->getSent()[0]->getMessage()); |
| 54 | + self::assertEquals($result, 0); |
| 55 | + } |
| 56 | + |
| 57 | + public function testSynchronizeAllOrganizationFailure(): void |
| 58 | + { |
| 59 | + $alias = 'non-existing-alias'; |
| 60 | + |
| 61 | + $this->expectException(\InvalidArgumentException::class); |
| 62 | + $this->expectExceptionMessage(sprintf('Organization with alias %s not found.', $alias)); |
| 63 | + |
| 64 | + /** @var InMemoryTransport $transport */ |
| 65 | + $transport = $this->container()->get('messenger.transport.async'); |
| 66 | + $transport->reset(); |
| 67 | + |
| 68 | + $commandTester = new CommandTester($this->container()->get(SynchronizeAllPackagesCommand::class)); |
| 69 | + $commandTester->execute(['organization' => $alias]); |
| 70 | + } |
| 71 | +} |
0 commit comments