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

Drop phpunit support #26

Merged
merged 3 commits into from
Jan 13, 2023
Merged
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
3 changes: 0 additions & 3 deletions config/somake.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,5 @@
'policy' => null,
'request' => Illuminate\Foundation\Http\FormRequest::class,
'resource' => Illuminate\Http\Resources\Json\JsonResource::class,
'test_contract' => Tests\TestCase::class,
'test_feature' => Tests\TestCase::class,
'test_unit' => PHPUnit\Framework\TestCase::class,
],
];
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Class Tests\\\\TestCase not found\\.$#"
count: 2
path: config/somake.php

-
message: "#^Method Soyhuce\\\\Somake\\\\Commands\\\\BuilderCommand\\:\\:askModel\\(\\) should return class\\-string\\<Illuminate\\\\Database\\\\Eloquent\\\\Model\\> but returns array\\|bool\\|string\\.$#"
count: 1
Expand Down
19 changes: 0 additions & 19 deletions resources/views/test-contract.blade.php

This file was deleted.

19 changes: 0 additions & 19 deletions resources/views/test-feature.blade.php

This file was deleted.

17 changes: 0 additions & 17 deletions resources/views/test-unit.blade.php

This file was deleted.

6 changes: 1 addition & 5 deletions src/Commands/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ protected function askType(): string

private function stubFile(string $type): string
{
if (is_file(base_path('tests/Pest.php'))) {
return "pest-{$type}";
}

return "test-{$type}";
return "pest-{$type}";
}
}
4 changes: 3 additions & 1 deletion src/Domains/Request/RouteGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class RouteGuesser

public function __construct(string $controller, string $method)
{
$this->route = RouteFacade::getRoutes()->getByAction("{$controller}@{$method}");
$action = $method === '__invoke' ? $controller : $controller . '@' . $method;

$this->route = RouteFacade::getRoutes()->getByAction($action);
}

public function verb(): string
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php declare(strict_types=1);

namespace App\Website\Videos\Controllers;

use Illuminate\Http\Response;

class InvokableVideoController
{
public function __invoke(int $video): Response
{
return response()->noContent();
}
}
4 changes: 3 additions & 1 deletion test-laravel/routes/api.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php declare(strict_types=1);

use App\Website\Videos\Controllers\InvokableVideoController;
use App\Website\Videos\Controllers\VideoController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
Expand All @@ -19,4 +20,5 @@
return $request->user();
});

Route::put('videos/{video}', [VideoController::class, 'update']);
Route::get('videos/{video}', [VideoController::class, 'show']);
Route::put('videos-invokable/{video}', InvokableVideoController::class);
97 changes: 10 additions & 87 deletions tests/Feature/TestCommandTest.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
<?php declare(strict_types=1);

it('creates correctly the contract test', function (): void {
$this->artisan('somake:test')
->expectsQuestion('Which kind of test do you want to create ?', 'Contract')
->expectsQuestion('Which controller do you want to cover ?', 'VideoController')
->expectsQuestion('Which method do you want to cover ?', 'update')
->expectsQuestion('What is the Test name ?', 'ContractUpdateVideoTest')
->expectsOutput('The Tests\\Contract\\Website\\Videos\\Video\\ContractUpdateVideoTest class was successfully created !')
->assertExitCode(0)
->execute();

expect($this->app->basePath('tests/Contract/Website/Videos/Video/ContractUpdateVideoTest.php'))
->toBeFile()
->toMatchFileSnapshot();
});

it('creates correctly the contract test with custom base class', function (): void {
config()->set('somake.base_classes.test_contract', 'Tests\\ContractTestCase');
file_put_contents(base_path('tests/Pest.php'), '');

$this->artisan('somake:test')
->expectsQuestion('Which kind of test do you want to create ?', 'Contract')
->expectsQuestion('Which controller do you want to cover ?', 'VideoController')
->expectsQuestion('Which method do you want to cover ?', null)
->expectsQuestion('Which method do you want to cover ?', 'show')
->expectsQuestion('What is the Test name ?', 'ContractShowVideoTest')
->expectsOutput('The Tests\\Contract\\Website\\Videos\\Video\\ContractShowVideoTest class was successfully created !')
->assertExitCode(0)
Expand All @@ -32,45 +17,13 @@
->toMatchFileSnapshot();
});

it('creates correctly the contract pest', function (): void {
file_put_contents(base_path('tests/Pest.php'), '');

$this->artisan('somake:test')
->expectsQuestion('Which kind of test do you want to create ?', 'Contract')
->expectsQuestion('Which controller do you want to cover ?', 'VideoController')
->expectsQuestion('Which method do you want to cover ?', 'update')
->expectsQuestion('What is the Test name ?', 'ContractUpdateVideoTest')
->expectsOutput('The Tests\\Contract\\Website\\Videos\\Video\\ContractUpdateVideoTest class was successfully created !')
->assertExitCode(0)
->execute();

expect($this->app->basePath('tests/Contract/Website/Videos/Video/ContractUpdateVideoTest.php'))
->toBeFile()
->toMatchFileSnapshot();
});

it('creates correctly the feature test', function (): void {
$this->artisan('somake:test')
->expectsQuestion('Which kind of test do you want to create ?', 'Feature')
->expectsQuestion('Which controller do you want to cover ?', 'VideoController')
->expectsQuestion('Which method do you want to cover ?', null)
->expectsQuestion('What is the Test name ?', 'ShowVideoTest')
->expectsOutput('The Tests\\Feature\\Website\\Videos\\VideoController\\ShowVideoTest class was successfully created !')
->assertExitCode(0)
->execute();

expect($this->app->basePath('tests/Feature/Website/Videos/VideoController/ShowVideoTest.php'))
->toBeFile()
->toMatchFileSnapshot();
});

it('creates correctly the feature test with custom base class', function (): void {
config()->set('somake.base_classes.test_feature', 'Tests\\FeatureTestCase');
file_put_contents(base_path('tests/Pest.php'), '');

$this->artisan('somake:test')
->expectsQuestion('Which kind of test do you want to create ?', 'Feature')
->expectsQuestion('Which controller do you want to cover ?', 'VideoController')
->expectsQuestion('Which method do you want to cover ?', null)
->expectsQuestion('Which method do you want to cover ?', 'show')
->expectsQuestion('What is the Test name ?', 'ShowVideoTest')
->expectsOutput('The Tests\\Feature\\Website\\Videos\\VideoController\\ShowVideoTest class was successfully created !')
->assertExitCode(0)
Expand All @@ -96,52 +49,22 @@
->toMatchFileSnapshot();
});

it('creates correctly the feature pest', function (): void {
file_put_contents(base_path('tests/Pest.php'), '');

it('creates correctly the feature test with invokable controller', function (): void {
$this->artisan('somake:test')
->expectsQuestion('Which kind of test do you want to create ?', 'Feature')
->expectsQuestion('Which controller do you want to cover ?', 'VideoController')
->expectsQuestion('Which method do you want to cover ?', null)
->expectsQuestion('What is the Test name ?', 'ShowVideoTest')
->expectsOutput('The Tests\\Feature\\Website\\Videos\\VideoController\\ShowVideoTest class was successfully created !')
->expectsQuestion('Which controller do you want to cover ?', 'InvokableVideoController')
->expectsQuestion('Which method do you want to cover ?', '__invoke')
->expectsQuestion('What is the Test name ?', 'IndexVideosTest')
->expectsOutput('The Tests\\Feature\\Website\\Videos\\InvokableVideoController\\IndexVideosTest class was successfully created !')
->assertExitCode(0)
->execute();

expect($this->app->basePath('tests/Feature/Website/Videos/VideoController/ShowVideoTest.php'))
expect($this->app->basePath('tests/Feature/Website/Videos/InvokableVideoController/IndexVideosTest.php'))
->toBeFile()
->toMatchFileSnapshot();
});

it('creates correctly the unit test', function (): void {
$this->artisan('somake:test')
->expectsQuestion('Which kind of test do you want to create ?', 'Unit')
->expectsQuestion('Which class do you want to cover ?', 'User')
->expectsOutput('The Tests\\Unit\\Domain\\User\\Models\\UserTest class was successfully created !')
->assertExitCode(0)
->execute();

expect($this->app->basePath('tests/Unit/Domain/User/Models/UserTest.php'))
->toBeFile()
->toMatchFileSnapshot();
});

it('creates correctly the unit testwith custom base class', function (): void {
config()->set('somake.base_classes.test_unit', 'Tests\\UnitTestCase');

$this->artisan('somake:test')
->expectsQuestion('Which kind of test do you want to create ?', 'Unit')
->expectsQuestion('Which class do you want to cover ?', 'User')
->expectsOutput('The Tests\\Unit\\Domain\\User\\Models\\UserTest class was successfully created !')
->assertExitCode(0)
->execute();

expect($this->app->basePath('tests/Unit/Domain/User/Models/UserTest.php'))
->toBeFile()
->toMatchFileSnapshot();
});

it('creates correctly the unit pest', function (): void {
file_put_contents(base_path('tests/Pest.php'), '');

$this->artisan('somake:test')
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
<?php

namespace Tests\Contract\Website\Videos\Video;
/* @covers \App\Website\Videos\Controllers\VideoController::show */

use Tests\TestCase;

/**
* @coversDefaultClass \App\Website\Videos\Controllers\VideoController
*/
class ContractUpdateVideoTest extends TestCase
{
/**
* @test
* @covers ::update
*/
public function success(): void
{
$this->putJson("api/videos/{$video}")
->assertValidContract(200);
}
}
it('respects success contract', function (): void {
$this->getJson("api/videos/{$video}")
->assertValidContract(200);
});

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
<?php

namespace Tests\Feature\Website\Videos\VideoController;
/* @covers \App\Website\Videos\Controllers\VideoController::show */

use Tests\TestCase;

/**
* @coversDefaultClass \App\Website\Videos\Controllers\VideoController
*/
class ShowVideoTest extends TestCase
{
/**
* @test
* @covers ::defineMe
*/
public function simple(): void
{
$this->getJson("/")
->assertOk();
}
}
it('is successful', function (): void {
$this->getJson("api/videos/{$video}")
->assertOk();
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

/* @covers \App\Website\Videos\Controllers\InvokableVideoController::__invoke */

it('is successful', function (): void {
$this->putJson("api/videos-invokable/{$video}")
->assertOk();
});
Loading