-
Notifications
You must be signed in to change notification settings - Fork 109
Add: generate servers.description & servers.variables #44
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
Merged
vyuldashev
merged 5 commits into
vyuldashev:master
from
sun-yryr:feature/generate-server
May 7, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1855fb2
add: generate server.description & server.variables
sun-yryr cb474fa
add: test for ServerBuilder
sun-yryr 7ba9fd7
update: config for servers
sun-yryr a15a2de
fix: styleci
sun-yryr 8332df0
refactor: rename variable & delete dev log
sun-yryr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
'servers' => [ | ||
[ | ||
'url' => env('APP_URL'), | ||
'description' => null, | ||
'variables' => [], | ||
], | ||
], | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vyuldashev\LaravelOpenApi\Tests\Builders; | ||
|
||
use Vyuldashev\LaravelOpenApi\Builders\ServersBuilder; | ||
use Vyuldashev\LaravelOpenApi\Tests\TestCase; | ||
|
||
class ServersBuilderTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider providerBuild | ||
* @param array $config | ||
* @param array $expected | ||
* @return void | ||
*/ | ||
public function testBuild(array $config, array $expected): void | ||
{ | ||
$SUT = new ServersBuilder(); | ||
$servers = $SUT->build($config); | ||
$this->assertSameAssociativeArray($expected[0], $servers[0]->toArray()); | ||
} | ||
|
||
public function providerBuild(): array | ||
{ | ||
return [ | ||
'If the variables field does not exist, it is possible to output the correct json.' => [ | ||
[[ | ||
'url' => 'http://example.com', | ||
'description' => 'sample_description', | ||
'variables' => [], | ||
]], | ||
[[ | ||
'url' => 'http://example.com', | ||
'description' => 'sample_description', | ||
]], | ||
], | ||
'If the variables field is present, it can output the correct json.' => [ | ||
[[ | ||
'url' => 'http://example.com', | ||
'description' => 'sample_description', | ||
'variables' => [ | ||
'variable_name' => [ | ||
'default' => 'variable_defalut', | ||
'description' => 'variable_description', | ||
], | ||
], | ||
]], | ||
[[ | ||
'url' => 'http://example.com', | ||
'description' => 'sample_description', | ||
'variables' => [ | ||
'variable_name' => [ | ||
'default' => 'variable_defalut', | ||
'description' => 'variable_description', | ||
], | ||
], | ||
]], | ||
], | ||
'If there is a variables field containing enum, it can output the correct json.' => [ | ||
[[ | ||
'url' => 'http://example.com', | ||
'description' => 'sample_description', | ||
'variables' => [ | ||
'variable_name' => [ | ||
'default' => 'variable_defalut', | ||
'description' => 'variable_description', | ||
'enum' => [ | ||
'A', | ||
'B', | ||
'C', | ||
], | ||
], | ||
], | ||
]], | ||
[[ | ||
'url' => 'http://example.com', | ||
'description' => 'sample_description', | ||
'variables' => [ | ||
'variable_name' => [ | ||
'default' => 'variable_defalut', | ||
'description' => 'variable_description', | ||
'enum' => [ | ||
'A', | ||
'B', | ||
'C', | ||
], | ||
], | ||
], | ||
]], | ||
], | ||
'If there are variables fields in multiple formats, it is possible to output the correct json.' => [ | ||
[[ | ||
'url' => 'http://example.com', | ||
'description' => 'sample_description', | ||
'variables' => [ | ||
'variable_name' => [ | ||
'default' => 'variable_defalut', | ||
'description' => 'variable_description', | ||
'enum' => ['A', 'B'], | ||
], | ||
'variable_name_B' => [ | ||
'default' => 'sample', | ||
'description' => 'sample', | ||
], | ||
], | ||
]], | ||
[[ | ||
'url' => 'http://example.com', | ||
'description' => 'sample_description', | ||
'variables' => [ | ||
'variable_name' => [ | ||
'default' => 'variable_defalut', | ||
'description' => 'variable_description', | ||
'enum' => ['A', 'B'], | ||
], | ||
'variable_name_B' => [ | ||
'default' => 'sample', | ||
'description' => 'sample', | ||
], | ||
], | ||
]], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Assert equality as an associative array. | ||
* | ||
* @param array $expected | ||
* @param array $actual | ||
* @return void | ||
*/ | ||
protected function assertSameAssociativeArray(array $expected, array $actual): void | ||
{ | ||
foreach ($expected as $key => $value) { | ||
if (is_array($value)) { | ||
$this->assertSameAssociativeArray($value, $actual[$key]); | ||
unset($actual[$key]); | ||
continue; | ||
} | ||
self::assertSame($value, $actual[$key]); | ||
unset($actual[$key]); | ||
} | ||
self::assertCount(0, $actual, sprintf('[%s] does not matched keys.', join(', ', array_keys($actual)))); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.