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

Prepare tests for phpUnit12 #594

Closed
wants to merge 7 commits into from
Closed
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
134 changes: 60 additions & 74 deletions tests/ConfigFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
namespace Tests;

use L5Swagger\Exceptions\L5SwaggerException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\TestDox;

/**
* @testdox Configuration factory
*/
#[TestDox('Configuration factory')]
class ConfigFactoryTest extends TestCase
{
/**
* @test
*/
public function itThrowsExceptionIfDocumentationConfigNotFound(): void
public function testItThrowsExceptionIfDocumentationConfigNotFound(): void
{
$config = config('l5-swagger');
unset($config['documentations']['default']);
Expand All @@ -25,16 +22,10 @@ public function itThrowsExceptionIfDocumentationConfigNotFound(): void
}

/**
* @test
*
* @dataProvider configDataProvider
*
* @param array $data
* @param array $assert
*
* @throws L5SwaggerException
*/
public function canMergeConfigurationDeep(array $data, array $assert): void
#[DataProvider('configDataProvider')]
public function testCanMergeConfigurationDeep(array $data, array $assert): void
{
config(['l5-swagger' => array_merge(
$data,
Expand All @@ -58,72 +49,70 @@ public function canMergeConfigurationDeep(array $data, array $assert): void
$this->assertArraySimilar($config, $assert);
}

public static function configDataProvider(): array
public static function configDataProvider(): \Iterator
{
return [
yield [
[
[
'default' => 'v2',
'documentations' => [
'v2' => [
'api' => [
'title' => 'Api V2',
],
'paths' => [
'docs_json' => 'api-v2.json',
],
'proxy' => true,
'default' => 'v2',
'documentations' => [
'v2' => [
'api' => [
'title' => 'Api V2',
],
'paths' => [
'docs_json' => 'api-v2.json',
],
'proxy' => true,
],
],
[
'api' => [
'title' => 'Api V2',
],
'routes' => [
'api' => 'api/documentation',
'docs' => 'docs',
],
'paths' => [
'docs_json' => 'api-v2.json',
'docs' => 'docs/',
'docs_yaml' => 'docs.yaml',
],
'proxy' => true,
],
[
'api' => [
'title' => 'Api V2',
],
'routes' => [
'api' => 'api/documentation',
'docs' => 'docs',
],
'paths' => [
'docs_json' => 'api-v2.json',
'docs' => 'docs/',
'docs_yaml' => 'docs.yaml',
],
'proxy' => true,
],
];
yield [
[
[
'default' => 'v1',
'documentations' => [
'v1' => [
'api' => [
'title' => 'Api V1',
],
'routes' => [
'api' => 'api/v1',
],
'paths' => [
'docs_json' => 'api-v1.json',
],
'default' => 'v1',
'documentations' => [
'v1' => [
'api' => [
'title' => 'Api V1',
],
'routes' => [
'api' => 'api/v1',
],
'paths' => [
'docs_json' => 'api-v1.json',
],
],
],
[
'api' => [
'title' => 'Api V1',
],
'routes' => [
'api' => 'api/v1',
'docs' => 'docs',
],
'paths' => [
'docs_json' => 'api-v1.json',
'docs' => 'docs/',
'docs_yaml' => 'docs.yaml',
],
'proxy' => false,
],
[
'api' => [
'title' => 'Api V1',
],
'routes' => [
'api' => 'api/v1',
'docs' => 'docs',
],
'paths' => [
'docs_json' => 'api-v1.json',
'docs' => 'docs/',
'docs_yaml' => 'docs.yaml',
],
'proxy' => false,
],
];
}
Expand All @@ -133,13 +122,10 @@ public static function configDataProvider(): array
*
* Both arrays must have the same indexes with identical values
* without respect to key ordering
*
* @param array $expected
* @param array $array
*/
protected function assertArraySimilar(array $expected, array $array)
protected function assertArraySimilar(array $expected, array $array): void
{
$this->assertTrue(count(array_diff_key($array, $expected)) === 0);
$this->assertSame([], array_diff_key($array, $expected));

foreach ($expected as $key => $value) {
if (is_array($value)) {
Expand Down
22 changes: 6 additions & 16 deletions tests/ConsoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,18 @@
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Artisan;
use L5Swagger\Exceptions\L5SwaggerException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\TestDox;

/**
* @testdox Console commands
*/
#[TestDox('Console commands')]
class ConsoleTest extends TestCase
{
/**
* @test
*
* @dataProvider provideGenerateCommands
*
* @param string $artisanCommand
*
* @throws L5SwaggerException
* @throws FileNotFoundException
*/
public function canGenerate(string $artisanCommand): void
#[DataProvider('provideGenerateCommands')]
public function testCanGenerate(string $artisanCommand): void
{
$fileSystem = new Filesystem();

Expand All @@ -38,9 +33,6 @@ public function canGenerate(string $artisanCommand): void
$this->assertStringContainsString('L5 Swagger', $fileContent);
}

/**
* @return iterable
*/
public static function provideGenerateCommands(): iterable
{
yield 'default' => [
Expand All @@ -52,11 +44,9 @@ public static function provideGenerateCommands(): iterable
}

/**
* @test
*
* @throws L5SwaggerException
*/
public function canPublish(): void
public function testCanPublish(): void
{
$fileSystem = new Filesystem();
Artisan::call('vendor:publish', ['--provider' => 'L5Swagger\L5SwaggerServiceProvider']);
Expand Down
Loading
Loading