Skip to content

Commit

Permalink
Trigger based sniffers
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloelcolombiano committed Nov 23, 2020
1 parent 985b5de commit 3268a45
Show file tree
Hide file tree
Showing 41 changed files with 1,874 additions and 484 deletions.
5 changes: 5 additions & 0 deletions .env.Mysql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DB_DRIVER=Mysql
DB_USER=root
DB_PWD=root
DB_HOST=localhost
DB_DATABASE=test_suite_light
5 changes: 5 additions & 0 deletions .env.Postgres
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DB_DRIVER=Postgres
DB_USER=root
DB_PWD=root
DB_HOST=localhost
DB_DATABASE=test_suite_light
5 changes: 5 additions & 0 deletions .env.Sqlite
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DB_DRIVER=Sqlite
DB_USER=root
DB_PWD=root
DB_HOST=localhost
DB_DATABASE=test_suite_light
140 changes: 70 additions & 70 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
name: GitHub CI

on:
push:
branches:
- '*'
pull_request:
branches:
- '*'
schedule:
- cron: '0 0 * * 0'

jobs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php-version: ['7.0', '7.2']
db-type: [sqlite, mysql, pgsql]
composer-type: [lowest, stable, dev]
exclude:
- php-version: '7.0'
db-type: sqlite

name: PHP ${{ matrix.php-version }} & ${{ matrix.db-type }} & ${{ matrix.composer-type }}

services:
postgres:
image: postgres
ports:
- 5432:5432
env:
POSTGRES_DB: test_suite_light
POSTGRES_PASSWORD: root
POSTGRES_USER: root

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl, apcu, pdo_${{ matrix.db-type }}
ini-values: apc.enable_cli = 1

- name: Update composer
run: composer self-update

- name: Validate composer.json
run: composer validate

- name: Install dependencies
run: |
if [[ ${{ matrix.composer-type }} == 'lowest' ]]; then
composer update --prefer-dist --no-progress --no-suggest --prefer-stable --prefer-lowest
elif [[ ${{ matrix.composer-type }} == 'stable' ]]; then
composer update --prefer-dist --no-progress --no-suggest --prefer-stable
else
composer update --prefer-dist --no-progress --no-suggest
fi
- name: Run tests
run: |
if [ ${{ matrix.db-type }} == 'mysql' ]; then
sudo service mysql start && mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE IF NOT EXISTS test_suite_light;';
fi
composer run-tests-${{ matrix.db-type }} root root
name: GitHub CI

on:
push:
branches:
- '*'
pull_request:
branches:
- '*'
schedule:
- cron: '0 0 * * 0'

jobs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php-version: ['7.0', '7.2']
db-type: [sqlite, mysql, pgsql]
composer-type: [lowest, stable, dev]
exclude:
- php-version: '7.0'
db-type: sqlite

name: PHP ${{ matrix.php-version }} & ${{ matrix.db-type }} & ${{ matrix.composer-type }}

services:
postgres:
image: postgres
ports:
- 5432:5432
env:
POSTGRES_DB: test_suite_light
POSTGRES_PASSWORD: root
POSTGRES_USER: root

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl, apcu, pdo_${{ matrix.db-type }}
ini-values: apc.enable_cli = 1

- name: Update composer
run: composer self-update

- name: Validate composer.json
run: composer validate

- name: Install dependencies
run: |
if [[ ${{ matrix.composer-type }} == 'lowest' ]]; then
composer update --prefer-dist --no-progress --no-suggest --prefer-stable --prefer-lowest
elif [[ ${{ matrix.composer-type }} == 'stable' ]]; then
composer update --prefer-dist --no-progress --no-suggest --prefer-stable
else
composer update --prefer-dist --no-progress --no-suggest
fi
- name: Run tests
run: |
if [ ${{ matrix.db-type }} == 'mysql' ]; then
sudo service mysql start && mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE IF NOT EXISTS test_suite_light;';
fi
composer run-tests-${{ matrix.db-type }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ dummy_database
composer.lock
/.phpunit.result.cache
/tmp/
.env
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
"minimum-stability": "dev",
"require": {
"php": ">=7.0",
"cakephp/cakephp": "^3.6"
"cakephp/cakephp": "^3.7",
"ext-pdo": "*"
},
"require-dev": {
"cakephp/migrations": "^2.3",
"josegonzalez/dotenv": "dev-master",
"phpunit/phpunit": "^6.1"
},
"autoload": {
Expand All @@ -30,7 +33,8 @@
"autoload-dev": {
"psr-4": {
"CakephpTestSuiteLight\\Test\\": "tests",
"TestApp\\": "tests/TestApp/src"
"TestApp\\": "tests/TestApp/src",
"TestApp\\Test\\": "tests/TestApp/tests"
}
},
"scripts": {
Expand Down
33 changes: 8 additions & 25 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,9 @@
#!/bin/bash

DRIVER=$1;
USER=$2;
PWD=$3;
DRIVER_NAMESPACE='Cake\Database\Driver\'

echo "Starting PHPUNIT tests"

if [ -n "$DRIVER" ]; then
DRIVER="$DRIVER_NAMESPACE$DRIVER"
export DB_DRIVER=$DRIVER
echo "With driver: $DRIVER"
else
echo "Using default driver $DB_DRIVER"
fi

if [ -n "$USER" ]; then
export DB_USER=$USER
echo "With user: $USER"
else
echo "Using default user $DB_USER"
fi

if [ -n "$PWD" ]; then
export DB_PWD=$PWD
echo "With password: $PWD"
else
echo "Using default password $DB_PWD"
fi
export DB_DRIVER=$DRIVER

# Test Cases where tables get dropped are put separately,
# since they are giving a hard time to the fixtures
Expand All @@ -38,3 +14,10 @@ fi
./vendor/bin/phpunit --testsuite DropCountries --stop-on-fail
./vendor/bin/phpunit --testsuite DropTables --stop-on-fail

# Run the tests again using non-triggered based sniffers
export TABLE_SNIFFER="CakephpTestSuiteLight\Sniffer\\${DRIVER}TableSniffer"

./vendor/bin/phpunit --testsuite Default --stop-on-fail
./vendor/bin/phpunit --testsuite DropCities --stop-on-fail
./vendor/bin/phpunit --testsuite DropCountries --stop-on-fail
./vendor/bin/phpunit --testsuite DropTables --stop-on-fail
4 changes: 0 additions & 4 deletions src/FixtureInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ class FixtureInjector extends \Cake\TestSuite\Fixture\FixtureInjector
public function __construct(FixtureManager $manager, bool $withStatistics = false)
{
$this->_fixtureManager = $manager;
$this->_fixtureManager
->collectDirtyTables()
->truncateDirtyTables();
$this->statisticTool = new StatisticTool($manager, $withStatistics);
}

Expand Down Expand Up @@ -85,7 +82,6 @@ public function startTest(Test $test)
*/
public function endTest(Test $test, $time)
{
$this->_fixtureManager->collectDirtyTables();
$this->statisticTool->collectTestStatistics($test, $time);
}

Expand Down
Loading

0 comments on commit 3268a45

Please sign in to comment.