Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions legacy/src/Command/Integration/IntegrationCommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,21 @@ private function getFields(): array
return true;
},
]),
'excluded_services' => new ArrayField('Excluded services', [
'optionName' => 'excluded-services',
'conditions' => ['type' => [
'httplog',
'newrelic',
'splunk',
'sumologic',
'syslog',
'otlplog',
]],
'default' => [],
'description' => 'A list of services to exclude from the log forwarding.',
'required' => false,
'avoidQuestion' => true,
]),
];
}

Expand Down
94 changes: 94 additions & 0 deletions legacy/tests/Command/Integration/IntegrationCommandBaseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

declare(strict_types=1);

namespace Platformsh\Cli\Tests\Command\Integration;

use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use Platformsh\Cli\Command\Integration\IntegrationAddCommand;
use Platformsh\ConsoleForm\Field\ArrayField;

#[Group('commands')]
class IntegrationCommandBaseTest extends TestCase
{
/** @var array<string, \Platformsh\ConsoleForm\Field\Field> */
private array $fields;

protected function setUp(): void
{
$command = new IntegrationAddCommand(
$this->createMock(\Platformsh\Cli\Service\ActivityMonitor::class),
$this->createMock(\Platformsh\Cli\Service\QuestionHelper::class),
$this->createMock(\Platformsh\Cli\Selector\Selector::class),
);
$ref = new \ReflectionMethod($command, 'getFields');
$ref->setAccessible(true);
$this->fields = $ref->invoke($command);
}

public function testExcludedServicesFieldExists(): void
{
$this->assertArrayHasKey('excluded_services', $this->fields);
}

public function testExcludedServicesFieldIsArrayField(): void
{
$this->assertInstanceOf(ArrayField::class, $this->fields['excluded_services']);
}

public function testExcludedServicesFieldOptionName(): void
{
$this->assertSame('excluded-services', $this->fields['excluded_services']->getOptionName());
}

public function testExcludedServicesFieldNotRequired(): void
{
$this->assertFalse($this->fields['excluded_services']->isRequired());
}

public function testExcludedServicesFieldConditions(): void
{
$conditions = $this->fields['excluded_services']->getConditions();
$this->assertArrayHasKey('type', $conditions);
$expected = ['httplog', 'newrelic', 'splunk', 'sumologic', 'syslog', 'otlplog'];
$this->assertSame($expected, $conditions['type']);
}

public function testExcludedServicesFieldIncludedForLogForwardingTypes(): void
{
$typeField = $this->fields['type'];
$conditionValues = $this->fields['excluded_services']->getConditions()['type'];
$logTypes = ['httplog', 'newrelic', 'splunk', 'sumologic', 'syslog', 'otlplog'];
foreach ($logTypes as $type) {
$this->assertTrue(
$typeField->matchesCondition($type, $conditionValues),
"Expected excluded_services to be included for type '$type'",
);
}
}

public function testExcludedServicesFieldExcludedForNonLogForwardingTypes(): void
{
$typeField = $this->fields['type'];
$conditionValues = $this->fields['excluded_services']->getConditions()['type'];
$nonLogTypes = [
'bitbucket',
'bitbucket_server',
'github',
'gitlab',
'webhook',
'health.email',
'health.pagerduty',
'health.slack',
'health.webhook',
'script',
];
foreach ($nonLogTypes as $type) {
$this->assertFalse(
$typeField->matchesCondition($type, $conditionValues),
"Expected excluded_services to be excluded for type '$type'",
);
}
}
}
Loading