Skip to content

Commit

Permalink
Fix resolving dsn configuration, small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pulzarraider committed May 14, 2024
1 parent 3b0c80e commit a3e6c1b
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 53 deletions.
121 changes: 93 additions & 28 deletions Tests/Transport/GpsConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public static function dataProvider(): array
'options' => [],
'expectedConfiguration' => new GpsConfiguration(
GpsConfigurationResolverInterface::DEFAULT_TOPIC_NAME,
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
GpsConfigurationResolverInterface::DEFAULT_TOPIC_NAME,
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
[],
[],
[],
Expand All @@ -53,9 +53,9 @@ public static function dataProvider(): array
'options' => [],
'expectedConfiguration' => new GpsConfiguration(
'something',
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
'something',
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
[],
[],
[],
Expand All @@ -67,9 +67,9 @@ public static function dataProvider(): array
'options' => [],
'expectedConfiguration' => new GpsConfiguration(
'topic_name',
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
'subscription_name',
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
[],
[],
[],
Expand All @@ -81,9 +81,9 @@ public static function dataProvider(): array
'options' => [],
'expectedConfiguration' => new GpsConfiguration(
'topic_name',
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
'subscription_name',
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
['apiEndpoint' => 'https://europe-west3-pubsub.googleapis.com'],
['labels' => ['label_topic1']],
['labels' => ['label_subscription1'], 'enableMessageOrdering' => true, 'ackDeadlineSeconds' => 100],
Expand All @@ -97,9 +97,9 @@ public static function dataProvider(): array
],
'expectedConfiguration' => new GpsConfiguration(
'something',
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
'something',
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
[],
[],
[],
Expand All @@ -114,9 +114,9 @@ public static function dataProvider(): array
],
'expectedConfiguration' => new GpsConfiguration(
'topic_name',
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
'subscription_name',
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
[],
[],
[],
Expand Down Expand Up @@ -147,9 +147,9 @@ public static function dataProvider(): array
],
'expectedConfiguration' => new GpsConfiguration(
'topic_name1',
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
'subscription_name',
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
['apiEndpoint' => 'https://europe-west3-pubsub.googleapis.com'],
['labels' => ['label_topic1']],
['labels' => ['label_subscription1'], 'enableMessageOrdering' => true, 'ackDeadlineSeconds' => 100],
Expand All @@ -161,9 +161,9 @@ public static function dataProvider(): array
'options' => [],
'expectedConfiguration' => new GpsConfiguration(
GpsConfigurationResolverInterface::DEFAULT_TOPIC_NAME,
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
GpsConfigurationResolverInterface::DEFAULT_TOPIC_NAME,
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
[],
[],
[],
Expand All @@ -175,9 +175,9 @@ public static function dataProvider(): array
'options' => [],
'expectedConfiguration' => new GpsConfiguration(
GpsConfigurationResolverInterface::DEFAULT_TOPIC_NAME,
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
GpsConfigurationResolverInterface::DEFAULT_TOPIC_NAME,
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
[],
[],
[],
Expand All @@ -196,9 +196,9 @@ public static function dataProvider(): array
],
'expectedConfiguration' => new GpsConfiguration(
GpsConfigurationResolverInterface::DEFAULT_TOPIC_NAME,
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
GpsConfigurationResolverInterface::DEFAULT_TOPIC_NAME,
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
[],
[],
[],
Expand All @@ -217,9 +217,9 @@ public static function dataProvider(): array
],
'expectedConfiguration' => new GpsConfiguration(
GpsConfigurationResolverInterface::DEFAULT_TOPIC_NAME,
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
GpsConfigurationResolverInterface::DEFAULT_TOPIC_NAME,
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
[],
[],
[],
Expand All @@ -228,30 +228,95 @@ public static function dataProvider(): array
],
'Subscription is not created' => [
'dsn' => 'gps://default',
'enableCreation' => false,
'options' => [
'subscription' => [
'createIfNotExist' => false
],
],
'expectedConfiguration' => new GpsConfiguration(
GpsConfigurationResolverInterface::DEFAULT_TOPIC_NAME,
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
GpsConfigurationResolverInterface::DEFAULT_TOPIC_NAME,
false,
[],
[],
[],
['maxMessages' => 5, 'returnImmediately' => true]
['maxMessages' => 10, 'returnImmediately' => false]
),
],
'Topic is not created' => [
'dsn' => 'gps://default',
'enableCreation' => false,
'options' => [
'topic' => [
'createIfNotExist' => false
],
],
'expectedConfiguration' => new GpsConfiguration(
GpsConfigurationResolverInterface::DEFAULT_TOPIC_NAME,
false,
GpsConfigurationResolverInterface::DEFAULT_TOPIC_NAME,
GpsConfigurationResolverInterface::CREATION_ENABLE,
true,
[],
[],
[],
['maxMessages' => 5, 'returnImmediately' => true]
['maxMessages' => 10, 'returnImmediately' => false]
),
],
'DSN: Subscription is not created' => [
'dsn' => 'gps://default?topic[name]=foo&subscription[name]=bar&subscription[createIfNotExist]=false',
'options' => [],
//&topic[createIfNotExist]=true
'expectedConfiguration' => new GpsConfiguration(
'foo',
true,
'bar',
false,
[],
[],
[],
['maxMessages' => 10, 'returnImmediately' => false]
),
],
'DSN: Subscription is not created #2' => [
'dsn' => 'gps://default?topic[name]=foo&topic[createIfNotExist]=true&subscription[name]=bar&subscription[createIfNotExist]=false',
'options' => [],
'expectedConfiguration' => new GpsConfiguration(
'foo',
true,
'bar',
false,
[],
[],
[],
['maxMessages' => 10, 'returnImmediately' => false]
),
],
'DSN: Topic is not created' => [
'dsn' => 'gps://default?topic[name]=foo&topic[createIfNotExist]=false&subscription[name]=bar&subscription[createIfNotExist]=true',
'options' => [],
'expectedConfiguration' => new GpsConfiguration(
'foo',
false,
'bar',
true,
[],
[],
[],
['maxMessages' => 10, 'returnImmediately' => false]
),
],
'DSN: Topic is not created #2' => [
'dsn' => 'gps://default?topic[name]=foo&topic[createIfNotExist]=false&subscription[name]=bar',
'options' => [],
'expectedConfiguration' => new GpsConfiguration(
'foo',
false,
'bar',
true,
[],
[],
[],
['maxMessages' => 10, 'returnImmediately' => false]
),
],
];
Expand Down
10 changes: 10 additions & 0 deletions Tests/Transport/GpsTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ public function testSetup()
->method('getSubscriptionName')
->willReturn($queue);

$this->gpsConfiguration
->expects($this->atLeast(1))
->method('createTopicIfNotExist')
->willReturn(true);

$this->gpsConfiguration
->expects($this->atLeast(1))
->method('createSubscriptionIfNotExist')
->willReturn(true);

$topicMock = $this->createMock(Topic::class);
$topicMock
->expects($this->once())
Expand Down
28 changes: 14 additions & 14 deletions Transport/GpsConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@
final class GpsConfiguration implements GpsConfigurationInterface
{
private string $topicName;
private bool $isTopicEnabled;
private bool $createTopicIfNotExist;
private string $subscriptionName;
private bool $isSubscriptionEnabled;
private bool $createSubscriptionIfNotExist;
private array $clientConfig;
private array $topicOptions;
private array $subscriptionOptions;
private array $subscriptionPullOptions;

public function __construct(
string $queueName,
bool $isTopicEnabled,
bool $isTopicEnabled,
string $subscriptionName,
bool $isSubscriptionEnabled,
array $clientConfig,
array $topicOptions,
array $subscriptionOptions,
array $subscriptionPullOptions
bool $isSubscriptionEnabled,
array $clientConfig,
array $topicOptions,
array $subscriptionOptions,
array $subscriptionPullOptions
) {
$this->topicName = $queueName;
$this->isTopicEnabled = $isTopicEnabled;
$this->createTopicIfNotExist = $isTopicEnabled;
$this->subscriptionName = $subscriptionName;
$this->isSubscriptionEnabled = $isSubscriptionEnabled;
$this->createSubscriptionIfNotExist = $isSubscriptionEnabled;
$this->clientConfig = $clientConfig;
$this->topicOptions = $topicOptions;
$this->subscriptionOptions = $subscriptionOptions;
Expand All @@ -43,19 +43,19 @@ public function getTopicName(): string
return $this->topicName;
}

public function isTopicEnabled(): bool
public function createTopicIfNotExist(): bool
{
return $this->isTopicEnabled;
return $this->createTopicIfNotExist;
}

public function getSubscriptionName(): string
{
return $this->subscriptionName;
}

public function isSubscriptionEnabled(): bool
public function createSubscriptionIfNotExist(): bool
{
return $this->isSubscriptionEnabled;
return $this->createSubscriptionIfNotExist;
}

public function getClientConfig(): array
Expand Down
4 changes: 2 additions & 2 deletions Transport/GpsConfigurationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ interface GpsConfigurationInterface
{
public function getTopicName(): string;

public function isTopicEnabled(): bool;
public function createTopicIfNotExist(): bool;

public function getSubscriptionName(): string;

public function isSubscriptionEnabled(): bool;
public function createSubscriptionIfNotExist(): bool;

/**
* @see PubSubClient constructor options
Expand Down
Loading

0 comments on commit a3e6c1b

Please sign in to comment.