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

Fix Actions and update PHP matrix #174

Merged
merged 7 commits into from
Jun 19, 2023
Merged
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
53 changes: 37 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,65 @@
name: CI
on: [pull_request]
on:
pull_request:
branches:
- 'master'
push:
branches:
- '**'

jobs:
static_analysis:
name: Static analysis with phpstan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: phpstan, composer:v2

- uses: "ramsey/composer-install@v1"

- run: composer require --dev phpstan/phpstan

- run: vendor/bin/phpstan analyse
- run: phpstan analyse

tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
fail-fast: true
matrix:
php: ['7.3', '7.4', '8.0']
php: ['7.4', '8.0', '8.1', '8.2']
name: PHP ${{ matrix.php }} tests
steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v3

- uses: shivammathur/setup-php@v2
- name: Setup Brokers
run: ./travisci/bin/start.sh

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug
ini-values: error_reporting=E_ALL
tools: composer:v2

- name: Get composer cache directory
id: composercache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- run: ./travisci/bin/start.sh
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- uses: "ramsey/composer-install@v1"
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- run: |
- name: Run tests
run: |
./travisci/bin/logs.sh
vendor/bin/phpunit --debug

- run: ./travisci/bin/stop.sh
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
12 changes: 4 additions & 8 deletions src/Network/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,7 @@ public function readFrame()
return $this->onFrame($frame);
}

if (!$this->hasDataToRead()) {
return false;
}

do {
while ($this->hasDataToRead()) {
$read = @fread($this->connection, $this->maxReadBytes);
if ($read === false) {
throw new ConnectionException(sprintf('Was not possible to read data from stream.'), $this->activeHost);
Expand All @@ -546,7 +542,7 @@ public function readFrame()
if ($frame = $this->parser->nextFrame()) {
return $this->onFrame($frame);
}
} while ($this->hasDataToRead());
}

return false;
}
Expand Down Expand Up @@ -638,7 +634,7 @@ private function isDataOnStream()
if ($hasStreamInfo === false) {
// can return `false` if used in combination with `pcntl_signal` and lead to false errors here
$error = error_get_last();
if ($error && isset($error['message']) && stripos($error['message'], 'interrupted system call') === false) {
if ($error && stripos($error['message'], 'interrupted system call') === false) {
throw new ConnectionException(
'Check failed to determine if the socket is readable.',
$this->activeHost
Expand All @@ -647,7 +643,7 @@ private function isDataOnStream()
return null;
}

return !empty($read);
return $hasStreamInfo > 0;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Protocol/Version.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
1 change: 1 addition & 0 deletions src/Transport/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public function parse()
$this->frame = null;
$this->offset = 0;
$this->bufferSize = strlen($this->buffer);
/** @phpstan-ignore-next-line */
while ($this->offset < $this->bufferSize) {
if ($this->mode === self::MODE_HEADER) {
$this->skipEmptyLines();
Expand Down
11 changes: 6 additions & 5 deletions src/Util/IdGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ class IdGenerator
public static function generateId()
{
while ($rand = rand(1, PHP_INT_MAX)) {
if (!in_array($rand, static::$generatedIds, true)) {
static::$generatedIds[] = $rand;
if (!in_array($rand, self::$generatedIds, true)) {
self::$generatedIds[] = $rand;
return $rand;
}
}
throw new RuntimeException('Message Id generation failed.');
// This is never hit because the above becomes an infinite loop. Possibly need a release valve.
// throw new RuntimeException('Message Id generation failed.');
}

/**
Expand All @@ -46,9 +47,9 @@ public static function generateId()
*/
public static function releaseId($generatedId)
{
$index = array_search($generatedId, static::$generatedIds, true);
$index = array_search($generatedId, self::$generatedIds, true);
if ($index !== false) {
unset(static::$generatedIds[$index]);
unset(self::$generatedIds[$index]);
}
}
}
8 changes: 4 additions & 4 deletions tests/Functional/Generic/ConnectionTest.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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