Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Add tests #17

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions .github/workflows/pint.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
name: PHP Linting (Pint)
name: 'PHP Code Styling'

on:
workflow_dispatch:
push:
branches-ignore:
- 'dependabot/npm_and_yarn/*'
branches:
- main
paths:
- '**.php'

permissions:
contents: write

jobs:
phplint:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: "laravel-pint"
uses: aglipanci/[email protected]
with:
preset: laravel
ref: ${{ github.head_ref }}

- name: Fix PHP code style issues
uses: aglipanci/laravel-pint-action@v2

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: PHP Linting (Pint)
skip_fetch: true
commit_message: "Format Code"
commit_user_name: 'GitHub Actions'
69 changes: 69 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: "Tests"

on:
workflow_dispatch:
pull_request:
types:
- opened
- synchronize
branches:
- main
paths:
- '**.php'
- '.github/workflows/tests.yml'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.3, 8.2, 8.1]
laravel: [11.*, 10.*]
stability: [prefer-stable]
include:
- laravel: 11.*
testbench: 9.*
carbon: 3.*
collision: 8.*
- laravel: 10.*
testbench: 8.*
carbon: 2.*
collision: 7.*
exclude:
- laravel: 11.*
php: 8.1
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Cache Dependencies
uses: actions/cache@v4
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Install Dependencies
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Install Dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" "nunomaduro/collision:${{ matrix.collision }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: Execute tests
run: vendor/bin/pest --parallel
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
.idea
.phpunit.cache
.phpunit.result.cache
.vscode
build
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
},
"autoload": {
"psr-4": {
"CodeWithDennis\\SimpleAlert\\": "src/",
"CodeWithDennis\\SimpleAlert\\Database\\Factories\\": "database/factories/"
"CodeWithDennis\\SimpleAlert\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"CodeWithDennis\\SimpleAlert\\Tests\\": "tests/"
"CodeWithDennis\\SimpleAlert\\Tests\\": "tests/src",
"CodeWithDennis\\SimpleAlert\\Tests\\Database\\Factories\\": "tests/database/factories"

}
},
"scripts": {
Expand Down
45 changes: 17 additions & 28 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,38 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd"
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<testsuites>
<testsuite name="CodeWithDennis Test Suite">
<directory>tests</directory>
<testsuite name="FilamentSimpleAlert">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<coverage>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
<php>
<env name="APP_ENV" value="self-testing"/>
<env name="APP_KEY" value="base64:UlE7hpzgY3KFqx4yxA9BvR8n2tDm5iXcZ6WoVSOkj/M="/>
<env name="DB_CONNECTION" value="testing"/>
</php>
</phpunit>
2 changes: 1 addition & 1 deletion src/Components/Concerns/HasColor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

trait HasColor
{
protected Closure|string $color = 'gray';
public Closure|string $color = 'gray';

public function color(Closure|string $color): static
{
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Concerns/HasDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

trait HasDescription
{
protected string|Htmlable|Closure|null $description = null;
public string|Htmlable|Closure|null $description = null;

public function description(string|Htmlable|Closure|null $description): static
{
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Concerns/HasIcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

trait HasIcon
{
protected Closure|string|null $icon = null;
public Closure|string|null $icon = null;

public function icon(Closure|string $icon): static
{
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Concerns/HasTitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

trait HasTitle
{
protected string|Htmlable|Closure|null $title = null;
public string|Htmlable|Closure|null $title = null;

public function title(string|Htmlable|Closure|null $title): static
{
Expand Down
2 changes: 1 addition & 1 deletion src/Facades/SimpleAlert.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class SimpleAlert extends Facade
{
protected static function getFacadeAccessor()
protected static function getFacadeAccessor(): string
{
return \CodeWithDennis\SimpleAlert\SimpleAlert::class;
}
Expand Down
8 changes: 8 additions & 0 deletions src/SimpleAlertServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace CodeWithDennis\SimpleAlert;

use CodeWithDennis\SimpleAlert\Testing\TestsSimpleAlert;
use Livewire\Features\SupportTesting\Testable;
use Spatie\LaravelPackageTools\Commands\InstallCommand;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
Expand All @@ -24,6 +26,12 @@ public function configurePackage(Package $package): void
}
}

public function packageBooted(): void
{
// Testing
Testable::mixin(new TestsSimpleAlert);
}

protected function getAssetPackageName(): ?string
{
return 'codewithdennis/filament-simple-alert';
Expand Down
10 changes: 10 additions & 0 deletions src/Testing/TestsSimpleAlert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace CodeWithDennis\SimpleAlert\Testing;

use Livewire\Features\SupportTesting\Testable;

/**
* @mixin Testable
*/
class TestsSimpleAlert {}
5 changes: 5 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

use CodeWithDennis\SimpleAlert\Tests\TestCase;

uses(TestCase::class)->in(__DIR__);
20 changes: 20 additions & 0 deletions tests/database/factories/DummyFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace CodeWithDennis\SimpleAlert\Tests\Database\Factories;

use CodeWithDennis\SimpleAlert\Tests\Models\Dummy;
use Illuminate\Database\Eloquent\Factories\Factory;

class DummyFactory extends Factory
{
protected $model = Dummy::class;

public function definition(): array
{
$title = fake()->sentence();

return [
'title' => $title,
];
}
}
23 changes: 23 additions & 0 deletions tests/database/factories/UserFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace CodeWithDennis\SimpleAlert\Tests\Database\Factories;

use CodeWithDennis\SimpleAlert\Tests\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

class UserFactory extends Factory
{
protected $model = User::class;

public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
];
}
}
17 changes: 17 additions & 0 deletions tests/database/migrations/create_dummies_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::create('dummies', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->timestamps();
});
}
};
Loading