Skip to content

Commit

Permalink
Add workflows for other DBMS (#47)
Browse files Browse the repository at this point in the history
* Add mysql workflow

* Do not use template

* Install composer dependencies

* Separate sqlite / mysql

* Fix creation of db manager

* Apply fixes from StyleCI

* Fix testsuite arg

* Fix undefined driver

* Add pgsql

* Fix indentation

* Fix dsn for pg

* Add Mssql

* Fix testsuite arg for mssql

* Remove cache key

---------

Co-authored-by: StyleCI Bot <bot@styleci.io>
  • Loading branch information
arogachev and StyleCIBot committed Mar 16, 2023
1 parent f2ee663 commit 394074f
Show file tree
Hide file tree
Showing 26 changed files with 564 additions and 44 deletions.
98 changes: 98 additions & 0 deletions .github/workflows/mssql.yml
@@ -0,0 +1,98 @@
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

push:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

name: mssql

jobs:
tests:
name: PHP ${{ matrix.php }}-mssql-${{ matrix.mssql }}

env:
extensions: pdo, pdo_sqlsrv-5.10.1

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- 8.0
- 8.1

mssql:
- server:2017-latest
- server:2019-latest

exclude:
- php: 8.0
mssql: server:2017-latest
- php: 8.1
mssql: server:2017-latest

services:
mssql:
image: mcr.microsoft.com/mssql/${{ matrix.mssql }}
env:
SA_PASSWORD: YourStrong!Passw0rd
ACCEPT_EULA: Y
MSSQL_PID: Developer
ports:
- 1433:1433
options: --name=mssql --health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'SELECT 1'" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Create MS SQL Database
run: docker exec -i mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'CREATE DATABASE yiitest'

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
ini-values: date.timezone='UTC'
coverage: pcov
tools: composer:v2, pecl

- name: Determine composer cache directory
if: matrix.os == 'ubuntu-latest'
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v3
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-
- name: Update composer
run: composer self-update

- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run tests with phpunit
run: vendor/bin/phpunit --testsuite Mssql --colors=always
88 changes: 88 additions & 0 deletions .github/workflows/mysql.yml
@@ -0,0 +1,88 @@
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

push:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

name: mysql

jobs:
tests:
name: PHP ${{ matrix.php }}-mysql-${{ matrix.mysql }}

env:
extensions: pdo, pdo_mysql

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- 8.0
- 8.1

mysql:
- 5.7
- latest

services:
mysql:
image: mysql:${{ matrix.mysql }}
env:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_PASSWORD: ''
MYSQL_DATABASE: yiitest
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
ini-values: date.timezone='UTC'
coverage: pcov

- name: Determine composer cache directory
if: matrix.os == 'ubuntu-latest'
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v3
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-
- name: Update composer
run: composer self-update

- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run tests with phpunit
run: vendor/bin/phpunit --testsuite Mysql --colors=always
93 changes: 93 additions & 0 deletions .github/workflows/pgsql.yml
@@ -0,0 +1,93 @@
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

push:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

name: pgsql

jobs:
tests:
name: PHP ${{ matrix.php }}-pgsql-${{ matrix.pgsql }}

env:
extensions: pdo, pdo_pgsql

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- 8.0
- 8.1

pgsql:
- 9
- 10
- 11
- 12
- 13
- 14

services:
postgres:
image: postgres:${{ matrix.pgsql }}
env:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: yiitest
ports:
- 5432:5432
options: --name=postgres --health-cmd="pg_isready" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
ini-values: date.timezone='UTC'
coverage: pcov
tools: composer:v2

- name: Determine composer cache directory
if: matrix.os == 'ubuntu-latest'
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v3
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-
- name: Update composer
run: composer self-update

- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run tests with phpunit
run: vendor/bin/phpunit --testsuite Pgsql --colors=always
Expand Up @@ -19,7 +19,7 @@ on:
- 'infection.json.dist'
- 'psalm.xml'

name: build
name: sqlite

jobs:
phpunit:
Expand Down
14 changes: 12 additions & 2 deletions phpunit.xml.dist
Expand Up @@ -6,6 +6,7 @@
bootstrap="vendor/autoload.php"
failOnRisky="true"
failOnWarning="true"
defaultTestSuite="Sqlite"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
Expand All @@ -20,8 +21,17 @@
<ini name="error_reporting" value="-1"/>
</php>
<testsuites>
<testsuite name="Yii Rbac Cycle Db tests">
<directory>./tests</directory>
<testsuite name="Sqlite">
<directory>./tests/Sqlite</directory>
</testsuite>
<testsuite name="Mysql">
<directory>./tests/Mysql</directory>
</testsuite>
<testsuite name="Pgsql">
<directory>./tests/Pgsql</directory>
</testsuite>
<testsuite name="Mssql">
<directory>./tests/Mssql</directory>
</testsuite>
</testsuites>
</phpunit>
Expand Up @@ -2,13 +2,13 @@

declare(strict_types=1);

namespace Yiisoft\Rbac\Cycle\Tests;
namespace Yiisoft\Rbac\Cycle\Tests\Base;

use Yiisoft\Rbac\Assignment;
use Yiisoft\Rbac\Cycle\AssignmentsStorage;
use Yiisoft\Rbac\Item;

class AssignmentsStorageTest extends TestCase
abstract class AssignmentsStorageTest extends TestCase
{
public function testHasItem(): void
{
Expand Down
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Yiisoft\Rbac\Cycle\Tests\Command;
namespace Yiisoft\Rbac\Cycle\Tests\Base\Command;

use Cycle\Database\ForeignKeyInterface;
use Cycle\Database\Schema\AbstractForeignKey;
Expand All @@ -12,10 +12,10 @@
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\NullOutput;
use Yiisoft\Rbac\Cycle\Command\RbacCycleInit;
use Yiisoft\Rbac\Cycle\Tests\TestCase;
use Yiisoft\Rbac\Cycle\Tests\Base\TestCase;
use Yiisoft\Rbac\Item;

class RbacCycleInitTest extends TestCase
abstract class RbacCycleInitTest extends TestCase
{
protected function setUp(): void
{
Expand Down
Expand Up @@ -2,14 +2,14 @@

declare(strict_types=1);

namespace Yiisoft\Rbac\Cycle\Tests;
namespace Yiisoft\Rbac\Cycle\Tests\Base;

use Yiisoft\Rbac\Cycle\ItemsStorage;
use Yiisoft\Rbac\Item;
use Yiisoft\Rbac\Permission;
use Yiisoft\Rbac\Role;

class ItemsStorageTest extends TestCase
abstract class ItemsStorageTest extends TestCase
{
public function testUpdate(): void
{
Expand Down

0 comments on commit 394074f

Please sign in to comment.