-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from mermshaus/update-tests-php8
Update tests to work in PHP 8 Docker Compose setup
- Loading branch information
Showing
11 changed files
with
152 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,37 @@ | ||
#!/bin/bash | ||
|
||
set -eu | ||
set -eux | ||
|
||
is_rabbitmq_gte_3_7_0() { | ||
[[ "3.7.0" = $(echo -e "3.7.0\n$RABBITMQ_VERSION" | sort -V | head -n1) ]] | ||
} | ||
|
||
install_certs() { | ||
local certs_dir="/rabbitmq-certs" | ||
|
||
rm -rf "${certs_dir}" | ||
mkdir "${certs_dir}" | ||
cp "${TEST_DATA_ROOT}"/{ca.pem,server.pem,server.key} "${certs_dir}" | ||
chown rabbitmq "${certs_dir}"/{ca.pem,server.pem,server.key} | ||
chmod 0400 "${certs_dir}"/{ca.pem,server.pem,server.key} | ||
} | ||
|
||
install_config() { | ||
if [[ -n "$CONFIG_NAME" ]]; then | ||
if is_rabbitmq_gte_3_7_0; then | ||
cp "${TEST_DATA_ROOT}/${CONFIG_NAME}.conf" /etc/rabbitmq/rabbitmq.conf | ||
chown rabbitmq /etc/rabbitmq/rabbitmq.conf | ||
else | ||
cp "${TEST_DATA_ROOT}/${CONFIG_NAME}.config" /etc/rabbitmq/rabbitmq.config | ||
chown rabbitmq /etc/rabbitmq/rabbitmq.config | ||
fi | ||
fi | ||
} | ||
|
||
TEST_DATA_ROOT=/opt/bunny/test/ssl | ||
CONFIG_NAME=${CONFIG_NAME:-} | ||
|
||
cp ${TEST_DATA_ROOT}/{ca.pem,server.pem,server.key} /etc/rabbitmq/ | ||
chown rabbitmq /etc/rabbitmq/{ca.pem,server.pem,server.key} | ||
chmod 0400 /etc/rabbitmq/{ca.pem,server.pem,server.key} | ||
|
||
if [[ -n "$CONFIG_NAME" ]]; then | ||
if is_rabbitmq_gte_3_7_0; then | ||
cp ${TEST_DATA_ROOT}/${CONFIG_NAME}.conf /etc/rabbitmq/rabbitmq.conf | ||
chown rabbitmq /etc/rabbitmq/rabbitmq.conf | ||
else | ||
cp ${TEST_DATA_ROOT}/${CONFIG_NAME}.config /etc/rabbitmq/rabbitmq.config | ||
chown rabbitmq /etc/rabbitmq/rabbitmq.config | ||
fi | ||
fi | ||
install_certs | ||
install_config | ||
|
||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.5/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true"> | ||
|
||
<testsuites> | ||
<testsuite name="Tests"> | ||
<directory suffix="Test.php">test/Bunny</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">src</directory> | ||
</whitelist> | ||
</filter> | ||
|
||
<php> | ||
<!-- This is the default configuration when running the test suite | ||
through the docker-compose setup --> | ||
<env name="TEST_RABBITMQ_CONNECTION_URI" value="amqp://guest:guest@localhost:5672/"/> | ||
|
||
<!-- RabbitMQ running on localhost with default user (guest:guest) and | ||
vhost "/" would be (slashes in the actual vhost name need to be | ||
percent-encoded, see https://www.rabbitmq.com/uri-spec.html): --> | ||
<!--<env name="TEST_RABBITMQ_CONNECTION_URI" value="amqp://localhost:5672/%2f"/>--> | ||
</php> | ||
|
||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true"> | ||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">src</directory> | ||
</include> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="Tests"> | ||
<directory suffix="Test.php">test/Bunny</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bunny\Test\Library; | ||
|
||
final class Environment | ||
{ | ||
public static function getSslCa(): string | ||
{ | ||
return trim(self::getenv('SSL_CA')); | ||
} | ||
|
||
public static function getSslClientCert(): string | ||
{ | ||
return trim(self::getenv('SSL_CLIENT_CERT', '')); | ||
} | ||
|
||
public static function getSslClientKey(): string | ||
{ | ||
return trim(self::getenv('SSL_CLIENT_KEY', '')); | ||
} | ||
|
||
public static function getSslPeerName(): string | ||
{ | ||
return trim(self::getenv('SSL_PEER_NAME')); | ||
} | ||
|
||
/** | ||
* Can have the following values: | ||
* | ||
* - "client" -> run all SSL tests, expect peer cert (c.f. rabbitmq.ssl.verify_peer.conf) | ||
* - "yes" -> run all SSL tests, do *not* expect peer cert (c.f. rabbitmq.ssl.verify_none.conf) | ||
* - "no" (default) -> skip SSL-related tests | ||
*/ | ||
public static function getSslTest(): string | ||
{ | ||
$value = self::getenv('SSL_TEST', 'no'); | ||
|
||
switch ($value) { | ||
case 'client': | ||
case 'no': | ||
case 'yes': | ||
return $value; | ||
} | ||
|
||
throw new EnvironmentException('SSL_TEST'); | ||
} | ||
|
||
public static function getTestRabbitMqConnectionUri(): string | ||
{ | ||
return trim(self::getenv('TEST_RABBITMQ_CONNECTION_URI')); | ||
} | ||
|
||
private static function getenv(string $envVariable, ?string $default = null):string | ||
{ | ||
$value = getenv($envVariable); | ||
|
||
if ($value === false && $default === null) { | ||
throw new EnvironmentException($envVariable); | ||
} | ||
|
||
return $value!==false?$value:$default; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Bunny\Test\Library; | ||
|
||
class EnvironmentException extends \RuntimeException | ||
{ | ||
public function __construct(string $envVariable) | ||
{ | ||
$value = getenv($envVariable); | ||
|
||
$valueFormatted = $value===false?'false': '"' . $value . '"'; | ||
|
||
parent::__construct(sprintf('Invalid value for env var %s: %s', $envVariable, $valueFormatted), 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters