Skip to content

Commit cc612e0

Browse files
author
u.aleroev
committed
feat: add tests for middleware
1 parent 53e9e1c commit cc612e0

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
"YSRoot\\SwaggerUI\\": "src/"
3737
}
3838
},
39+
"autoload-dev": {
40+
"psr-4": {
41+
"YSRoot\\SwaggerUI\\Tests\\": "tests"
42+
}
43+
},
3944
"minimum-stability": "dev",
4045
"prefer-stable": true
4146
}

phpunit.xml.dist

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
>
12+
<testsuites>
13+
<testsuite name="Unit">
14+
<directory suffix=".php">./tests/Unit</directory>
15+
</testsuite>
16+
</testsuites>
17+
18+
<php>
19+
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
20+
</php>
21+
</phpunit>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace YSRoot\SwaggerUI\Tests\Unit\Http\Middleware;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Http\Response;
7+
use Orchestra\Testbench\TestCase;
8+
use YSRoot\SwaggerUI\Http\Middleware\EnsureIsAuthorized;
9+
10+
class EnsureIsAuthorizedTest extends TestCase
11+
{
12+
public function testLocalEnvMiddlewarePassed(): void
13+
{
14+
$this->app->detectEnvironment(fn() => 'local');
15+
$request = Request::create('not-important');
16+
$expectedResult = new Response(['expected' => 'expected']);
17+
$callback = fn () => $expectedResult;
18+
19+
$result = (new EnsureIsAuthorized())->handle($request, $callback);
20+
21+
$this->assertEquals($expectedResult->content(), $result->content());
22+
}
23+
}

0 commit comments

Comments
 (0)