Skip to content

Commit

Permalink
PHPUnit 10 Shift (#72)
Browse files Browse the repository at this point in the history
* Bump PHPUnit dependencies

* Set return type of base TestCase methods

From the [PHPUnit 8 release notes][1], the `TestCase` methods below now declare a `void` return type:

- `setUpBeforeClass()`
- `setUp()`
- `assertPreConditions()`
- `assertPostConditions()`
- `tearDown()`
- `tearDownAfterClass()`
- `onNotSuccessfulTest()`

[1]: https://phpunit.de/announcements/phpunit-8.html

* Ignore PHPUnit cache folder

* Add return types to test methods

* Define test classes as `final`

* Fix tests and upgrade supported php version to 8.1

---------

Co-authored-by: Shift <[email protected]>
  • Loading branch information
kainxspirits and laravel-shift authored Mar 3, 2024
1 parent d6b6f8d commit 470ac83
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
vendor
composer.lock
.phpunit.result.cache
/.phpunit.cache
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -49,4 +49,4 @@
}
},
"minimum-stability": "stable"
}
}
33 changes: 15 additions & 18 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
verbose="true">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
processIsolation="false"
stopOnFailure="false"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false">
<testsuites>
<testsuite name="tests">
<directory suffix="Tests.php">./tests/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
10 changes: 5 additions & 5 deletions tests/Unit/Connectors/PubSubConnectorTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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-'];
Expand All @@ -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-'];
Expand Down
32 changes: 16 additions & 16 deletions tests/Unit/Jobs/PubSubJobTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use PHPUnit\Framework\TestCase;
use ReflectionClass;

class PubSubJobTests extends TestCase
final class PubSubJobTests extends TestCase
{
/**
* @var string
Expand All @@ -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']);
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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());
Expand Down
Loading

0 comments on commit 470ac83

Please sign in to comment.