Execute docker dependent tests with github actions

This commit is contained in:
Jakub Zalas 2020-05-01 13:33:43 +01:00
parent f8d3b0626a
commit d710c1b654
No known key found for this signature in database
GPG Key ID: 15614199651BDE8D
39 changed files with 239 additions and 56 deletions

101
.github/workflows/tests.yml vendored Normal file
View File

@ -0,0 +1,101 @@
name: Tests
on:
push:
pull_request:
jobs:
integration:
name: Integration
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.1', '7.4']
services:
redis:
image: redis:6.0.0
ports:
- 6379:6379
redis-cluster:
image: grokzen/redis-cluster:5.0.4
ports:
- 7000:7000
- 7001:7001
- 7002:7002
- 7003:7003
- 7004:7004
- 7005:7005
- 7006:7006
- 7007:7007
env:
STANDALONE: true
memcached:
image: memcached:1.6.5
ports:
- 11211:11211
rabbitmq:
image: rabbitmq:3.8.3
ports:
- 5672:5672
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
coverage: "none"
extensions: "memcached,redis,xsl"
ini-values: "memory_limit=-1"
php-version: "${{ matrix.php }}"
tools: flex
- name: Configure composer
run: |
([ -d ~/.composer ] || mkdir ~/.composer) && cp .github/composer-config.json ~/.composer/config.json
SYMFONY_VERSION=$(cat composer.json | grep '^ *\"dev-master\". *\"[1-9]' | grep -o '[0-9.]*')
echo "::set-env name=SYMFONY_VERSION::$SYMFONY_VERSION"
echo "::set-env name=COMPOSER_ROOT_VERSION::$SYMFONY_VERSION.x-dev"
- name: Determine composer cache directory
id: composer-cache
run: echo "::set-output name=directory::$(composer config cache-dir)"
- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.directory }}
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ matrix.php }}-composer-
- name: Install dependencies
run: |
echo "::group::composer update"
composer update --no-progress --no-suggest --ansi
echo "::endgroup::"
echo "::group::install phpunit"
./phpunit install
echo "::endgroup::"
- name: Run tests
run: ./phpunit --verbose --group integration
env:
SYMFONY_DEPRECATIONS_HELPER: 'max[indirect]=7'
REDIS_HOST: localhost
REDIS_CLUSTER_HOSTS: 'localhost:7000 localhost:7001 localhost:7002 localhost:7003 localhost:7004 localhost:7005'
MESSENGER_REDIS_DSN: redis://127.0.0.1:7006/messages
MESSENGER_AMQP_DSN: amqp://localhost/%2f/messages
MEMCACHED_HOST: localhost
- name: Run HTTP push tests
if: matrix.php == '7.4'
run: |
[ -d .phpunit ] && mv .phpunit .phpunit.bak
wget -q https://github.com/symfony/binary-utils/releases/download/v0.1/vulcain_0.1.3_Linux_x86_64.tar.gz -O - | tar xz && mv vulcain /usr/local/bin
docker run --rm -e COMPOSER_ROOT_VERSION -e SYMFONY_VERSION -v $(pwd):/app -v $(which composer):/usr/local/bin/composer -v /usr/local/bin/vulcain:/usr/local/bin/vulcain -w /app php:7.4-alpine ./phpunit --verbose src/Symfony/Component/HttpClient/Tests/CurlHttpClientTest.php --filter testHttp2Push
sudo rm -rf .phpunit
[ -d .phpunit.bak ] && mv .phpunit.bak .phpunit

View File

@ -13,14 +13,11 @@ addons:
- slapd
- zookeeperd
- libzookeeper-mt-dev
- rabbitmq-server
env:
global:
- MIN_PHP=7.1.3
- SYMFONY_PROCESS_PHP_TEST_BINARY=~/.phpenv/shims/php
- MESSENGER_AMQP_DSN=amqp://localhost/%2f/messages
- MESSENGER_REDIS_DSN=redis://127.0.0.1:7006/messages
- SYMFONY_PHPUNIT_DISABLE_RESULT_CACHE=1
matrix:
@ -39,13 +36,6 @@ cache:
- php-$MIN_PHP
- ~/php-ext
services:
- memcached
- mongodb
- redis-server
- rabbitmq
- docker
before_install:
- |
# Enable Sury ppa
@ -56,12 +46,6 @@ before_install:
sudo apt update
sudo apt install -y librabbitmq-dev libsodium-dev
- |
# Start Redis cluster
docker pull grokzen/redis-cluster:5.0.4
docker run -d -p 7000:7000 -p 7001:7001 -p 7002:7002 -p 7003:7003 -p 7004:7004 -p 7005:7005 -p 7006:7006 -p 7007:7007 -e "STANDALONE=true" --name redis-cluster grokzen/redis-cluster:5.0.4
export REDIS_CLUSTER_HOSTS='localhost:7000 localhost:7001 localhost:7002 localhost:7003 localhost:7004 localhost:7005'
- |
# General configuration
set -e
@ -141,12 +125,6 @@ before_install:
(cd php-$MIN_PHP && ./configure --enable-sigchild --enable-pcntl && make -j2)
fi
- |
# Install vulcain
wget https://github.com/symfony/binary-utils/releases/download/v0.1/vulcain_0.1.3_Linux_x86_64.tar.gz -O - | tar xz
sudo mv vulcain /usr/local/bin
docker pull php:7.3-alpine
- |
# php.ini configuration
for PHP in $TRAVIS_PHP_VERSION $php_extra; do
@ -268,15 +246,6 @@ install:
set -e
export PHP=$1
if [[ !$deps && $PHP = 7.2 ]]; then
phpenv global $PHP
tfold 'composer update' $COMPOSER_UP
[ -d .phpunit ] && mv .phpunit .phpunit.bak
tfold src/Symfony/Component/HttpClient.h2push "docker run -it --rm -v $(pwd):/app -v $(phpenv which composer):/usr/local/bin/composer -v /usr/local/bin/vulcain:/usr/local/bin/vulcain -w /app php:7.3-alpine ./phpunit src/Symfony/Component/HttpClient/Tests/CurlHttpClientTest.php --filter testHttp2Push"
sudo rm .phpunit -rf
[ -d .phpunit.bak ] && mv .phpunit.bak .phpunit
fi
if [[ $PHP != 7.4* && $PHP != $TRAVIS_PHP_VERSION && $TRAVIS_PULL_REQUEST != false ]]; then
echo -e "\\n\\e[33;1mIntermediate PHP version $PHP is skipped for pull requests.\\e[0m"
return

View File

@ -26,9 +26,12 @@ class CachePoolsTest extends AbstractWebTestCase
/**
* @requires extension redis
* @group integration
*/
public function testRedisCachePools()
{
$this->skipIfRedisUnavailable();
try {
$this->doTestCachePools(['root_config' => 'redis_config.yml', 'environment' => 'redis_cache'], RedisAdapter::class);
} catch (\PHPUnit\Framework\Error\Warning $e) {
@ -51,9 +54,12 @@ class CachePoolsTest extends AbstractWebTestCase
/**
* @requires extension redis
* @group integration
*/
public function testRedisCustomCachePools()
{
$this->skipIfRedisUnavailable();
try {
$this->doTestCachePools(['root_config' => 'redis_custom_config.yml', 'environment' => 'custom_redis_cache'], RedisAdapter::class);
} catch (\PHPUnit\Framework\Error\Warning $e) {
@ -121,4 +127,13 @@ class CachePoolsTest extends AbstractWebTestCase
{
return parent::createKernel(['test_case' => 'CachePools'] + $options);
}
private function skipIfRedisUnavailable()
{
try {
(new \Redis())->connect(getenv('REDIS_HOST'));
} catch (\Exception $e) {
self::markTestSkipped($e->getMessage());
}
}
}

View File

@ -34,9 +34,10 @@ abstract class AbstractRedisAdapterTest extends AdapterTestCase
if (!\extension_loaded('redis')) {
self::markTestSkipped('Extension redis required.');
}
if (!@((new \Redis())->connect(getenv('REDIS_HOST')))) {
$e = error_get_last();
self::markTestSkipped($e['message']);
try {
(new \Redis())->connect(getenv('REDIS_HOST'));
} catch (\Exception $e) {
self::markTestSkipped($e->getMessage());
}
}

View File

@ -15,6 +15,9 @@ use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\AbstractAdapter;
use Symfony\Component\Cache\Adapter\MemcachedAdapter;
/**
* @group integration
*/
class MemcachedAdapterTest extends AdapterTestCase
{
protected $skippedTests = [

View File

@ -14,6 +14,9 @@ namespace Symfony\Component\Cache\Tests\Adapter;
use Predis\Connection\StreamConnection;
use Symfony\Component\Cache\Adapter\RedisAdapter;
/**
* @group integration
*/
class PredisAdapterTest extends AbstractRedisAdapterTest
{
public static function setUpBeforeClass(): void

View File

@ -11,6 +11,9 @@
namespace Symfony\Component\Cache\Tests\Adapter;
/**
* @group integration
*/
class PredisClusterAdapterTest extends AbstractRedisAdapterTest
{
public static function setUpBeforeClass(): void

View File

@ -13,6 +13,9 @@ namespace Symfony\Component\Cache\Tests\Adapter;
use Symfony\Component\Cache\Adapter\RedisAdapter;
/**
* @group integration
*/
class PredisRedisClusterAdapterTest extends AbstractRedisAdapterTest
{
public static function setUpBeforeClass(): void

View File

@ -15,6 +15,9 @@ use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
/**
* @group integration
*/
class PredisTagAwareAdapterTest extends PredisAdapterTest
{
use TagAwareTestTrait;

View File

@ -15,6 +15,9 @@ use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
/**
* @group integration
*/
class PredisTagAwareClusterAdapterTest extends PredisClusterAdapterTest
{
use TagAwareTestTrait;

View File

@ -14,6 +14,9 @@ namespace Symfony\Component\Cache\Tests\Adapter;
use Symfony\Component\Cache\Adapter\AbstractAdapter;
use Symfony\Component\Cache\Adapter\RedisAdapter;
/**
* @group integration
*/
class RedisAdapterSentinelTest extends AbstractRedisAdapterTest
{
public static function setUpBeforeClass(): void

View File

@ -16,6 +16,9 @@ use Symfony\Component\Cache\Adapter\AbstractAdapter;
use Symfony\Component\Cache\Adapter\RedisAdapter;
use Symfony\Component\Cache\Traits\RedisProxy;
/**
* @group integration
*/
class RedisAdapterTest extends AbstractRedisAdapterTest
{
public static function setUpBeforeClass(): void

View File

@ -11,6 +11,9 @@
namespace Symfony\Component\Cache\Tests\Adapter;
/**
* @group integration
*/
class RedisArrayAdapterTest extends AbstractRedisAdapterTest
{
public static function setUpBeforeClass(): void

View File

@ -16,6 +16,9 @@ use Symfony\Component\Cache\Adapter\AbstractAdapter;
use Symfony\Component\Cache\Adapter\RedisAdapter;
use Symfony\Component\Cache\Traits\RedisClusterProxy;
/**
* @group integration
*/
class RedisClusterAdapterTest extends AbstractRedisAdapterTest
{
public static function setUpBeforeClass(): void

View File

@ -16,6 +16,9 @@ use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
use Symfony\Component\Cache\Traits\RedisProxy;
/**
* @group integration
*/
class RedisTagAwareAdapterTest extends RedisAdapterTest
{
use TagAwareTestTrait;

View File

@ -15,6 +15,9 @@ use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
/**
* @group integration
*/
class RedisTagAwareArrayAdapterTest extends RedisArrayAdapterTest
{
use TagAwareTestTrait;

View File

@ -16,6 +16,9 @@ use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
use Symfony\Component\Cache\Traits\RedisClusterProxy;
/**
* @group integration
*/
class RedisTagAwareClusterAdapterTest extends RedisClusterAdapterTest
{
use TagAwareTestTrait;

View File

@ -37,9 +37,10 @@ abstract class AbstractRedisCacheTest extends CacheTestCase
if (!\extension_loaded('redis')) {
self::markTestSkipped('Extension redis required.');
}
if (!@((new \Redis())->connect(getenv('REDIS_HOST')))) {
$e = error_get_last();
self::markTestSkipped($e['message']);
try {
(new \Redis())->connect(getenv('REDIS_HOST'));
} catch (\Exception $e) {
self::markTestSkipped($e->getMessage());
}
}

View File

@ -17,6 +17,7 @@ use Symfony\Component\Cache\Simple\MemcachedCache;
/**
* @group legacy
* @group integration
*/
class MemcachedCacheTest extends CacheTestCase
{

View File

@ -17,6 +17,7 @@ use Symfony\Component\Cache\Simple\MemcachedCache;
/**
* @group legacy
* @group integration
*/
class MemcachedCacheTextModeTest extends MemcachedCacheTest
{

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Cache\Tests\Simple;
/**
* @group legacy
* @group integration
*/
class RedisArrayCacheTest extends AbstractRedisCacheTest
{

View File

@ -15,6 +15,7 @@ use Symfony\Component\Cache\Simple\RedisCache;
/**
* @group legacy
* @group integration
*/
class RedisCacheTest extends AbstractRedisCacheTest
{

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Cache\Tests\Simple;
/**
* @group legacy
* @group integration
*/
class RedisClusterCacheTest extends AbstractRedisCacheTest
{

View File

@ -44,6 +44,11 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
if (!\extension_loaded('redis')) {
self::markTestSkipped('Extension redis required.');
}
try {
(new \Redis())->connect(getenv('REDIS_HOST'));
} catch (\Exception $e) {
self::markTestSkipped($e->getMessage());
}
$host = getenv('REDIS_HOST') ?: 'localhost';

View File

@ -13,6 +13,9 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
use Predis\Client;
/**
* @group integration
*/
class PredisClusterSessionHandlerTest extends AbstractRedisSessionHandlerTestCase
{
protected function createRedisClient(string $host): Client

View File

@ -13,6 +13,9 @@ namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
use Predis\Client;
/**
* @group integration
*/
class PredisSessionHandlerTest extends AbstractRedisSessionHandlerTestCase
{
protected function createRedisClient(string $host): Client

View File

@ -11,6 +11,9 @@
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
/**
* @group integration
*/
class RedisArraySessionHandlerTest extends AbstractRedisSessionHandlerTestCase
{
/**

View File

@ -11,6 +11,9 @@
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
/**
* @group integration
*/
class RedisClusterSessionHandlerTest extends AbstractRedisSessionHandlerTestCase
{
public static function setUpBeforeClass(): void

View File

@ -11,6 +11,9 @@
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
/**
* @group integration
*/
class RedisSessionHandlerTest extends AbstractRedisSessionHandlerTestCase
{
/**

View File

@ -19,6 +19,7 @@ use Symfony\Component\Lock\Store\MemcachedStore;
* @author Jérémy Derussé <jeremy@derusse.com>
*
* @requires extension memcached
* @group integration
*/
class MemcachedStoreTest extends AbstractStoreTest
{

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Lock\Tests\Store;
/**
* @author Jérémy Derussé <jeremy@derusse.com>
* @group integration
*/
class PredisStoreTest extends AbstractRedisStoreTest
{

View File

@ -15,6 +15,7 @@ namespace Symfony\Component\Lock\Tests\Store;
* @author Jérémy Derussé <jeremy@derusse.com>
*
* @requires extension redis
* @group integration
*/
class RedisArrayStoreTest extends AbstractRedisStoreTest
{
@ -23,9 +24,10 @@ class RedisArrayStoreTest extends AbstractRedisStoreTest
if (!class_exists('RedisArray')) {
self::markTestSkipped('The RedisArray class is required.');
}
if (!@((new \Redis())->connect(getenv('REDIS_HOST')))) {
$e = error_get_last();
self::markTestSkipped($e['message']);
try {
(new \Redis())->connect(getenv('REDIS_HOST'));
} catch (\Exception $e) {
self::markTestSkipped($e->getMessage());
}
}

View File

@ -15,6 +15,7 @@ namespace Symfony\Component\Lock\Tests\Store;
* @author Jérémy Derussé <jeremy@derusse.com>
*
* @requires extension redis
* @group integration
*/
class RedisClusterStoreTest extends AbstractRedisStoreTest
{

View File

@ -17,14 +17,16 @@ use Symfony\Component\Lock\Store\RedisStore;
* @author Jérémy Derussé <jeremy@derusse.com>
*
* @requires extension redis
* @group integration
*/
class RedisStoreTest extends AbstractRedisStoreTest
{
public static function setUpBeforeClass(): void
{
if (!@((new \Redis())->connect(getenv('REDIS_HOST')))) {
$e = error_get_last();
self::markTestSkipped($e['message']);
try {
(new \Redis())->connect(getenv('REDIS_HOST'));
} catch (\Exception $e) {
self::markTestSkipped($e->getMessage());
}
}

View File

@ -33,6 +33,7 @@ use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
/**
* @requires extension amqp
* @group integration
*/
class AmqpExtIntegrationTest extends TestCase
{

View File

@ -17,14 +17,14 @@ use Symfony\Component\Messenger\Transport\RedisExt\Connection;
/**
* @requires extension redis >= 4.3.0
* @group integration
*/
class ConnectionTest extends TestCase
{
public static function setUpBeforeClass(): void
{
$redis = Connection::fromDsn('redis://localhost/queue');
try {
$redis = Connection::fromDsn('redis://localhost/queue');
$redis->get();
} catch (TransportException $e) {
if (0 === strpos($e->getMessage(), 'ERR unknown command \'X')) {
@ -32,6 +32,8 @@ class ConnectionTest extends TestCase
}
throw $e;
} catch (\RedisException $e) {
self::markTestSkipped($e->getMessage());
}
}

View File

@ -18,6 +18,7 @@ use Symfony\Component\Messenger\Transport\RedisExt\Connection;
/**
* @requires extension redis
* @group time-sensitive
* @group integration
*/
class RedisExtIntegrationTest extends TestCase
{
@ -30,10 +31,14 @@ class RedisExtIntegrationTest extends TestCase
$this->markTestSkipped('The "MESSENGER_REDIS_DSN" environment variable is required.');
}
$this->redis = new \Redis();
$this->connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'), [], $this->redis);
$this->connection->cleanup();
$this->connection->setup();
try {
$this->redis = new \Redis();
$this->connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'), [], $this->redis);
$this->connection->cleanup();
$this->connection->setup();
} catch (\Exception $e) {
self::markTestSkipped($e->getMessage());
}
}
public function testConnectionSendAndGet()

View File

@ -31,12 +31,26 @@ class RedisTransportFactoryTest extends TestCase
$this->assertFalse($factory->supports('invalid-dsn', []));
}
/**
* @group integration
*/
public function testCreateTransport()
{
$this->skipIfRedisUnavailable();
$factory = new RedisTransportFactory();
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock();
$expectedTransport = new RedisTransport(Connection::fromDsn('redis://localhost', ['foo' => 'bar']), $serializer);
$expectedTransport = new RedisTransport(Connection::fromDsn('redis://'.getenv('REDIS_HOST'), ['foo' => 'bar']), $serializer);
$this->assertEquals($expectedTransport, $factory->createTransport('redis://localhost', ['foo' => 'bar'], $serializer));
$this->assertEquals($expectedTransport, $factory->createTransport('redis://'.getenv('REDIS_HOST'), ['foo' => 'bar'], $serializer));
}
private function skipIfRedisUnavailable()
{
try {
(new \Redis())->connect(getenv('REDIS_HOST'));
} catch (\Exception $e) {
self::markTestSkipped($e->getMessage());
}
}
}

View File

@ -17,6 +17,7 @@ use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
/**
* @author Nicolas Grekas <p@tchwork.com>
* @requires extension redis
* @group integration
*/
class RedisCasterTest extends TestCase
{
@ -37,16 +38,18 @@ EODUMP;
public function testConnected()
{
$redisHost = getenv('REDIS_HOST');
$redis = new \Redis();
if (!@$redis->connect('127.0.0.1')) {
$e = error_get_last();
self::markTestSkipped($e['message']);
try {
$redis->connect($redisHost);
} catch (\Exception $e) {
self::markTestSkipped($e->getMessage());
}
$xCast = <<<'EODUMP'
$xCast = <<<EODUMP
Redis {%A
isConnected: true
host: "127.0.0.1"
host: "$redisHost"
port: 6379
auth: null
mode: ATOMIC