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

Use attributes in tests #618

Draft
wants to merge 31 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6ecf1e6
WIP
DarkaOnLine Mar 13, 2024
0090525
WIP
DarkaOnLine Mar 13, 2024
c0df379
WIP
DarkaOnLine Mar 13, 2024
a304935
WIP
DarkaOnLine Mar 13, 2024
1760bfe
Apply fixes from StyleCI
StyleCIBot Mar 13, 2024
f939553
WIP
DarkaOnLine Mar 13, 2024
8d51ba9
Apply fixes from StyleCI
StyleCIBot Mar 13, 2024
092feaa
Merge branch 'master' into use-attributes-in-tests
DarkaOnLine Aug 9, 2024
4fff6f2
WIP
DarkaOnLine Aug 9, 2024
4e0aa39
Apply fixes from StyleCI
StyleCIBot Aug 9, 2024
2371c75
drop php7.4 support
DarkaOnLine Aug 9, 2024
fea1216
merge master
DarkaOnLine Aug 9, 2024
f5eeae4
dependencies
DarkaOnLine Aug 9, 2024
33e73bf
dependencies
DarkaOnLine Aug 9, 2024
6c6b546
WIP
DarkaOnLine Aug 9, 2024
556f1a2
covers attributes
DarkaOnLine Aug 9, 2024
8a8dbba
Apply fixes from StyleCI
StyleCIBot Aug 9, 2024
d1e0b9b
ci
DarkaOnLine Aug 9, 2024
18b6ecf
Merge branch 'use-attributes-in-tests' of github.com:DarkaOnLine/L5-S…
DarkaOnLine Aug 9, 2024
064e674
wip
DarkaOnLine Aug 9, 2024
396d9d2
WIP
DarkaOnLine Aug 28, 2024
80c3f2f
Merge branch 'master' into use-attributes-in-tests
DarkaOnLine Aug 29, 2024
d9531ef
update tests
DarkaOnLine Aug 30, 2024
4cc0c79
update tests
DarkaOnLine Sep 3, 2024
84ca74a
Apply fixes from StyleCI
StyleCIBot Sep 3, 2024
3a06766
update tests
DarkaOnLine Sep 3, 2024
2de2e7d
update tests
DarkaOnLine Sep 3, 2024
7f7fe71
update tests
DarkaOnLine Sep 3, 2024
b95fb31
update tests
DarkaOnLine Sep 3, 2024
7314605
update tests
DarkaOnLine Sep 3, 2024
7018eaf
Apply fixes from StyleCI
StyleCIBot Sep 3, 2024
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
7 changes: 6 additions & 1 deletion .github/workflows/test-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [ '7.4', '8.0', '8.1', '8.2', '8.3' ]
php: [ '8.0', '8.1', '8.2', '8.3' ]
l5-swagger-flags: ['latest', 'swagger-php-3', 'swagger-ui-3']

name: PHP ${{ matrix.php }} - ${{ matrix.l5-swagger-flags }}
Expand Down Expand Up @@ -66,8 +66,13 @@ jobs:
./cc-test-reporter before-build
if: matrix.php == '8.3' && matrix.l5-swagger-flags == 'latest'

- name: Run PHP 8.0 test suite
run: vendor/bin/phpunit --testdox -c phpunit-php80.xml
if: matrix.php == '8.0'

- name: Run test suite
run: composer run-script phpunit
if: matrix.php != '8.0'

- name: Publish code coverage
env:
Expand Down
54 changes: 0 additions & 54 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
}
],
"require": {
"php": "^7.2 || ^8.0",
"laravel/framework": "^11.0 || ^10.0 || ^9.0 || >=8.40.0 || ^7.0",
"php": "^8.0",
"laravel/framework": "^11.0 || ^10.0 || ^9.0",
"zircote/swagger-php": "^3.2.0 || ^4.0.0",
"swagger-api/swagger-ui": "^3.0 || >=4.1.3",
"symfony/yaml": "^5.0 || ^6.0 || ^7.0",
Expand Down
29 changes: 29 additions & 0 deletions phpunit-php80.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
stopOnFailure="false"
verbose="true">
<testsuites>
<testsuite name="L5-Swagger TestSuite for php8.0">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<php>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
<env name="SWAGGER_VERSION" value="3.0"/>
</php>
</phpunit>
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@
<include>
<directory suffix=".php">src/</directory>
</include>
<exclude>
<file>src/routes.php</file>
</exclude>
</source>
</phpunit>
4 changes: 2 additions & 2 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
function swagger_ui_dist_path(string $documentation, $asset = null)
{
$allowed_files = [
$allowedFiles = [
'favicon-16x16.png',
'favicon-32x32.png',
'oauth2-redirect.html',
Expand All @@ -37,7 +37,7 @@ function swagger_ui_dist_path(string $documentation, $asset = null)
return realpath($path);
}

if (! in_array($asset, $allowed_files)) {
if (! in_array($asset, $allowedFiles, true)) {
throw new L5SwaggerException(sprintf('(%s) - this L5 Swagger asset is not allowed', $asset));
}

Expand Down
138 changes: 66 additions & 72 deletions tests/ConfigFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

namespace Tests;

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

/**
* @testdox Configuration factory
* @covers \L5Swagger\ConfigFactory
*/
#[TestDox('Configuration factory')]
#[CoversClass(ConfigFactory::class)]
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 +28,12 @@ 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 +57,70 @@ public function canMergeConfigurationDeep(array $data, array $assert): void
$this->assertArraySimilar($config, $assert);
}

public static function configDataProvider(): array
public static function configDataProvider(): \Iterator
{
return [
[
[
'default' => 'v2',
'documentations' => [
'v2' => [
'api' => [
'title' => 'Api V2',
],
'paths' => [
'docs_json' => 'api-v2.json',
],
'proxy' => true,
yield 'V1 configuration' => [
'data' => [
'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,
],
'assert' => [
'api' => [
'title' => 'Api V2',
],
'routes' => [
'api' => 'api/documentation',
'docs' => 'docs',
],
'paths' => [
'docs_json' => 'api-v2.json',
'docs' => 'docs/',
'docs_yaml' => 'docs.yaml',
],
'proxy' => true,
],
[
[
'default' => 'v1',
'documentations' => [
'v1' => [
'api' => [
'title' => 'Api V1',
],
'routes' => [
'api' => 'api/v1',
],
'paths' => [
'docs_json' => 'api-v1.json',
],
];
yield 'V2 configuration' => [
'data' => [
'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,
],
'assert' => [
'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 +130,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: 10 additions & 12 deletions tests/ConsoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Artisan;
use L5Swagger\Console\GenerateDocsCommand;
use L5Swagger\Exceptions\L5SwaggerException;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\TestDox;

/**
* @testdox Console commands
* @covers \L5Swagger\Console\GenerateDocsCommand
*/
#[TestDox('Console commands')]
#[CoversClass(GenerateDocsCommand::class)]
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 +41,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 +52,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