Skip to content

Commit 9a21f52

Browse files
committed
Add PHPUnit + Orchestra Testbench test scaffolding, CI workflow, and tests badge
1 parent 2d9bf18 commit 9a21f52

6 files changed

Lines changed: 120 additions & 0 deletions

File tree

.github/workflows/tests.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: tests
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
php: ['8.2', '8.3']
17+
laravel: ['11.*', '12.*']
18+
include:
19+
- laravel: '11.*'
20+
testbench: '9.*'
21+
- laravel: '12.*'
22+
testbench: '10.*'
23+
24+
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
25+
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
30+
- name: Setup PHP
31+
uses: shivammathur/setup-php@v2
32+
with:
33+
php-version: ${{ matrix.php }}
34+
extensions: mbstring, pdo, pdo_sqlite
35+
coverage: none
36+
37+
- name: Install dependencies
38+
run: |
39+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
40+
composer update --prefer-dist --no-interaction --no-progress
41+
42+
- name: Run tests
43+
run: vendor/bin/phpunit

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# xnoire666/db-diff
22

33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/xnoire666/db-diff.svg?style=flat-square)](https://packagist.org/packages/xnoire666/db-diff)
4+
[![Tests](https://img.shields.io/github/actions/workflow/status/xnoire666/db-diff/tests.yml?branch=master&label=tests&style=flat-square)](https://github.com/xnoire666/db-diff/actions/workflows/tests.yml)
45
[![Total Downloads](https://img.shields.io/packagist/dt/xnoire666/db-diff.svg?style=flat-square)](https://packagist.org/packages/xnoire666/db-diff)
56
[![License](https://img.shields.io/packagist/l/xnoire666/db-diff.svg?style=flat-square)](https://packagist.org/packages/xnoire666/db-diff)
67

composer.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,23 @@
1717
"illuminate/filesystem": "^9.0|^10.0|^11.0|^12.0",
1818
"illuminate/support": "^9.0|^10.0|^11.0|^12.0"
1919
},
20+
"require-dev": {
21+
"orchestra/testbench": "^8.0|^9.0|^10.0",
22+
"phpunit/phpunit": "^10.5|^11.0"
23+
},
2024
"autoload": {
2125
"psr-4": {
2226
"Xnoire666\\DbDiff\\": "src/"
2327
}
2428
},
29+
"autoload-dev": {
30+
"psr-4": {
31+
"Xnoire666\\DbDiff\\Tests\\": "tests/"
32+
}
33+
},
34+
"scripts": {
35+
"test": "vendor/bin/phpunit"
36+
},
2537
"extra": {
2638
"laravel": {
2739
"providers": [

phpunit.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true">
6+
<testsuites>
7+
<testsuite name="Unit">
8+
<directory>tests/Unit</directory>
9+
</testsuite>
10+
</testsuites>
11+
<source>
12+
<include>
13+
<directory>src</directory>
14+
</include>
15+
</source>
16+
</phpunit>

tests/TestCase.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Xnoire666\DbDiff\Tests;
4+
5+
use Orchestra\Testbench\TestCase as OrchestraTestCase;
6+
use Xnoire666\DbDiff\DbDiffServiceProvider;
7+
8+
abstract class TestCase extends OrchestraTestCase
9+
{
10+
protected function getPackageProviders($app): array
11+
{
12+
return [DbDiffServiceProvider::class];
13+
}
14+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Xnoire666\DbDiff\Tests\Unit;
4+
5+
use Xnoire666\DbDiff\Console\Commands\DbDiffCommand;
6+
use Xnoire666\DbDiff\Tests\TestCase;
7+
8+
class DbDiffServiceProviderTest extends TestCase
9+
{
10+
public function test_config_is_merged(): void
11+
{
12+
$this->assertIsArray(config('db-diff.connections'));
13+
$this->assertArrayHasKey('mysql1', config('db-diff.connections'));
14+
$this->assertArrayHasKey('mysql2', config('db-diff.connections'));
15+
}
16+
17+
public function test_db_diff_command_is_registered(): void
18+
{
19+
$commands = $this->app[\Illuminate\Contracts\Console\Kernel::class]->all();
20+
21+
$this->assertArrayHasKey('db:diff', $commands);
22+
$this->assertInstanceOf(DbDiffCommand::class, $commands['db:diff']);
23+
}
24+
25+
public function test_config_file_is_publishable(): void
26+
{
27+
$paths = \Illuminate\Support\ServiceProvider::pathsToPublish(
28+
\Xnoire666\DbDiff\DbDiffServiceProvider::class,
29+
'db-diff-config'
30+
);
31+
32+
$this->assertNotEmpty($paths);
33+
}
34+
}

0 commit comments

Comments
 (0)