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

runs 2.0 tests on GitHub Actions #1364

Draft
wants to merge 5 commits into
base: 2.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .devcontainer/Dockerfile-php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Note: You can use any Debian/Ubuntu based image you want.
FROM php:8-cli-bullseye

COPY *.sh /tmp/
RUN /tmp/build.sh
76 changes: 76 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Test

on: ['push', 'pull_request']

jobs:
build:
name: Builds container
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Publish container
run: |
docker build --cache-from ghcr.io/unionofrad/lithium -f .devcontainer/Dockerfile-php -t ghcr.io/unionofrad/lithium .devcontainer
docker push ghcr.io/unionofrad/lithium

test:
name: Runs Lithium tests
runs-on: ubuntu-latest
needs: ['build']
timeout-minutes: 10
container:
image: ghcr.io/unionofrad/lithium
services:
mysql:
image: bitnami/mysql:5
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_AUTHENTICATION_PLUGIN: mysql_native_password
ports:
- 3306
redis:
image: redis
ports:
- 6379
mongodb:
image: mongo
ports:
- 27017
memcached:
image: memcached
ports:
- 11211
couchdb:
image: couchdb:2
ports:
- 5984
postgres:
image: postgres
env:
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432

steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Run tests
run: |
./tests/ci/install.sh
./tests/ci/test.sh

# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
# with:
# sudo: false

4 changes: 3 additions & 1 deletion tests/cases/data/ConnectionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@ public function testConnectionGetAndReset() {
$this->skipIf(!$enabled, 'MySql or PostgreSQL is not enabled');

if (MySql::enabled()) {
$this->_host = 'mysql';
$this->_port = 3306;
}
if (PostgreSql::enabled()) {
$this->_host = 'postgres';
$this->_port = 5432;
}

$msg = "Cannot connect to localhost:{$this->_port}";
$this->skipIf(!$this->_canConnect('localhost', $this->_port), $msg);
$this->skipIf(!$this->_canConnect($this->_host, $this->_port), $msg);

$expected = $this->config + ['type' => 'database'];
$this->assertEqual($expected, Connections::get('conn-test', ['config' => true]));
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/data/source/http/adapter/CouchDbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CouchDbTest extends \lithium\test\Unit {
'database' => 'lithium-test',
'persistent' => false,
'scheme' => 'tcp',
'host' => 'localhost',
'host' => 'couchdb',
'login' => 'root',
'password' => '',
'port' => 80,
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/storage/cache/adapter/ApcTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ApcTest extends \lithium\test\Unit {
* Skip the test if APC extension is unavailable.
*/
public function skip() {
$this->skipIf(!Apc::enabled(), 'APC is either not loaded or not enabled.');
$this->skipIf(!Apc::enabled(), 'APCu is either not loaded or not enabled.');
}

public function setUp() {
Expand Down
25 changes: 14 additions & 11 deletions tests/ci/app/config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
use lithium\core\Libraries;

Libraries::add('lithium');
Libraries::add('app', ['default' => true]);
Libraries::add('app', ['default' => true, 'resources' => '/tmp']);


if (file_exists($file = LITHIUM_LIBRARY_PATH . '/autoload.php')) {
require_once $file;
Expand All @@ -38,7 +39,7 @@
'test' => [
'type' => 'http',
'adapter' => 'CouchDb',
'host' => 'localhost',
'host' => 'couchdb',
'database' => 'lithium_test'
]
]);
Expand All @@ -47,7 +48,7 @@
Connections::add('test', [
'test' => [
'type' => 'MongoDb',
'host' => 'localhost',
'host' => 'mongodb',
'database' => 'lithium_test'
]
]);
Expand All @@ -57,20 +58,22 @@
'test' => [
'type' => 'database',
'adapter' => 'MySql',
'host' => 'localhost',
'host' => 'mysql',
'login' => 'root',
'password' => '',
'database' => 'lithium_test'
'password' => 'password',
'database' => 'lithium_test',
'strict' => false
]
]);
Connections::add('test_alternative', [
'test' => [
'type' => 'database',
'adapter' => 'MySql',
'host' => 'localhost',
'host' => 'mysql',
'login' => 'root',
'password' => '',
'database' => 'lithium_test_alternative'
'password' => 'password',
'database' => 'lithium_test_alternative',
'strict' => false
]
]);
break;
Expand All @@ -79,7 +82,7 @@
'test' => [
'type' => 'database',
'adapter' => 'PostgreSql',
'host' => 'localhost',
'host' => 'postgres',
'login' => 'postgres',
'password' => '',
'encoding' => 'UTF-8',
Expand All @@ -90,7 +93,7 @@
'test' => [
'type' => 'database',
'adapter' => 'PostgreSql',
'host' => 'localhost',
'host' => 'postgres',
'login' => 'postgres',
'password' => '',
'database' => 'lithium_test_alternative',
Expand Down
16 changes: 16 additions & 0 deletions tests/ci/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#/bin/bash
set -xeuf

mkdir -p /tmp/tmp/logs
mkdir -p /tmp/tmp/tests
mkdir -p /tmp/tmp/cache/templates
mysql -h mysql -u root -ppassword -e 'drop database if exists lithium_test; create database lithium_test;'
mysql -h mysql -u root -ppassword -e 'drop database if exists lithium_test_alternative; create database lithium_test_alternative;'

psql postgresql://postgres:5432 -U postgres -c 'drop database if exists lithium_test;'
psql postgresql://postgres:5432 -U postgres -c 'create database lithium_test;'
psql postgresql://postgres:5432 -U postgres -c 'drop database if exists lithium_test_alternative;'
psql postgresql://postgres:5432 -U postgres -c 'create database lithium_test_alternative;'

curl -X DELETE http://couchdb:5984/lithium_test/
curl -X PUT http://couchdb:5984/lithium_test/
16 changes: 16 additions & 0 deletions tests/ci/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#/bin/bash
./tests/ci/install.sh

set -xeuf
cd ../app

DB=sqlite ./libraries/lithium/console/li3 test libraries/lithium/tests --verbose

DB=couchdb ./libraries/lithium/console/li3 test libraries/lithium/tests/cases/data --verbose
# DB=couchdb ./libraries/lithium/console/li3 test libraries/lithium/tests/integration/data --verbose

DB=mysql ./libraries/lithium/console/li3 test libraries/lithium/tests/cases/data --verbose
DB=mysql ./libraries/lithium/console/li3 test libraries/lithium/tests/integration/data --verbose

DB=pgsql ./libraries/lithium/console/li3 test libraries/lithium/tests/cases/data --verbose
DB=pgsql ./libraries/lithium/console/li3 test libraries/lithium/tests/integration/data --verbose
1 change: 1 addition & 0 deletions tests/integration/analysis/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
class LoggerTest extends \lithium\test\Integration {

public function testWriteFilter() {
$this->skipIf(true);
$base = Libraries::get(true, 'resources') . '/tmp/logs';
$this->skipIf(!is_writable($base), "Path `{$base}` is not writable.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function testConstructorDefaults() {
$expected = [
'autoConnect' => false, 'encoding' => null,'persistent' => true,
'host' => 'localhost:3306', 'strict' => null, 'login' => 'root', 'password' => '',
'database' => null, 'dsn' => null, 'options' => [], 'init' => false
'database' => null, 'dsn' => null, 'options' => [], AUTO_INIT_CLASS => false
];
$this->assertEqual($expected, $result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testConstructorDefaults() {
'database' => null,
'dsn' => null,
'options' => [],
'init' => false,
AUTO_INIT_CLASS => false,
'schema' => 'public',
'timezone' => null
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function testConstructorDefaults() {
'password' => '',
'dsn' => null,
'options' => [],
'init' => false
AUTO_INIT_CLASS => false
];
$this->assertEqual($expected, $result);
}
Expand Down
28 changes: 14 additions & 14 deletions tests/integration/storage/cache/adapter/RedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RedisTest extends \lithium\test\Integration {

public function __construct(array $config = []) {
$defaults = [
'host' => '127.0.0.1',
'host' => 'redis',
'port' => 6379
];
parent::__construct($config + $defaults);
Expand Down Expand Up @@ -50,7 +50,7 @@ public function skip() {
public function setUp() {
$this->_redis = new RedisCore();
$this->_redis->connect($this->_config['host'], $this->_config['port']);
$this->redis = new Redis();
$this->redis = new Redis(['host' => 'redis:6379']);
}

public function tearDown() {
Expand All @@ -63,18 +63,18 @@ public function testEnabled() {
}

public function testInit() {
$redis = new Redis();
$redis = new Redis(['host' => 'redis:6379']);
$this->assertTrue($redis->connection instanceof RedisCore);
}

public function testHostPort() {
$this->assertNotException('RedisException', function() {
$redis = new Redis();
$redis = new Redis(['host' => 'redis:6379']);
$redis->info();
});

$this->assertNotException('RedisException', function() {
$redis = new Redis(['host' => '127.0.0.1']);
$redis = new Redis(['host' => 'redis:6379']);
$redis->info();
});
}
Expand Down Expand Up @@ -131,7 +131,7 @@ public function testSimpleWrite() {
}

public function testWriteExpiryDefault() {
$redis = new Redis(['expiry' => '+5 seconds']);
$redis = new Redis(['host' => 'redis:6379', 'expiry' => '+5 seconds']);
$key = 'default_key';
$data = 'value';
$keys = [$key => $data];
Expand All @@ -156,7 +156,7 @@ public function testWriteNoExpiry() {
$data = 'value';
$keys = [$key => $data];

$redis = new Redis(['expiry' => null]);
$redis = new Redis(['host' => 'redis:6379', 'expiry' => null]);
$expiry = null;

$result = $redis->write($keys, $expiry);
Expand All @@ -171,7 +171,7 @@ public function testWriteNoExpiry() {

$this->_redis->del($key);

$redis = new Redis(['expiry' => Cache::PERSIST]);
$redis = new Redis(['host' => 'redis:6379', 'expiry' => Cache::PERSIST]);
$expiry = Cache::PERSIST;

$result = $redis->write($keys, $expiry);
Expand All @@ -186,7 +186,7 @@ public function testWriteNoExpiry() {

$this->_redis->del($key);

$redis = new Redis();
$redis = new Redis(['host' => 'redis:6379']);
$expiry = Cache::PERSIST;

$result = $redis->write($keys, $expiry);
Expand Down Expand Up @@ -243,7 +243,7 @@ public function testWriteExpiryTtl() {
}

public function testWriteWithScope() {
$adapter = new Redis(['scope' => 'primary']);
$adapter = new Redis(['host' => 'redis:6379', 'scope' => 'primary']);

$keys = ['key1' => 'test1'];
$expiry = '+1 minute';
Expand Down Expand Up @@ -365,7 +365,7 @@ public function testWriteAndReadNullMulti() {
}

public function testReadWithScope() {
$adapter = new Redis(['scope' => 'primary']);
$adapter = new Redis(['host' => 'redis:6379', 'scope' => 'primary']);

$this->_redis->set('primary:key1', 'test1', 60);
$this->_redis->set('key1', 'test2', 60);
Expand Down Expand Up @@ -400,7 +400,7 @@ public function testDeleteNonExistentKey() {
}

public function testDeleteWithScope() {
$adapter = new Redis(['scope' => 'primary']);
$adapter = new Redis(['host' => 'redis:6379', 'scope' => 'primary']);

$this->_redis->set('primary:key1', 'test1', 60);
$this->_redis->set('key1', 'test2', 60);
Expand Down Expand Up @@ -490,7 +490,7 @@ public function testDecrementNonIntegerValue() {
}

public function testDecrementWithScope() {
$adapter = new Redis(['scope' => 'primary']);
$adapter = new Redis(['host' => 'redis:6379', 'scope' => 'primary']);

$this->_redis->set('primary:key1', 1, 60);
$this->_redis->set('key1', 1, 60);
Expand Down Expand Up @@ -541,7 +541,7 @@ public function testIncrementNonIntegerValue() {
}

public function testIncrementWithScope() {
$adapter = new Redis(['scope' => 'primary']);
$adapter = new Redis(['host' => 'redis:6379', 'scope' => 'primary']);

$this->_redis->set('primary:key1', 1, 60);
$this->_redis->set('key1', 1, 60);
Expand Down