Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir committed Jan 18, 2024
1 parent dbcab12 commit 5a8b2fa
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 51 deletions.
15 changes: 15 additions & 0 deletions .docker/php81.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM php:8.1-cli

RUN apt-get update && \
apt-get install -y libpq-dev && \
docker-php-ext-install pdo_mysql pdo_pgsql

RUN apt-get -y install gpg && \
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg && \
curl https://packages.microsoft.com/config/debian/12/prod.list | tee /etc/apt/sources.list.d/mssql-release.list && \
apt-get update && \
ACCEPT_EULA=Y apt-get -y install msodbcsql18 unixodbc-dev && \
pecl install sqlsrv pdo_sqlsrv && \
docker-php-ext-enable sqlsrv pdo_sqlsrv

COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
15 changes: 15 additions & 0 deletions .docker/php82.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM php:8.2-cli

RUN apt-get update && \
apt-get install -y libpq-dev && \
docker-php-ext-install pdo_mysql pdo_pgsql

RUN apt-get -y install gpg && \
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg && \
curl https://packages.microsoft.com/config/debian/12/prod.list | tee /etc/apt/sources.list.d/mssql-release.list && \
apt-get update && \
ACCEPT_EULA=Y apt-get -y install msodbcsql18 unixodbc-dev && \
pecl install sqlsrv pdo_sqlsrv && \
docker-php-ext-enable sqlsrv pdo_sqlsrv

COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
15 changes: 15 additions & 0 deletions .docker/php83.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM php:8.3-cli

RUN apt-get update && \
apt-get install -y libpq-dev && \
docker-php-ext-install pdo_mysql pdo_pgsql

RUN apt-get -y install gpg && \
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg && \
curl https://packages.microsoft.com/config/debian/12/prod.list | tee /etc/apt/sources.list.d/mssql-release.list && \
apt-get update && \
ACCEPT_EULA=Y apt-get -y install msodbcsql18 unixodbc-dev && \
pecl install sqlsrv pdo_sqlsrv && \
docker-php-ext-enable sqlsrv pdo_sqlsrv

COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
16 changes: 9 additions & 7 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/.github export-ignore
/tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.scrutinizer.yml export-ignore
phpstan.neon.dist export-ignore
phpunit.xml.dist export-ignore
/.docker export-ignore
/.github export-ignore
/tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.scrutinizer.yml export-ignore
docker-compose.yml export-ignore
phpstan.neon.dist export-ignore
phpunit.xml.dist export-ignore
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
PHPUNIT_FLAGS=$([ "${{ matrix.coverage }}" == "xdebug" ] && echo "--coverage-clover=coverage.xml" || echo "")
vendor/bin/phpunit $PHPUNIT_FLAGS
env:
DATABASE: ${{ matrix.database }}
DB_CONNECTION: ${{ matrix.database }}
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
MARIADB_PORT: ${{ job.services.mariadb.ports[3306] }}
PGSQL_PORT: ${{ job.services.pgsql.ports[5432] }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/vendor
.php-cs-fixer.cache
composer.lock
docker-compose.override.yml
77 changes: 77 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
version: '3.8'

services:
php81:
build:
context: .
dockerfile: .docker/php81.Dockerfile
working_dir: /var/www/html
networks:
- test
volumes:
- .:/var/www/html:delegated
php82:
build:
context: .
dockerfile: .docker/php82.Dockerfile
working_dir: /var/www/html
networks:
- test
volumes:
- .:/var/www/html:delegated
php83:
build:
context: .
dockerfile: .docker/php83.Dockerfile
working_dir: /var/www/html
networks:
- test
volumes:
- .:/var/www/html:delegated
mysql:
image: 'mysql:latest'
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: test
networks:
- test
mariadb:
image: 'mariadb:latest'
ports:
- '33060:3306'
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: test
networks:
- test
pgsql:
image: 'postgres:latest'
ports:
- '5432:5432'
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: test
networks:
- test
sqlsrv:
image: 'mcr.microsoft.com/mssql/server:2019-latest'
ports:
- '1433:1433'
environment:
ACCEPT_EULA: Y
SA_PASSWORD: Password!
healthcheck:
test: /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$${SA_PASSWORD}" -Q "SELECT 1" -b -o /dev/null
interval: 10s
timeout: 3s
retries: 10
start_period: 10s
networks:
- test

networks:
test:
driver: bridge
20 changes: 10 additions & 10 deletions tests/EloquentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testWithRecursiveExpression()

public function testWithRecursiveExpressionAndCycleDetection()
{
if (!in_array($this->database, ['mariadb', 'pgsql'])) {
if (!in_array($this->connection, ['mariadb', 'pgsql'])) {
$this->markTestSkipped();
}

Expand All @@ -54,11 +54,11 @@ public function testWithRecursiveExpressionAndCycleDetection()
->withRecursiveExpressionAndCycleDetection('ancestors', $query, 'id', 'is_cycle', 'path')
->get();

if ($this->database === 'mariadb') {
if ($this->connection === 'mariadb') {
$this->assertEquals([3, 2, 1], $users->pluck('id')->all());
}

if ($this->database === 'pgsql') {
if ($this->connection === 'pgsql') {
$this->assertEquals([3, 2, 1, 3], $users->pluck('id')->all());
$this->assertSame(false, $users[0]->is_cycle);
$this->assertEquals('{(3)}', $users[0]->path);
Expand Down Expand Up @@ -87,7 +87,7 @@ public function testInsertUsing()

public function testUpdate()
{
if ($this->database === 'mariadb') {
if ($this->connection === 'mariadb') {
$this->markTestSkipped();
}

Expand All @@ -102,7 +102,7 @@ public function testUpdate()

public function testUpdateWithJoin()
{
if ($this->database === 'mariadb') {
if ($this->connection === 'mariadb') {
$this->markTestSkipped();
}

Expand All @@ -119,7 +119,7 @@ public function testUpdateWithLimit()
{
// SingleStore support update with limit only when it is constrained to a single partition
// https://docs.singlestore.com/cloud/reference/sql-reference/data-manipulation-language-dml/update/#update-using-limit
if (in_array($this->database, ['mariadb', 'sqlsrv', 'singlestore'])) {
if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) {
$this->markTestSkipped();
}

Expand All @@ -136,7 +136,7 @@ public function testUpdateWithLimit()

public function testDelete()
{
if ($this->database === 'mariadb') {
if ($this->connection === 'mariadb') {
$this->markTestSkipped();
}

Expand All @@ -149,7 +149,7 @@ public function testDelete()

public function testDeleteWithJoin()
{
if ($this->database === 'mariadb') {
if ($this->connection === 'mariadb') {
$this->markTestSkipped();
}

Expand All @@ -163,11 +163,11 @@ public function testDeleteWithJoin()

public function testDeleteWithLimit()
{
if (in_array($this->database, ['mariadb', 'sqlsrv'])) {
if (in_array($this->connection, ['mariadb', 'sqlsrv'])) {
$this->markTestSkipped();
}

if ($this->database === 'singlestore') {
if ($this->connection === 'singlestore') {
$query = Post::withExpression('u', User::where('id', '<', 2));
} else {
$query = Post::withExpression('u', User::where('id', '>', 0))
Expand Down
28 changes: 14 additions & 14 deletions tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function testWithRecursiveExpression()
// SingleStore doesn't support previous variant of the RCTE
// It throws the following error:
// Unsupported recursive common table expression query shape: recursive CTE select cannot be materialized.
if ($this->database === 'singlestore') {
if ($this->connection === 'singlestore') {
$query = 'select 1 as number from `users` limit 1 union all select number + 1 from numbers where number < 3';
} else {
$query = 'select 1 union all select number + 1 from numbers where number < 3';
Expand Down Expand Up @@ -223,7 +223,7 @@ public function testWithRecursiveExpressionSingleStore()

public function testWithRecursiveExpressionAndCycleDetection()
{
if (!in_array($this->database, ['mariadb', 'pgsql'])) {
if (!in_array($this->connection, ['mariadb', 'pgsql'])) {
$this->markTestSkipped();
}

Expand All @@ -233,11 +233,11 @@ public function testWithRecursiveExpressionAndCycleDetection()
->withRecursiveExpressionAndCycleDetection('numbers', $query, 'modulo', 'is_cycle', 'path', ['number', 'modulo'])
->get();

if ($this->database === 'mariadb') {
if ($this->connection === 'mariadb') {
$this->assertEquals([1, 2, 3, 4, 5], $rows->pluck('number')->all());
}

if ($this->database === 'pgsql') {
if ($this->connection === 'pgsql') {
$this->assertEquals([1, 2, 3, 4, 5, 6], $rows->pluck('number')->all());
$this->assertSame(false, $rows[0]->is_cycle);
$this->assertEquals('{(1)}', $rows[0]->path);
Expand All @@ -246,7 +246,7 @@ public function testWithRecursiveExpressionAndCycleDetection()

public function testWithMaterializedExpression()
{
if (!in_array($this->database, ['pgsql', 'sqlite'])) {
if (!in_array($this->connection, ['pgsql', 'sqlite'])) {
$this->markTestSkipped();
}

Expand Down Expand Up @@ -282,7 +282,7 @@ public function testWithMaterializedExpressionSQLite()

public function testWithNonMaterializedExpression()
{
if (!in_array($this->database, ['pgsql', 'sqlite'])) {
if (!in_array($this->connection, ['pgsql', 'sqlite'])) {
$this->markTestSkipped();
}

Expand Down Expand Up @@ -383,7 +383,7 @@ public function testInsertUsingWithRecursionLimit()

public function testUpdate()
{
if ($this->database === 'mariadb') {
if ($this->connection === 'mariadb') {
$this->markTestSkipped();
}

Expand All @@ -399,7 +399,7 @@ public function testUpdate()

public function testUpdateWithJoin()
{
if ($this->database === 'mariadb') {
if ($this->connection === 'mariadb') {
$this->markTestSkipped();
}

Expand All @@ -417,7 +417,7 @@ public function testUpdateWithLimit()
{
// SingleStore support update with limit only when it is constrained to a single partition
// https://docs.singlestore.com/cloud/reference/sql-reference/data-manipulation-language-dml/update/#update-using-limit
if (in_array($this->database, ['mariadb', 'sqlsrv', 'singlestore'])) {
if (in_array($this->connection, ['mariadb', 'sqlsrv', 'singlestore'])) {
$this->markTestSkipped();
}

Expand All @@ -435,7 +435,7 @@ public function testUpdateWithLimit()

public function testUpdateFrom()
{
if ($this->database !== 'pgsql') {
if ($this->connection !== 'pgsql') {
$this->markTestSkipped();
}

Expand All @@ -451,7 +451,7 @@ public function testUpdateFrom()

public function testDelete()
{
if ($this->database === 'mariadb') {
if ($this->connection === 'mariadb') {
$this->markTestSkipped();
}

Expand All @@ -465,7 +465,7 @@ public function testDelete()

public function testDeleteWithJoin()
{
if ($this->database === 'mariadb') {
if ($this->connection === 'mariadb') {
$this->markTestSkipped();
}

Expand All @@ -480,11 +480,11 @@ public function testDeleteWithJoin()

public function testDeleteWithLimit()
{
if (in_array($this->database, ['mariadb', 'sqlsrv'])) {
if (in_array($this->connection, ['mariadb', 'sqlsrv'])) {
$this->markTestSkipped();
}

if ($this->database === 'singlestore') {
if ($this->connection === 'singlestore') {
$query = DB::table('posts')
->withExpression('u', DB::table('users')->where('id', '<', 2));
} else {
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

abstract class TestCase extends Base
{
protected string $database;
protected string $connection;

protected function setUp(): void
{
$this->database = getenv('DATABASE') ?: 'sqlite';
$this->connection = getenv('DB_CONNECTION') ?: 'sqlite';

parent::setUp();

Expand Down Expand Up @@ -54,7 +54,7 @@ protected function getEnvironmentSetUp($app)

$app['config']->set('database.default', 'testing');

$app['config']->set('database.connections.testing', $config[$this->database]);
$app['config']->set('database.connections.testing', $config[$this->connection]);
}

protected function getPackageProviders($app)
Expand Down
4 changes: 2 additions & 2 deletions tests/config/database.ci.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'password' => 'password',
'unix_socket' => '',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'collation' => 'utf8mb4_0900_ai_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
Expand All @@ -24,7 +24,7 @@
'password' => 'password',
'unix_socket' => '',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'collation' => 'utf8mb4_uca1400_ai_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
Expand Down
Loading

0 comments on commit 5a8b2fa

Please sign in to comment.