diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 3269d4b78..a43e796cd 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -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 diff --git a/PhpAmqpLib/Connection/AMQPStreamConnection.php b/PhpAmqpLib/Connection/AMQPStreamConnection.php index f9f5c377f..3480d1122 100644 --- a/PhpAmqpLib/Connection/AMQPStreamConnection.php +++ b/PhpAmqpLib/Connection/AMQPStreamConnection.php @@ -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 diff --git a/tests/Unit/Connection/AMQPStreamConnectionTest.php b/tests/Unit/Connection/AMQPStreamConnectionTest.php index fad5b8626..d2988664e 100644 --- a/tests/Unit/Connection/AMQPStreamConnectionTest.php +++ b/tests/Unit/Connection/AMQPStreamConnectionTest.php @@ -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( @@ -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' + ); + } }