Skip to content

Commit 9980e32

Browse files
committed
[FIX] Test package
1 parent b4053ad commit 9980e32

File tree

8 files changed

+89
-50
lines changed

8 files changed

+89
-50
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
### Composer template
22
composer.phar
33
/vendor/
4+
/build/

composer.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi",
5454
"clear": "@php vendor/bin/testbench package:purge-filament-otp-input --ansi",
5555
"analyse": "vendor/bin/phpstan analyse",
56-
"test": "vendor/bin/pest",
56+
"test": "vendor/bin/pest --parallel",
5757
"test-coverage": "vendor/bin/pest --coverage",
5858
"format": "vendor/bin/pint"
5959
},
@@ -69,10 +69,7 @@
6969
"laravel": {
7070
"providers": [
7171
"HasanAhani\\FilamentOtpInput\\FilamentOtpInputServiceProvider"
72-
],
73-
"aliases": {
74-
"Skeleton": "HasanAhani\\FilamentOtpInput\\Facades\\Skeleton"
75-
}
72+
]
7673
}
7774
},
7875
"minimum-stability": "dev",

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml.dist

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5+
backupGlobals="false"
6+
backupStaticAttributes="false"
7+
bootstrap="vendor/autoload.php"
8+
colors="true"
9+
convertErrorsToExceptions="true"
10+
convertNoticesToExceptions="true"
11+
convertWarningsToExceptions="true"
12+
processIsolation="false"
13+
stopOnFailure="false"
14+
executionOrder="random"
15+
failOnWarning="true"
16+
failOnRisky="true"
17+
failOnEmptyTestSuite="true"
18+
beStrictAboutOutputDuringTests="true"
19+
verbose="true"
20+
>
21+
<testsuites>
22+
<testsuite name="HasanAhani Test Suite">
23+
<directory>tests</directory>
24+
</testsuite>
25+
</testsuites>
26+
<coverage>
27+
<include>
28+
<directory suffix=".php">./src</directory>
29+
</include>
30+
<report>
31+
<html outputDirectory="build/coverage"/>
32+
<text outputFile="build/coverage.txt"/>
33+
<clover outputFile="build/logs/clover.xml"/>
34+
</report>
35+
</coverage>
36+
<logging>
37+
<junit outputFile="build/report.junit.xml"/>
38+
</logging>
39+
</phpunit>

tests/ArchTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
it('will not use debugging functions')
64
->expect(['dd', 'dump', 'ray', 'var_dump', 'ddd'])
75
->each->not->toBeUsed();
8-
9-
test('strict types are used')
10-
->expect('HasanAhani\FilamentOtpInput')
11-
->toUseStrictTypes();
12-
13-
test('strict types are used in tests')
14-
->expect('HasanAhani\FilamentOtpInput\Tests')
15-
->toUseStrictTypes();
16-
17-
test('only otp input are put in the component directory')
18-
->expect('HasanAhani\FilamentOtpInput\Components')
19-
->toBeClasses();

tests/Fixtures/Livewire.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace HasanAhani\FilamentOtpInput\Tests\Fixtures;
4+
5+
use Filament\Forms\Concerns\InteractsWithForms;
6+
use Filament\Forms\Contracts\HasForms;
7+
use Livewire\Component;
8+
9+
class Livewire extends Component implements HasForms
10+
{
11+
use InteractsWithForms;
12+
13+
public $data;
14+
15+
public static function make(): static
16+
{
17+
return new static();
18+
}
19+
20+
public function mount(): void
21+
{
22+
$this->form->fill();
23+
}
24+
25+
public function data($data): static
26+
{
27+
$this->data = $data;
28+
29+
return $this;
30+
}
31+
32+
public function getData()
33+
{
34+
return $this->data;
35+
}
36+
}

tests/InputTest.php

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,26 @@
11
<?php
22

3-
declare(strict_types=1);
4-
3+
use Filament\Forms\ComponentContainer;
54
use Filament\Actions\Concerns\InteractsWithActions;
65
use Filament\Actions\Contracts\HasActions;
76
use Filament\Forms\Concerns\InteractsWithForms;
87
use Filament\Forms\Contracts\HasForms;
98
use Filament\Forms\Form;
9+
use HasanAhani\FilamentOtpInput\Tests\Fixtures\Livewire;
1010
use Livewire\Component;
1111
use HasanAhani\FilamentOtpInput\Components\OtpInput;
1212

13+
use Illuminate\Support\Str;
1314
use function Pest\Livewire\livewire;
1415

1516
it('can be rendered', function () {
16-
$component = new class extends Component implements HasActions, HasForms
17-
{
18-
use InteractsWithActions;
19-
use InteractsWithForms;
20-
21-
public function form(Form $form): Form
22-
{
23-
return $form
24-
->schema([
25-
OtpInput::make('otp')
26-
->numberInput(5),
27-
]);
28-
}
17+
$field = (new OtpInput($name = Str::random()))
18+
->numberInput($number = 5)
19+
->container(ComponentContainer::make(Livewire::make()));
2920

30-
public function render(): string
31-
{
32-
return <<<'HTML'
33-
<div>{{ $this->form }}</div>
34-
HTML;
35-
}
36-
};
21+
expect($field)
22+
->getStatePath()->toBe($name);
3723

38-
livewire($component::class)->assertSuccessful();
24+
expect($field)->getNumberInput()->toBe($number);
3925
});
26+

tests/TestCase.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
<?php
2-
declare(strict_types=1);
3-
42
namespace HasanAhani\FilamentOtpInput\Tests;
53

6-
use Filament\FilamentServiceProvider;
7-
use Livewire\LivewireServiceProvider;
84
use HasanAhani\FilamentOtpInput\FilamentOtpInputServiceProvider;
95
use Orchestra\Testbench\TestCase as Orchestra;
106
class TestCase extends Orchestra
117
{
12-
protected $enablesPackageDiscoveries = true;
138

149
protected function getPackageProviders($app): array
1510
{
1611
return [
17-
LivewireServiceProvider::class,
18-
FilamentServiceProvider::class,
1912
FilamentOtpInputServiceProvider::class,
2013
];
2114
}

0 commit comments

Comments
 (0)