Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php 8.1 compat #166

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.3', '7.4', '8.0']
php: ['7.3', '7.4', '8.0', '8.1']
name: PHP ${{ matrix.php }} tests
steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -5,4 +5,5 @@ vendor
/.idea
/.project
/travisci/tmp
stomp-php.iml
stomp-php.iml
.phpunit.result.cache
31 changes: 18 additions & 13 deletions phpunit.xml
@@ -1,23 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<!-- https://phpunit.readthedocs.io/en/stable/configuration.html -->
<phpunit
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "false"
stopOnFailure = "false"
bootstrap = "tests/bootstrap.php" >
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertDeprecationsToExceptions="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="tests/bootstrap.php"
>
<coverage>
<include>
<directory>src/</directory>
</include>
<exclude>
<directory>vendor/</directory>
</exclude>
<report>
<text outputFile="php://stdout" showUncoveredFiles="true"/>
</report>
</coverage>
<testsuites>
<testsuite name="stomp-php Functional Test Suite">
Expand All @@ -30,7 +35,7 @@
<directory>tests/Unit/</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/>
</logging>
<php>
<ini name="error_reporting" value="-1"/>
</php>
</phpunit>
4 changes: 4 additions & 0 deletions src/Broker/ActiveMq/Options.php
Expand Up @@ -43,23 +43,27 @@ public function __construct(array $options = [])
}
}

#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->options[$offset]);
}

#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->options[$offset];
}

#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if (in_array($offset, $this->extensions, true)) {
$this->options[$offset] = $value;
}
}

#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
unset($this->options[$offset]);
Expand Down
2 changes: 1 addition & 1 deletion src/Protocol/Version.php
Expand Up @@ -69,7 +69,7 @@ public function __construct(Frame $frame)
*/
public function getProtocol($clientId, $default = 'ActiveMQ/5.11.1')
{
$server = trim($this->frame['server']) ?: $default;
$server = trim((string) $this->frame['server']) ?: $default;
$version = $this->getVersion();
if (stristr($server, 'rabbitmq') !== false) {
return new RabbitMq($clientId, $version, $server);
Expand Down
6 changes: 6 additions & 0 deletions src/States/Meta/SubscriptionList.php
Expand Up @@ -59,6 +59,7 @@ public function getSubscription(Frame $frame)
*
* @return \Iterator|Subscription[]
*/
#[\ReturnTypeWillChange]
public function getIterator()
{
return new ArrayIterator($this->subscriptions);
Expand All @@ -69,6 +70,7 @@ public function getIterator()
*
* @return bool
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->subscriptions[$offset]);
Expand All @@ -79,6 +81,7 @@ public function offsetExists($offset)
*
* @return Subscription
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->subscriptions[$offset];
Expand All @@ -87,6 +90,7 @@ public function offsetGet($offset)
/**
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
$this->subscriptions[$offset] = $value;
Expand All @@ -95,6 +99,7 @@ public function offsetSet($offset, $value)
/**
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
unset($this->subscriptions[$offset]);
Expand All @@ -103,6 +108,7 @@ public function offsetUnset($offset)
/**
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function count()
{
return count($this->subscriptions);
Expand Down
4 changes: 4 additions & 0 deletions src/Transport/Frame.php
Expand Up @@ -212,6 +212,7 @@ protected function encodeHeaderValue($value)
/**
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->headers[$offset]);
Expand All @@ -220,6 +221,7 @@ public function offsetExists($offset)
/**
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
if (isset($this->headers[$offset])) {
Expand All @@ -231,6 +233,7 @@ public function offsetGet($offset)
/**
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if ($value !== null) {
Expand All @@ -242,6 +245,7 @@ public function offsetSet($offset, $value)
/**
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
unset($this->headers[$offset]);
Expand Down
8 changes: 4 additions & 4 deletions tests/Functional/Generic/ConnectionTest.php
Expand Up @@ -27,7 +27,7 @@ public function testReadFrameThrowsExceptionIfStreamIsBroken()
{
/** @var Connection|MockObject $connection */
$connection = $this->getMockBuilder(Connection::class)
->setMethods(['hasDataToRead', 'connectSocket'])
->onlyMethods(['hasDataToRead', 'connectSocket'])
->setConstructorArgs(['tcp://host'])
->getMock();

Expand Down Expand Up @@ -55,7 +55,7 @@ public function testReadFrameThrowsExceptionIfErrorFrameIsReceived()
{
/** @var \Stomp\Network\Connection|MockObject $connection */
$connection = $this->getMockBuilder(Connection::class)
->setMethods(['hasDataToRead', 'connectSocket'])
->onlyMethods(['hasDataToRead', 'connectSocket'])
->setConstructorArgs(['tcp://host'])
->getMock();

Expand Down Expand Up @@ -83,7 +83,7 @@ public function testWriteFrameThrowsExceptionIfConnectionIsBroken()
{
/** @var \Stomp\Network\Connection|MockObject $connection */
$connection = $this->getMockBuilder(Connection::class)
->setMethods(['connectSocket'])
->onlyMethods(['connectSocket'])
->setConstructorArgs(['tcp://host'])
->getMock();

Expand All @@ -107,7 +107,7 @@ public function testHasDataToReadThrowsExceptionIfConnectionIsBroken()
{
/** @var \Stomp\Network\Connection|MockObject $connection */
$connection = $this->getMockBuilder(Connection::class)
->setMethods(['isConnected', 'connectSocket'])
->onlyMethods(['isConnected', 'connectSocket'])
->setConstructorArgs(['tcp://host'])
->getMock();

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Broker/ActiveMq/Mode/ActiveMqModeTest.php
Expand Up @@ -27,7 +27,7 @@ public function testGetProtocolWillThrowExceptionIfClientIsNotConnectedToActiveM
{
$client = $this->getMockBuilder(Client::class)
->disableOriginalConstructor()
->setMethods(['getProtocol'])
->onlyMethods(['getProtocol'])
->getMock();

$client->expects($this->any())->method('getProtocol')->willReturn(new RabbitMq('clientid'));
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Broker/Apollo/Mode/QueueBrowserTest.php
Expand Up @@ -26,7 +26,7 @@ public function testBrowserWontWorkWithNonApolloBroker()
{
$client = $this->getMockBuilder(Client::class)
->disableOriginalConstructor()
->setMethods(['getProtocol'])
->onlyMethods(['getProtocol'])
->getMock();
$client->method('getProtocol')->willReturn(new RabbitMq('client-id'));

Expand Down
20 changes: 10 additions & 10 deletions tests/Unit/ClientTest.php
Expand Up @@ -119,7 +119,7 @@ public function testSyncModeIsEnabledByDefault()
public function testConnectWillUseConfiguredVersions()
{
$connection = $this->getMockBuilder(Connection::class)
->setMethods(['readFrame', 'writeFrame', 'getParser', 'isConnected', 'disconnect'])
->onlyMethods(['readFrame', 'writeFrame', 'getParser', 'isConnected', 'disconnect'])
->disableOriginalConstructor()
->getMock();
$connection
Expand Down Expand Up @@ -213,7 +213,7 @@ public function testWaitForReceiptWillThrowExceptionIfConnectionReadTimeoutOccur
protected function getStompWithInjectedMockedConnectionReadResult($readFrameResult)
{
$connection = $this->getMockBuilder(Connection::class)
->setMethods(['readFrame', 'writeFrame', 'getParser', 'isConnected', 'disconnect'])
->onlyMethods(['readFrame', 'writeFrame', 'getParser', 'isConnected', 'disconnect'])
->disableOriginalConstructor()
->getMock();
$connection
Expand Down Expand Up @@ -329,7 +329,7 @@ public function testSendWillConvertStringToFrameBodyAndSetSyncState()
protected function getStompMockWithSendFrameCatcher(&$lastSendFrame, &$lastSyncState)
{
$stomp = $this->getMockBuilder(Client::class)
->setMethods(['sendFrame', 'isConnected'])
->onlyMethods(['sendFrame', 'isConnected'])
->disableOriginalConstructor()
->getMock();

Expand All @@ -352,7 +352,7 @@ function (Frame $frame, $sync) use (&$lastSendFrame, &$lastSyncState) {
public function testSendFrameWithSyncWillLeadToMessageWithReceiptHeader()
{
$connection = $this->getMockBuilder(Connection::class)
->setMethods(['writeFrame', 'readFrame'])
->onlyMethods(['writeFrame', 'readFrame'])
->disableOriginalConstructor()
->getMock();

Expand All @@ -376,7 +376,7 @@ function ($frame) use (&$lastWriteFrame) {
);
$stomp = $this->getMockBuilder(Client::class)
->setConstructorArgs([$connection])
->setMethods(['isConnected'])
->onlyMethods(['isConnected'])
->getMock();
$stomp->expects($this->any())->method('isConnected')->willReturn(true);
/**
Expand All @@ -397,7 +397,7 @@ function ($frame) use (&$lastWriteFrame) {
public function testWaitForReceiptWillQueueUpFramesWithNoReceiptCommand()
{
$connection = $this->getMockBuilder(Connection::class)
->setMethods(['readFrame'])
->onlyMethods(['readFrame'])
->disableOriginalConstructor()
->getMock();

Expand All @@ -424,7 +424,7 @@ function () use (&$readFrames) {

$stomp = $this->getMockBuilder(Client::class)
->setConstructorArgs([$connection])
->setMethods(['isConnected'])
->onlyMethods(['isConnected'])
->getMock();
$stomp->expects($this->any())->method('isConnected')->willReturn(true);
/**
Expand Down Expand Up @@ -469,7 +469,7 @@ public function testDisconnectWillCallConnectionDisconnectEvenWhenWriteFails()
{
$connection = $this->getMockBuilder(Connection::class)
->setConstructorArgs(['tcp://127.0.0.1:'])
->setMethods(['disconnect', 'readFrame', 'writeFrame', 'isConnected'])
->onlyMethods(['disconnect', 'readFrame', 'writeFrame', 'isConnected'])
->getMock();

$connection->expects($this->any())->method('isConnected')->willReturn(true);
Expand Down Expand Up @@ -504,7 +504,7 @@ public function testDisconnectWillCallConnectionDisconnectEvenWhenWriteFails()
public function testClientWillAutoConnectOnSendFrame()
{
$connection = $this->getMockBuilder(Connection::class)
->setMethods(['connect', 'getParser'])
->onlyMethods(['connect', 'getParser'])
->disableOriginalConstructor()
->getMock();
$connection->expects($this->once())->method('connect');
Expand All @@ -521,7 +521,7 @@ public function testClientWillAutoConnectOnSendFrame()
public function testClientWillAutoConnectOnGetProtocol()
{
$connection = $this->getMockBuilder(Connection::class)
->setMethods(['connect', 'getParser'])
->onlyMethods(['connect', 'getParser'])
->disableOriginalConstructor()
->getMock();
$connection->expects($this->once())->method('connect');
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Network/ConnectionTest.php
Expand Up @@ -120,7 +120,7 @@ public function testConnectionSetupTriesFullHostListBeforeGivingUp()
{
/** @var Connection|MockObject $connection */
$connection = $this->getMockBuilder(Connection::class)
->setMethods(['connectSocket'])
->onlyMethods(['connectSocket'])
->setConstructorArgs(['failover://(tcp://host1,tcp://host2,tcp://host3)'])
->getMock();

Expand Down Expand Up @@ -182,7 +182,7 @@ public function testMessageWithNullBytesAfterFullReadWontCauseReadException()
stream_wrapper_register('stompFakeStream', FakeStream::class);

$mock = $this->getMockBuilder(Connection::class)
->setMethods(['getConnection'])
->onlyMethods(['getConnection'])
->setConstructorArgs(['stompFakeStream://notInUse'])
->getMock();
$fakeStreamResource = fopen('stompFakeStream://notInUse', 'rw');
Expand Down Expand Up @@ -212,7 +212,7 @@ public function testSendAliveWillCauseConnectionException()


$mock = $this->getMockBuilder(Connection::class)
->setMethods(['getConnection'])
->onlyMethods(['getConnection'])
->setConstructorArgs(['stompFakeStream://notInUse'])
->getMock();
$fakeStreamResource = fopen('stompFakeStream://notInUse', 'rw');
Expand Down
Expand Up @@ -37,7 +37,7 @@ public function testEventForward()
$frameA = new Message('message-a');
$frameB = new Message('message-b');
$observerA = $this->getMockBuilder(ConnectionObserver::class)
->setMethods(['sentFrame', 'emptyLineReceived', 'emptyBuffer', 'receivedFrame', 'emptyRead'])
->onlyMethods(['sentFrame', 'emptyLineReceived', 'emptyBuffer', 'receivedFrame', 'emptyRead'])
->getMock();
$observerA->expects($this->exactly(1))->method('sentFrame')->with($frameA);
$observerA->expects($this->exactly(1))->method('emptyLineReceived');
Expand All @@ -46,7 +46,7 @@ public function testEventForward()
$observerA->expects($this->exactly(1))->method('receivedFrame')->with($frameB);

$observerB = $this->getMockBuilder(ConnectionObserver::class)
->setMethods(['sentFrame', 'emptyLineReceived', 'emptyBuffer', 'receivedFrame', 'emptyRead'])
->onlyMethods(['sentFrame', 'emptyLineReceived', 'emptyBuffer', 'receivedFrame', 'emptyRead'])
->getMock();
$observerB->expects($this->exactly(1))->method('sentFrame')->with($frameA);
$observerB->expects($this->exactly(1))->method('emptyLineReceived');
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Network/Observer/HeartbeatEmitterTest.php
Expand Up @@ -45,7 +45,7 @@ protected function setUp(): void
parent::setUp();
$this->connection = $this->getMockBuilder(Connection::class)
->disableOriginalConstructor()
->setMethods(['sendAlive', 'getReadTimeout'])
->onlyMethods(['sendAlive', 'getReadTimeout'])
->getMock();
$this->connection->expects($this->any())->method('sendAlive')->willReturnCallback(
function () {
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Network/Observer/ServerAliveObserverTest.php
Expand Up @@ -71,7 +71,7 @@ public function testObserverMapping($activityMethod, $observerMethod = null)
{
$methods = ['rememberActivity', 'checkDelayed'];
$instance = $this->getMockBuilder(ServerAliveObserver::class)
->setMethods($methods)
->onlyMethods($methods)
->getMock();
foreach ($methods as $method) {
$instance->expects(($observerMethod === $method) ? $this->once() : $this->never())
Expand Down