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

Trigger ssl_protocol deprecation when it is really not null and not AMQPConnectionConfig instance #1162

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
4 changes: 2 additions & 2 deletions .github/workflows/phpunit.yml
Expand Up @@ -89,11 +89,11 @@ jobs:
run: php ./tests/wait_broker.php

- name: PHPUnit tests
run: ./vendor/bin/phpunit
run: ./vendor/bin/phpunit -d memory_limit=512M
if: matrix.coverage == 'none'

- name: PHPUnit tests + coverage
run: ./vendor/bin/phpunit --coverage-clover=coverage.xml
run: ./vendor/bin/phpunit -d memory_limit=512M --coverage-clover=coverage.xml
if: matrix.coverage != 'none'

- name: Upload Codecov coverage
Expand Down
2 changes: 1 addition & 1 deletion PhpAmqpLib/Connection/AMQPStreamConnection.php
Expand Up @@ -45,7 +45,7 @@ public function __construct(
$ssl_protocol = null,
?AMQPConnectionConfig $config = null
) {
if (func_num_args() === 17 || ($ssl_protocol !== null && $ssl_protocol instanceof AMQPConnectionConfig === false)) {
if ($ssl_protocol !== null && $ssl_protocol instanceof AMQPConnectionConfig === false) {
trigger_error(
'$ssl_protocol parameter is deprecated, use stream_context_set_option($context, \'ssl\', \'crypto_method\', $ssl_protocol) instead (see https://www.php.net/manual/en/function.stream-socket-enable-crypto.php for possible values)',
E_USER_DEPRECATED
Expand Down
81 changes: 79 additions & 2 deletions tests/Unit/Connection/AMQPStreamConnectionTest.php
Expand Up @@ -2,17 +2,19 @@

namespace PhpAmqpLib\Tests\Unit\Connection;

use InvalidArgumentException;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PHPUnit\Framework\TestCase;
use RuntimeException;

class AMQPStreamConnectionTest extends TestCase
{
/**
* @test
*/
public function channel_rpc_timeout_should_be_invalid_if_greater_than_read_write_timeout()
public function channel_rpc_timeout_should_be_invalid_if_greater_than_read_write_timeout(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('channel RPC timeout must not be greater than I/O read-write timeout');

new AMQPStreamConnection(
Expand All @@ -33,4 +35,79 @@ public function channel_rpc_timeout_should_be_invalid_if_greater_than_read_write
5.0
);
}

/**
* @test
* Generate deprecation warning if ssl_protocol is set
*/
public function trigger_deprecation_is_ssl_protocl_set(): void
{
// this is a workaround for deprecated PHPUnit functions
set_error_handler(
static function ($errno, $errstr) {
restore_error_handler();
throw new RuntimeException($errstr, $errno);
},
E_USER_DEPRECATED
);

$this->expectException(RuntimeException::class);
$this->expectExceptionMessage(
'$ssl_protocol parameter is deprecated, use stream_context_set_option($context, \'ssl\', \'crypto_method\', $ssl_protocol) instead (see https://www.php.net/manual/en/function.stream-socket-enable-crypto.php for possible values)'
);

new AMQPStreamConnection(
HOST,
PORT,
USER,
PASS,
VHOST,
false,
'AMQPLAIN',
null,
'en_US',
3.0,
3.0,
null,
false,
0,
3.0,
'test_ssl_protocol'
);
}

/**
* @test
* Generate deprecation warning if ssl_protocol is set with named parameters
*/
public function trigger_deprecation_is_ssl_protocl_set_with_named_params(): void
{
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('Named parameters are available in PHP 8.0+');
}

// this is a workaround for deprecated PHPUnit functions
set_error_handler(
static function ($errno, $errstr) {
restore_error_handler();
throw new RuntimeException($errstr, $errno);
},
E_USER_DEPRECATED
);

$this->expectException(RuntimeException::class);
$this->expectExceptionMessage(
'$ssl_protocol parameter is deprecated, use stream_context_set_option($context, \'ssl\', \'crypto_method\', $ssl_protocol) instead (see https://www.php.net/manual/en/function.stream-socket-enable-crypto.php for possible values)'
);

new AMQPStreamConnection(
host: HOST,
port: PORT,
user: USER,
password: PASS,
vhost: VHOST,
channel_rpc_timeout: 3.0,
ssl_protocol: 'test_ssl_protocol'
);
}
}