Skip to content

Commit ecc77ed

Browse files
Tests added
1 parent 88a8e97 commit ecc77ed

21 files changed

+455
-52
lines changed

.github/workflows/tests.yml

+108-23
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,115 @@ name: Tests
33
on: [ push, pull_request ]
44

55
jobs:
6-
build:
7-
runs-on: ubuntu-latest
6+
7+
sqlite:
8+
runs-on: ubuntu-latest
9+
10+
strategy:
11+
fail-fast: true
12+
matrix:
13+
php: [ "8.2", "8.3" ]
14+
laravel: [ "10.0", "11.0" ]
15+
16+
name: PHP ${{ matrix.php }}, Laravel ${{ matrix.laravel }}, SQLite 3
817

9-
strategy:
10-
fail-fast: true
11-
matrix:
12-
php: [ "8.2", "8.3" ]
13-
laravel: [ "10.0", "11.0" ]
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
1421

15-
name: PHP ${{ matrix.php }}, Laravel ${{ matrix.laravel }}
22+
- name: Setup PHP
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: ${{ matrix.php }}
26+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis, pdo_mysql, pdo_pgsql
27+
coverage: xdebug
1628

17-
steps:
18-
- name: Checkout code
19-
uses: actions/checkout@v4
29+
- name: Install dependencies
30+
run: composer require laravel/framework:^${{ matrix.laravel }}
2031

21-
- name: Setup PHP
22-
uses: shivammathur/setup-php@v2
23-
with:
24-
php-version: ${{ matrix.php }}
25-
extensions: curl, mbstring, zip, pcntl, pdo, pdo_sqlite, iconv
26-
coverage: xdebug
27-
28-
- name: Install dependencies
29-
run: composer require laravel/framework:^${{ matrix.laravel }}
30-
31-
- name: Execute tests
32-
run: sudo vendor/bin/phpunit
32+
- name: Execute tests
33+
run: sudo vendor/bin/phpunit
34+
35+
# mysql:
36+
# runs-on: ubuntu-latest
37+
#
38+
# strategy:
39+
# fail-fast: true
40+
# matrix:
41+
# php: [ "8.2", "8.3" ]
42+
# laravel: [ "10.0", "11.0" ]
43+
# mysql: [ "5.7", "8" ]
44+
#
45+
# name: PHP ${{ matrix.php }}, Laravel ${{ matrix.laravel }}, PostgreSQL ${{ matrix.psql }}
46+
#
47+
# services:
48+
# mysql:
49+
# image: mysql:${{ matrix.mysql }}
50+
# env:
51+
# MYSQL_ROOT_PASSWORD: root
52+
# MYSQL_DATABASE: default
53+
# ports:
54+
# - 3306:3306
55+
# options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
56+
#
57+
# steps:
58+
# - name: Checkout code
59+
# uses: actions/checkout@v4
60+
#
61+
# - name: Setup PHP
62+
# uses: shivammathur/setup-php@v2
63+
# with:
64+
# php-version: ${{ matrix.php }}
65+
# extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis, pdo_mysql, pdo_pgsql
66+
# coverage: xdebug
67+
#
68+
# - name: Install dependencies
69+
# run: composer require laravel/framework:^${{ matrix.laravel }}
70+
#
71+
# - name: Execute tests
72+
# run: sudo vendor/bin/phpunit
73+
# env:
74+
# DB_CONNECTION: mysql
75+
# MYSQL_HOST: 127.0.0.1
76+
#
77+
# postgres:
78+
# runs-on: ubuntu-latest
79+
#
80+
# strategy:
81+
# fail-fast: true
82+
# matrix:
83+
# php: [ "8.2", "8.3" ]
84+
# laravel: [ "10.0", "11.0" ]
85+
# psql: [ "12", "13", "14", "15", "16" ]
86+
#
87+
# name: PHP ${{ matrix.php }}, Laravel ${{ matrix.laravel }}, PostgreSQL ${{ matrix.psql }}
88+
#
89+
# services:
90+
# postgres:
91+
# image: postgres:${{ matrix.psql }}-alpine
92+
# ports:
93+
# - 5432:5432
94+
# env:
95+
# POSTGRES_DB: default
96+
# POSTGRES_USER: root
97+
# POSTGRES_PASSWORD: root
98+
#
99+
# steps:
100+
# - name: Checkout code
101+
# uses: actions/checkout@v4
102+
#
103+
# - name: Setup PHP
104+
# uses: shivammathur/setup-php@v2
105+
# with:
106+
# php-version: ${{ matrix.php }}
107+
# extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis, pdo_mysql, pdo_pgsql
108+
# coverage: xdebug
109+
#
110+
# - name: Install dependencies
111+
# run: composer require laravel/framework:^${{ matrix.laravel }}
112+
#
113+
# - name: Execute tests
114+
# run: sudo vendor/bin/phpunit
115+
# env:
116+
# DB_CONNECTION: pgsql
117+
# PGSQL_HOST: 127.0.0.1

.gitignore

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
.idea/
2-
_site/
32
build/
4-
node_modules/
5-
tmp/
3+
tests/tmp/
64
vendor/
75

86
.cache
97
.DS_Store
108
.env
11-
.php_cs.cache
12-
.phpintel
139
.temp
1410

1511
*.bak
@@ -18,4 +14,3 @@ vendor/
1814
*.orig
1915

2016
composer.lock
21-
package-lock.json

composer.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949
"require-dev": {
5050
"mockery/mockery": "^1.3.1",
5151
"orchestra/testbench": "^8.0 || ^9.0",
52-
"phpunit/phpunit": "^10.0"
52+
"pestphp/pest": "^2.34",
53+
"pestphp/pest-plugin-laravel": "^2.3",
54+
"ext-pdo": "*"
5355
},
5456
"minimum-stability": "stable",
5557
"prefer-stable": true,
@@ -68,6 +70,7 @@
6870
"dragon-code/codestyler": true,
6971
"ergebnis/composer-normalize": true,
7072
"friendsofphp/php-cs-fixer": true,
73+
"pestphp/pest-plugin": true,
7174
"symfony/thanks": true
7275
},
7376
"preferred-install": "dist",
@@ -79,5 +82,10 @@
7982
"DragonCode\\LaravelDataDumper\\ServiceProvider"
8083
]
8184
}
85+
},
86+
"scripts": {
87+
"test": [
88+
"vendor/bin/pest --parallel"
89+
]
8290
}
8391
}

phpunit.xml

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
<text outputFile="build/logs/coverage.txt"/>
1313
</report>
1414
</coverage>
15-
<php>
16-
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
17-
</php>
1815
<testsuites>
1916
<testsuite name="Test Suite">
2017
<directory>./tests</directory>
@@ -25,4 +22,9 @@
2522
<directory>./src</directory>
2623
</include>
2724
</source>
25+
<php>
26+
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
27+
<env name="DB_USERNAME" value="root"/>
28+
<env name="DB_PASSWORD" value="root"/>
29+
</php>
2830
</phpunit>

src/Listeners/DataDumpListener.php renamed to src/Listeners/DumpListener.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use DragonCode\LaravelDataDumper\Service\Tables;
99
use Illuminate\Database\Events\SchemaDumped;
1010

11-
class DataDumpListener
11+
class DumpListener
1212
{
1313
public function __construct(
1414
protected readonly Tables $tables,

src/Service/Tables.php

+3-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace DragonCode\LaravelDataDumper\Service;
66

7-
use stdClass;
7+
use Illuminate\Support\Facades\Schema;
88

99
class Tables
1010
{
@@ -20,20 +20,11 @@ protected function toDump(): array
2020

2121
protected function flatten(): array
2222
{
23-
return array_map(function (array | stdClass $item) {
24-
return is_array($item) ? $item['name'] : $item->name;
25-
}, $this->getTables());
23+
return array_column($this->getTables(), 'name');
2624
}
2725

2826
protected function getTables(): array
2927
{
30-
return method_exists($this->schema(), 'getAllTables')
31-
? $this->schema()->getAllTables()
32-
: $this->schema()->getTables();
33-
}
34-
35-
protected function schema()
36-
{
37-
return app('db.schema');
28+
return Schema::getTables();
3829
}
3930
}

src/ServiceProvider.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace DragonCode\LaravelDataDumper;
66

77
use DragonCode\LaravelDataDumper\Concerns\About;
8-
use DragonCode\LaravelDataDumper\Listeners\DataDumpListener;
8+
use DragonCode\LaravelDataDumper\Listeners\DumpListener;
99
use Illuminate\Database\Events\SchemaDumped;
1010
use Illuminate\Support\Facades\Event;
1111
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
@@ -29,7 +29,7 @@ public function register(): void
2929

3030
protected function bootListener(): void
3131
{
32-
Event::listen(SchemaDumped::class, DataDumpListener::class);
32+
Event::listen(SchemaDumped::class, DumpListener::class);
3333
}
3434

3535
protected function registerConfig(): void

tests/Fixtures/Database/Migration.php

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Fixtures\Database;
6+
7+
use Illuminate\Database\Migrations\Migration as BaseMigration;
8+
use Illuminate\Database\Query\Builder;
9+
use Illuminate\Database\Schema\Blueprint;
10+
use Illuminate\Support\Facades\DB;
11+
use Illuminate\Support\Facades\Schema;
12+
13+
abstract class Migration extends BaseMigration
14+
{
15+
protected string $tableName;
16+
17+
public function up(): void
18+
{
19+
$this->createTable();
20+
$this->fillTable();
21+
}
22+
23+
protected function createTable(): void
24+
{
25+
Schema::create($this->tableName(), function (Blueprint $table) {
26+
$table->id();
27+
28+
$table->string($this->column());
29+
30+
$table->timestamp('created_at')->useCurrent();
31+
$table->timestamp('updated_at')->useCurrent();
32+
});
33+
}
34+
35+
protected function fillTable(): void
36+
{
37+
circleProcess(fn (int $i) => $this->table()->insert([
38+
$this->column() => $this->value($i),
39+
]));
40+
}
41+
42+
protected function column(): string
43+
{
44+
return columnName($this->tableName);
45+
}
46+
47+
protected function value(int $index): string
48+
{
49+
return valueName($this->tableName, $index);
50+
}
51+
52+
protected function tableName(): string
53+
{
54+
return tableName($this->tableName);
55+
}
56+
57+
protected function table(): Builder
58+
{
59+
return DB::table($this->tableName());
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Fixtures\Providers;
6+
7+
use Illuminate\Support\ServiceProvider;
8+
9+
class TestServiceProvider extends ServiceProvider
10+
{
11+
public function boot(): void
12+
{
13+
$this->bootMigrations();
14+
}
15+
16+
protected function bootMigrations(): void
17+
{
18+
$this->loadMigrationsFrom(__DIR__ . '/../migrations');
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Tests\Fixtures\Database\Migration;
6+
7+
return new class extends Migration {
8+
protected string $tableName = 'foo';
9+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Tests\Fixtures\Database\Migration;
6+
7+
return new class extends Migration {
8+
protected string $tableName = 'bar';
9+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Tests\Fixtures\Database\Migration;
6+
7+
return new class extends Migration {
8+
protected string $tableName = 'baz';
9+
};

tests/Helpers/circle.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
function circleProcess(Closure $callback): void
6+
{
7+
for ($i = 0; $i < 10; $i++) {
8+
$callback($i);
9+
}
10+
}

0 commit comments

Comments
 (0)