Skip to content

Commit bc9c2c2

Browse files
committed
wip
1 parent a01f0c7 commit bc9c2c2

File tree

19 files changed

+199
-40
lines changed

19 files changed

+199
-40
lines changed

.github/workflows/run-tests.yml

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,22 @@ jobs:
6262
needs: access_check
6363
strategy:
6464
matrix:
65+
db: [ 'mysql', 'sqlite' ]
6566
payload:
66-
- { laravel: '11.*', php: '8.3', 'testbench': '9.*' }
67-
- { laravel: '11.*', php: '8.2', 'testbench': '9.*' }
68-
- { laravel: '10.*', php: '8.3', 'testbench': '8.*' }
69-
- { laravel: '10.*', php: '8.2', 'testbench': '8.*' }
70-
- { laravel: '10.*', php: '8.1', 'testbench': '8.*' }
67+
- { laravel: '11.*', php: '8.3', 'testbench': '9.*', collision: '8.*' }
68+
- { laravel: '11.*', php: '8.2', 'testbench': '9.*', collision: '8.*' }
69+
- { laravel: '10.*', php: '8.3', 'testbench': '8.*', collision: '7.*' }
70+
- { laravel: '10.*', php: '8.2', 'testbench': '8.*', collision: '7.*' }
71+
- { laravel: '10.*', php: '8.1', 'testbench': '8.*', collision: '7.*' }
7172

72-
name: PHP ${{ matrix.payload.php }} - Laravel ${{ matrix.payload.laravel }}
73+
name: PHP ${{ matrix.payload.php }} - Laravel ${{ matrix.payload.laravel }} - DB ${{ matrix.db }}
7374

7475
services:
7576
mysql:
7677
image: mysql:8
7778
env:
78-
MYSQL_USER: root
79-
MYSQL_ROOT_PASSWORD: root
80-
MYSQL_PASSWORD:
81-
MYSQL_ALLOW_EMPTY_PASSWORD: true
79+
MYSQL_USER: test
80+
MYSQL_PASSWORD: test
8281
MYSQL_DATABASE: test
8382
ports:
8483
- 3307:3306
@@ -97,9 +96,23 @@ jobs:
9796
extensions: mbstring, dom, fileinfo, mysql
9897
coverage: none
9998

99+
- name: Set up MySQL and PostgreSQL
100+
run: |
101+
MYSQL_PORT=3307 POSTGRES_PORT=5432 docker compose up ${{ matrix.db }} -d
102+
100103
- name: Install dependencies
101104
run: |
102-
composer require "laravel/framework:${{ matrix.payload.laravel }}" "orchestra/testbench:${{ matrix.payload.testbench }}" --no-interaction --no-update
105+
composer require "laravel/framework:${{ matrix.payload.laravel }}" "orchestra/testbench:${{ matrix.payload.testbench }}" "nunomaduro/collision:${{ matrix.payload.collision }}" --no-interaction --no-update
103106
composer update --prefer-stable --prefer-dist --no-interaction
107+
if [ "${{ matrix.db }}" = "mysql" ]; then
108+
while ! mysqladmin ping --host=127.0.0.1 --user=test --port=3307 --password=test --silent; do
109+
echo "Waiting for MySQL..."
110+
sleep 1
111+
done
112+
else
113+
echo "Not waiting for MySQL."
114+
fi
104115
- name: Execute tests
116+
env:
117+
DB_DRIVER: ${{ matrix.db }}
105118
run: composer test

composer.json

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
},
1616
"autoload-dev": {
1717
"psr-4": {
18-
"Tests\\": "tests/"
18+
"Tests\\": "tests/",
19+
"Workbench\\App\\": "workbench/app/",
20+
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
21+
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
1922
}
2023
},
2124
"extra": {
@@ -32,19 +35,36 @@
3235
"require-dev": {
3336
"mockery/mockery": "^1.2",
3437
"orchestra/testbench": "^8.0|^9.0",
38+
"nunomaduro/collision": "^7.0|^8.0",
3539
"laravel/pint": "^1.14"
3640
},
3741
"minimum-stability": "dev",
3842
"prefer-stable": true,
3943
"scripts": {
4044
"l11": [
41-
"composer update laravel/framework:11.* orchestra/testbench:9.* --with-all-dependencies"
45+
"composer update laravel/framework:11.* orchestra/testbench:9.* nunomaduro/collision:8.* --with-all-dependencies"
4246
],
4347
"l10": [
44-
"composer update laravel/framework:10.* orchestra/testbench:8.* --with-all-dependencies"
48+
"composer update laravel/framework:10.* orchestra/testbench:8.* nunomaduro/collision:7.* --with-all-dependencies"
4549
],
4650
"test": [
47-
"CI_DB_DRIVER=sqlite CI_DB_DATABASE=:memory: phpunit"
51+
"testbench package:test"
52+
],
53+
"post-autoload-dump": [
54+
"@clear",
55+
"@prepare"
56+
],
57+
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
58+
"prepare": "@php vendor/bin/testbench package:discover --ansi",
59+
"build": "@php vendor/bin/testbench workbench:build --ansi",
60+
"serve": [
61+
"Composer\\Config::disableProcessTimeout",
62+
"@build",
63+
"@php vendor/bin/testbench serve"
64+
],
65+
"lint": [
66+
"@php vendor/bin/pint",
67+
"@php vendor/bin/phpstan analyse"
4868
]
4969
}
50-
}
70+
}

docker-compose.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
services:
2+
mysql:
3+
image: mysql:8
4+
ports:
5+
- '${MYSQL_PORT:-3307}:3306'
6+
environment:
7+
MYSQL_USER: 'test'
8+
MYSQL_PASSWORD: 'test'
9+
MYSQL_DATABASE: 'test'
10+
MYSQL_RANDOM_ROOT_PASSWORD: true
11+
pgsql:
12+
image: postgres:14
13+
ports:
14+
- '${POSTGRES_PORT:-5432}:5432'
15+
environment:
16+
POSTGRES_USER: 'test'
17+
POSTGRES_PASSWORD: 'test'
18+
POSTGRES_DB: 'test'

testbench.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
providers:
2+
- Workbench\App\Providers\WorkbenchServiceProvider
3+
- Stackkit\LaravelDatabaseEmails\LaravelDatabaseEmailsServiceProvider
4+
5+
migrations:
6+
- workbench/database/migrations
7+
8+
seeders:
9+
- Workbench\Database\Seeders\DatabaseSeeder
10+
11+
workbench:
12+
start: '/'
13+
install: true
14+
health: false
15+
discovers:
16+
web: true
17+
api: false
18+
commands: false
19+
components: false
20+
views: false
21+
build: []
22+
assets: []
23+
sync: []

tests/QueuedEmailsTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@
99

1010
class QueuedEmailsTest extends TestCase
1111
{
12-
public function setUp(): void
13-
{
14-
parent::setUp();
15-
}
16-
1712
#[Test]
1813
public function queueing_an_email_will_leave_sending_on_false()
1914
{
15+
Queue::fake();
16+
2017
$email = $this->queueEmail();
2118

2219
$this->assertEquals(0, $email->sending);
@@ -25,6 +22,8 @@ public function queueing_an_email_will_leave_sending_on_false()
2522
#[Test]
2623
public function queueing_an_email_will_set_the_queued_at_column()
2724
{
25+
Queue::fake();
26+
2827
$email = $this->queueEmail();
2928

3029
$this->assertNotNull($email->queued_at);

tests/TestCase.php

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
namespace Tests;
44

5+
use Illuminate\Foundation\Testing\DatabaseTransactions;
6+
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
7+
use Illuminate\Foundation\Testing\RefreshDatabase;
58
use Stackkit\LaravelDatabaseEmails\Email;
9+
use Stackkit\LaravelDatabaseEmails\LaravelDatabaseEmailsServiceProvider;
610

711
class TestCase extends \Orchestra\Testbench\TestCase
812
{
913
protected $invalid;
1014

15+
use LazilyRefreshDatabase;
16+
1117
public function setUp(): void
1218
{
1319
parent::setUp();
@@ -31,20 +37,10 @@ function () {
3137
Email::truncate();
3238
}
3339

34-
/**
35-
* Get package providers. At a minimum this is the package being tested, but also
36-
* would include packages upon which our package depends, e.g. Cartalyst/Sentry
37-
* In a normal app environment these would be added to the 'providers' array in
38-
* the config/app.php file.
39-
*
40-
* @param \Illuminate\Foundation\Application $app
41-
*
42-
* @return array
43-
*/
4440
protected function getPackageProviders($app)
4541
{
4642
return [
47-
\Stackkit\LaravelDatabaseEmails\LaravelDatabaseEmailsServiceProvider::class,
43+
LaravelDatabaseEmailsServiceProvider::class,
4844
];
4945
}
5046

@@ -61,15 +57,25 @@ protected function getEnvironmentSetUp($app)
6157
$app['config']->set('laravel-database-emails.testing.email', '[email protected]');
6258

6359
$app['config']->set('database.default', 'testbench');
60+
$driver = env('DB_DRIVER', 'sqlite');
6461
$app['config']->set('database.connections.testbench', [
65-
'driver' => getenv('CI_DB_DRIVER'),
66-
'host' => getenv('CI_DB_HOST'),
67-
'port' => getenv('CI_DB_PORT'),
68-
'database' => getenv('CI_DB_DATABASE'),
69-
'username' => getenv('CI_DB_USERNAME'),
70-
'password' => getenv('CI_DB_PASSWORD'),
71-
'prefix' => '',
72-
'strict' => true,
62+
'driver' => $driver,
63+
...match($driver) {
64+
'sqlite' => [
65+
'database' => ':memory:',
66+
],
67+
'mysql' => [
68+
'host' => '127.0.0.1',
69+
'port' => 3307,
70+
],
71+
'pgsql' => [
72+
'host' => '127.0.0.1',
73+
'port' => 5432,
74+
],
75+
},
76+
'database' => 'test',
77+
'username' => 'test',
78+
'password' => 'test',
7379
]);
7480

7581
$app['config']->set('mail.driver', 'log');

workbench/app/Models/.gitkeep

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Workbench\App\Providers;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
7+
class WorkbenchServiceProvider extends ServiceProvider
8+
{
9+
/**
10+
* Register services.
11+
*/
12+
public function register(): void
13+
{
14+
//
15+
}
16+
17+
/**
18+
* Bootstrap services.
19+
*/
20+
public function boot(): void
21+
{
22+
//
23+
}
24+
}

workbench/bootstrap/.gitkeep

Whitespace-only changes.

workbench/bootstrap/app.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
use Illuminate\Foundation\Application;
4+
use Illuminate\Foundation\Configuration\Exceptions;
5+
use Illuminate\Foundation\Configuration\Middleware;
6+
7+
use function Orchestra\Testbench\default_skeleton_path;
8+
9+
return Application::configure(basePath: $APP_BASE_PATH ?? default_skeleton_path())
10+
->withRouting(
11+
web: __DIR__.'/../routes/web.php',
12+
commands: __DIR__.'/../routes/console.php',
13+
)
14+
->withMiddleware(function (Middleware $middleware) {
15+
//
16+
})
17+
->withExceptions(function (Exceptions $exceptions) {
18+
//
19+
})->create();

workbench/bootstrap/providers.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
//
5+
];

workbench/database/factories/.gitkeep

Whitespace-only changes.

workbench/database/migrations/.gitkeep

Whitespace-only changes.

workbench/database/seeders/.gitkeep

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Workbench\Database\Seeders;
4+
5+
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
6+
use Illuminate\Database\Seeder;
7+
8+
class DatabaseSeeder extends Seeder
9+
{
10+
/**
11+
* Run the database seeds.
12+
*/
13+
public function run(): void
14+
{
15+
//
16+
}
17+
}

workbench/resources/views/.gitkeep

Whitespace-only changes.

workbench/routes/.gitkeep

Whitespace-only changes.

workbench/routes/console.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
use Illuminate\Foundation\Inspiring;
4+
use Illuminate\Support\Facades\Artisan;
5+
6+
Artisan::command('inspire', function () {
7+
$this->comment(Inspiring::quote());
8+
})->purpose('Display an inspiring quote')->hourly();

workbench/routes/web.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Route;
4+
5+
Route::get('/', function () {
6+
return view('welcome');
7+
});

0 commit comments

Comments
 (0)