diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cb5295b..ac0b2bb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [8.0, 8.1, 8.2] + php: [8.1, 8.2, 8.3] steps: - uses: actions/checkout@v3 - name: Setup PHP diff --git a/.gitignore b/.gitignore index 50b321e..2976cf1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ vendor composer.lock -.phpunit.result.cache +/.phpunit.cache diff --git a/composer.json b/composer.json index cdee5d7..9795148 100644 --- a/composer.json +++ b/composer.json @@ -18,15 +18,15 @@ } ], "require": { - "php": ">=7.2", + "php": ">=8.1", "ext-json": "*", - "illuminate/queue": "5.7.* | 5.8.* | ^6.0 | ^7.0 | ^8.0 | ^9.0|^10.0 | ^11.0", - "illuminate/support": "5.7.* | 5.8.* | ^6.0 | ^7.0 | ^8.0 | ^9.0|^10.0 | ^11.0", + "illuminate/queue": "5.7.* | 5.8.* | ^6.0 | ^7.0 | ^8.0 | ^9.0| ^10.0 | ^11.0", + "illuminate/support": "5.7.* | 5.8.* | ^6.0 | ^7.0 | ^8.0 | ^9.0| ^10.0 | ^11.0", "google/cloud-pubsub": "^1.1", "ramsey/uuid": "^2.0|^3.0|^4.0" }, "require-dev": { - "phpunit/phpunit": "^8.0|^9.0 | ^10.5" + "phpunit/phpunit": "^10.0" }, "autoload": { "psr-4": { @@ -49,4 +49,4 @@ } }, "minimum-stability": "stable" -} +} \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 988d7c8..4c8b578 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,25 +1,22 @@ - - - - src/ - - + ./tests/ + + + src/ + + diff --git a/tests/Unit/Connectors/PubSubConnectorTests.php b/tests/Unit/Connectors/PubSubConnectorTests.php index 052202c..5821831 100644 --- a/tests/Unit/Connectors/PubSubConnectorTests.php +++ b/tests/Unit/Connectors/PubSubConnectorTests.php @@ -8,16 +8,16 @@ use PHPUnit\Framework\TestCase; use ReflectionClass; -class PubSubConnectorTests extends TestCase +final class PubSubConnectorTests extends TestCase { - public function testImplementsConnectorInterface() + public function testImplementsConnectorInterface(): void { putenv('SUPPRESS_GCLOUD_CREDS_WARNING=true'); $reflection = new ReflectionClass(PubSubConnector::class); $this->assertTrue($reflection->implementsInterface(ConnectorInterface::class)); } - public function testConnectReturnsPubSubQueueInstance() + public function testConnectReturnsPubSubQueueInstance(): void { $connector = new PubSubConnector; $config = $this->createFakeConfig(); @@ -27,7 +27,7 @@ public function testConnectReturnsPubSubQueueInstance() $this->assertEquals($queue->getSubscriberName(), 'test-subscriber'); } - public function testQueuePrefixAdded() + public function testQueuePrefixAdded(): void { $connector = new PubSubConnector(); $config = $this->createFakeConfig() + ['queue_prefix' => 'prefix-']; @@ -36,7 +36,7 @@ public function testQueuePrefixAdded() $this->assertEquals('prefix-my-queue', $queue->getQueue('my-queue')); } - public function testNotQueuePrefixAddedMultipleTimes() + public function testNotQueuePrefixAddedMultipleTimes(): void { $connector = new PubSubConnector(); $config = $this->createFakeConfig() + ['queue_prefix' => 'prefix-']; diff --git a/tests/Unit/Jobs/PubSubJobTests.php b/tests/Unit/Jobs/PubSubJobTests.php index f5a2d58..57acbe1 100644 --- a/tests/Unit/Jobs/PubSubJobTests.php +++ b/tests/Unit/Jobs/PubSubJobTests.php @@ -11,7 +11,7 @@ use PHPUnit\Framework\TestCase; use ReflectionClass; -class PubSubJobTests extends TestCase +final class PubSubJobTests extends TestCase { /** * @var string @@ -29,31 +29,31 @@ class PubSubJobTests extends TestCase protected $messageEncodedData; /** - * @var Container + * @var \PHPUnit\Framework\MockObject\MockObject&Container */ protected $container; /** - * @var PubSubQueue + * @var \PHPUnit\Framework\MockObject\MockObject&PubSubQueue */ protected $queue; /** - * @var PubSubClient + * @var \PHPUnit\Framework\MockObject\MockObject&PubSubClient */ protected $client; /** - * @var Message + * @var \PHPUnit\Framework\MockObject\MockObject&Message */ protected $message; /** - * @var PubSubJob + * @var \PHPUnit\Framework\MockObject\MockObject&PubSubJob */ protected $job; - public function setUp(): void + protected function setUp(): void { $this->messageId = '1234'; $this->messageData = json_encode(['id' => $this->messageId, 'foo' => 'bar']); @@ -65,7 +65,7 @@ public function setUp(): void $this->message = $this->getMockBuilder(Message::class) ->setConstructorArgs([[], []]) - ->setMethods(['data', 'id', 'attributes']) + ->onlyMethods(['data', 'id', 'attributes']) ->getMock(); $this->message->method('data') @@ -80,38 +80,38 @@ public function setUp(): void $this->job = $this->getMockBuilder(PubSubJob::class) ->setConstructorArgs([$this->container, $this->queue, $this->message, 'test', 'test']) - ->setMethods() + ->onlyMethods([]) ->getMock(); } - public function testImplementsJobInterface() + public function testImplementsJobInterface(): void { $reflection = new ReflectionClass(PubSubJob::class); $this->assertTrue($reflection->implementsInterface(JobContract::class)); } - public function testGetJobId() + public function testGetJobId(): void { $this->assertEquals($this->job->getJobId(), $this->messageId); } - public function testGetRawBody() + public function testGetRawBody(): void { $this->assertEquals($this->job->getRawBody(), $this->messageData); } - public function testDeleteMethodSetDeletedProperty() + public function testDeleteMethodSetDeletedProperty(): void { $this->job->delete(); $this->assertTrue($this->job->isDeleted()); } - public function testAttempts() + public function testAttempts(): void { $this->assertTrue(is_int($this->job->attempts())); } - public function testReleaseAndPublish() + public function testReleaseAndPublish(): void { $this->queue->expects($this->once()) ->method('republish') @@ -136,7 +136,7 @@ public function testReleaseAndPublish() $this->job->release(); } - public function testReleaseMethodSetReleasedProperty() + public function testReleaseMethodSetReleasedProperty(): void { $this->job->release(); $this->assertTrue($this->job->isReleased()); diff --git a/tests/Unit/PubSubQueueTests.php b/tests/Unit/PubSubQueueTests.php index 8b36ece..b9a1a7a 100644 --- a/tests/Unit/PubSubQueueTests.php +++ b/tests/Unit/PubSubQueueTests.php @@ -14,7 +14,7 @@ use PHPUnit\Framework\TestCase; use ReflectionClass; -class PubSubQueueTests extends TestCase +final class PubSubQueueTests extends TestCase { /** * @var string @@ -22,31 +22,31 @@ class PubSubQueueTests extends TestCase protected $expectedResult = 'message-id'; /** - * @var Topic + * @var \PHPUnit\Framework\MockObject\MockObject&Topic */ protected $topic; /** - * @var PubSubClient + * @var \PHPUnit\Framework\MockObject\MockObject&PubSubClient */ protected $client; /** - * @var Subscription + * @var \PHPUnit\Framework\MockObject\MockObject&Subscription */ protected $subscription; /** - * @var Message + * @var \PHPUnit\Framework\MockObject\MockObject&Message */ protected $message; /** - * @var PubSubQueue + * @var \PHPUnit\Framework\MockObject\MockObject&PubSubQueue */ protected $queue; - public function setUp(): void + protected function setUp(): void { $this->expectedResult = 'message-id'; @@ -57,23 +57,21 @@ public function setUp(): void $this->queue = $this->getMockBuilder(PubSubQueue::class) ->setConstructorArgs([$this->client, 'default']) - ->setMethods([ + ->onlyMethods([ 'pushRaw', 'getTopic', - 'exists', - 'subscription', 'availableAt', 'subscribeToTopic', ])->getMock(); } - public function testImplementsQueueInterface() + public function testImplementsQueueInterface(): void { $reflection = new ReflectionClass(PubSubQueue::class); $this->assertTrue($reflection->implementsInterface(QueueContract::class)); } - public function testPushNewJob() + public function testPushNewJob(): void { $job = 'test'; $data = ['foo' => 'bar']; @@ -90,11 +88,12 @@ public function testPushNewJob() $this->assertEquals($this->expectedResult, $this->queue->push('test', $data)); } - public function testPushRaw() + public function testPushRaw(): void { + /** @var \PHPUnit\Framework\MockObject\MockObject&PubSubQueue $queue */ $queue = $this->getMockBuilder(PubSubQueue::class) ->setConstructorArgs([$this->client, 'default']) - ->setMethods(['getTopic', 'subscribeToTopic']) + ->onlyMethods(['getTopic', 'subscribeToTopic']) ->getMock(); $payload = json_encode(['id' => $this->expectedResult]); @@ -116,13 +115,14 @@ public function testPushRaw() $this->assertEquals($this->expectedResult, $queue->pushRaw($payload)); } - public function testPushRawOptionsOnlyAcceptKeyValueStrings() + public function testPushRawOptionsOnlyAcceptKeyValueStrings(): void { $this->expectException(\UnexpectedValueException::class); + /** @var \PHPUnit\Framework\MockObject\MockObject&PubSubQueue $queue */ $queue = $this->getMockBuilder(PubSubQueue::class) ->setConstructorArgs([$this->client, 'default']) - ->setMethods(['getTopic', 'subscribeToTopic']) + ->onlyMethods(['getTopic', 'subscribeToTopic']) ->getMock(); $this->topic->method('publish') @@ -148,7 +148,7 @@ public function testPushRawOptionsOnlyAcceptKeyValueStrings() $queue->pushRaw($payload, '', $options); } - public function testLater() + public function testLater(): void { $job = 'test'; $delay = 60; @@ -185,7 +185,7 @@ public function testLater() $this->assertEquals($this->expectedResult, $this->queue->later($delay, $job, ['foo' => 'bar'])); } - public function testPopWhenJobsAvailable() + public function testPopWhenJobsAvailable(): void { $this->subscription->expects($this->once()) ->method('acknowledge'); @@ -210,7 +210,7 @@ public function testPopWhenJobsAvailable() $this->assertTrue($this->queue->pop('test') instanceof PubSubJob); } - public function testPopWhenNoJobAvailable() + public function testPopWhenNoJobAvailable(): void { $this->subscription->expects($this->exactly(0)) ->method('acknowledge'); @@ -230,7 +230,7 @@ public function testPopWhenNoJobAvailable() $this->assertTrue(is_null($this->queue->pop('test'))); } - public function testPopWhenTopicDoesNotExist() + public function testPopWhenTopicDoesNotExist(): void { $this->queue->method('getTopic') ->willReturn($this->topic); @@ -241,7 +241,7 @@ public function testPopWhenTopicDoesNotExist() $this->assertTrue(is_null($this->queue->pop('test'))); } - public function testPopWhenJobDelayed() + public function testPopWhenJobDelayed(): void { $delay = 60; $timestamp = Carbon::now()->addSeconds($delay)->getTimestamp(); @@ -266,7 +266,7 @@ public function testPopWhenJobDelayed() $this->assertTrue(is_null($this->queue->pop('test'))); } - public function testBulk() + public function testBulk(): void { $jobs = ['test']; $data = ['foo' => 'bar']; @@ -289,7 +289,7 @@ public function testBulk() $this->assertEquals($this->expectedResult, $this->queue->bulk($jobs, $data)); } - public function testAcknowledge() + public function testAcknowledge(): void { $this->subscription->expects($this->once()) ->method('acknowledge'); @@ -303,7 +303,7 @@ public function testAcknowledge() $this->queue->acknowledge($this->message); } - public function testRepublish() + public function testRepublish(): void { $options = ['foo' => 'bar']; $delay = 60; @@ -358,7 +358,7 @@ public function testRepublish() $this->queue->republish($this->message, 'test', $options, $delay); } - public function testRepublishOptionsOnlyAcceptString() + public function testRepublishOptionsOnlyAcceptString(): void { $this->expectException(\UnexpectedValueException::class); @@ -389,7 +389,7 @@ public function testRepublishOptionsOnlyAcceptString() $this->queue->republish($this->message, 'test', $options, $delay); } - public function testGetTopic() + public function testGetTopic(): void { $this->topic->method('exists') ->willReturn(true); @@ -397,15 +397,16 @@ public function testGetTopic() $this->client->method('topic') ->willReturn($this->topic); + /** @var \PHPUnit\Framework\MockObject\MockObject&PubSubQueue $queue */ $queue = $this->getMockBuilder(PubSubQueue::class) ->setConstructorArgs([$this->client, 'default']) - ->setMethods() + ->onlyMethods([]) ->getMock(); $this->assertTrue($queue->getTopic('test') instanceof Topic); } - public function testCreateTopicAndReturnIt() + public function testCreateTopicAndReturnIt(): void { $this->topic->method('exists') ->willReturn(false); @@ -417,15 +418,16 @@ public function testCreateTopicAndReturnIt() $this->client->method('topic') ->willReturn($this->topic); + /** @var \PHPUnit\Framework\MockObject\MockObject&PubSubQueue $queue */ $queue = $this->getMockBuilder(PubSubQueue::class) ->setConstructorArgs([$this->client, 'default']) - ->setMethods() + ->onlyMethods([]) ->getMock(); $this->assertTrue($queue->getTopic('test', true) instanceof Topic); } - public function testSubscribtionIsCreated() + public function testSubscribtionIsCreated(): void { $this->topic->method('subscription') ->willReturn($this->subscription); @@ -436,15 +438,16 @@ public function testSubscribtionIsCreated() $this->subscription->method('exists') ->willReturn(false); + /** @var \PHPUnit\Framework\MockObject\MockObject&PubSubQueue $queue */ $queue = $this->getMockBuilder(PubSubQueue::class) ->setConstructorArgs([$this->client, 'default']) - ->setMethods() + ->onlyMethods([]) ->getMock(); $this->assertTrue($queue->subscribeToTopic($this->topic) instanceof Subscription); } - public function testSubscriptionIsRetrieved() + public function testSubscriptionIsRetrieved(): void { $this->topic->method('subscription') ->willReturn($this->subscription); @@ -452,26 +455,28 @@ public function testSubscriptionIsRetrieved() $this->subscription->method('exists') ->willReturn(true); + /** @var \PHPUnit\Framework\MockObject\MockObject&PubSubQueue $queue */ $queue = $this->getMockBuilder(PubSubQueue::class) ->setConstructorArgs([$this->client, 'default']) - ->setMethods() + ->onlyMethods([]) ->getMock(); $this->assertTrue($queue->subscribeToTopic($this->topic) instanceof Subscription); } - public function testGetSubscriberName() + public function testGetSubscriberName(): void { + /** @var \PHPUnit\Framework\MockObject\MockObject&PubSubQueue $queue */ $queue = $this->getMockBuilder(PubSubQueue::class) ->setConstructorArgs([$this->client, 'default', 'test-subscriber']) - ->setMethods() + ->onlyMethods([]) ->getMock(); $this->assertTrue(is_string($queue->getSubscriberName())); $this->assertEquals($queue->getSubscriberName(), 'test-subscriber'); } - public function testGetPubSub() + public function testGetPubSub(): void { $this->assertTrue($this->queue->getPubSub() instanceof PubSubClient); }