Apply fixes from StyleCI

This commit is contained in:
Marcel Pociot
2019-10-08 21:16:47 +00:00
committed by StyleCI Bot
parent 901f153ea3
commit 7d94de8b16
7 changed files with 62 additions and 58 deletions

View File

@@ -4,4 +4,6 @@ namespace Mpociot\ApiDoc\Tests\Fixtures;
use Illuminate\Database\Eloquent\Model;
class TestUser extends Model {}
class TestUser extends Model
{
}

View File

@@ -3,7 +3,6 @@
namespace Mpociot\ApiDoc\Tests\Fixtures;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Http\Resources\Json\ResourceCollection;
class TestUserApiResource extends JsonResource
{
@@ -11,13 +10,14 @@ class TestUserApiResource extends JsonResource
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->first_name." ".$this->last_name,
'name' => $this->first_name.' '.$this->last_name,
'email' => $this->email,
];
}

View File

@@ -10,6 +10,7 @@ class TestUserApiResourceCollection extends ResourceCollection
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function toArray($request)
@@ -22,4 +23,3 @@ class TestUserApiResourceCollection extends ResourceCollection
];
}
}

View File

@@ -2,13 +2,13 @@
namespace Mpociot\ApiDoc\Tests;
use Mpociot\ApiDoc\Tests\Fixtures\TestUser;
use ReflectionException;
use Illuminate\Support\Str;
use Mpociot\ApiDoc\Tools\Utils;
use Orchestra\Testbench\TestCase;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;
use Mpociot\ApiDoc\Tests\Fixtures\TestUser;
use Mpociot\ApiDoc\Tests\Fixtures\TestController;
use Mpociot\ApiDoc\ApiDocGeneratorServiceProvider;
use Illuminate\Support\Facades\Route as RouteFacade;
@@ -24,14 +24,13 @@ class GenerateDocumentationTest extends TestCase
{
parent::setUp();
$factory = app(\Illuminate\Database\Eloquent\Factory::class);
$factory->define(TestUser::class, function () {
return [
'id' => 4,
'first_name' => "Tested",
'last_name' => "Again",
'email' => "a@b.com",
'first_name' => 'Tested',
'last_name' => 'Again',
'email' => 'a@b.com',
];
});
}
@@ -232,7 +231,8 @@ class GenerateDocumentationTest extends TestCase
/** @test */
public function generated_postman_collection_file_is_correct()
{ RouteFacade::get('/api/withDescription', [TestController::class, 'withEndpointDescription']);
{
RouteFacade::get('/api/withDescription', [TestController::class, 'withEndpointDescription']);
RouteFacade::get('/api/withResponseTag', TestController::class.'@withResponseTag');
RouteFacade::get('/api/withBodyParameters', TestController::class.'@withBodyParameters');
RouteFacade::get('/api/withQueryParameters', TestController::class.'@withQueryParameters');

View File

@@ -5,9 +5,9 @@
namespace Mpociot\ApiDoc\Tests\Unit;
use Illuminate\Support\Arr;
use Mpociot\ApiDoc\Tests\Fixtures\TestUser;
use Orchestra\Testbench\TestCase;
use Mpociot\ApiDoc\Tools\Generator;
use Mpociot\ApiDoc\Tests\Fixtures\TestUser;
use Mpociot\ApiDoc\Tools\DocumentationConfig;
use Mpociot\ApiDoc\Tests\Fixtures\TestController;
use Mpociot\ApiDoc\ApiDocGeneratorServiceProvider;
@@ -60,9 +60,9 @@ abstract class GeneratorTestCase extends TestCase
$factory->define(TestUser::class, function () {
return [
'id' => 4,
'first_name' => "Tested",
'last_name' => "Again",
'email' => "a@b.com",
'first_name' => 'Tested',
'last_name' => 'Again',
'email' => 'a@b.com',
];
});
$this->generator = new Generator(new DocumentationConfig($this->config));
@@ -395,7 +395,7 @@ abstract class GeneratorTestCase extends TestCase
$route = $this->createRoute('POST', '/withEloquentApiResource', 'withEloquentApiResource');
$config = $this->config;
$config['strategies']['responses'] = [\Mpociot\ApiDoc\Strategies\Responses\UseApiResourceTags::class,];
$config['strategies']['responses'] = [\Mpociot\ApiDoc\Strategies\Responses\UseApiResourceTags::class];
$generator = new Generator(new DocumentationConfig($config));
$parsed = $this->generator->processRoute($route);
@@ -407,8 +407,8 @@ abstract class GeneratorTestCase extends TestCase
$this->assertEquals(200, $response['status']);
$this->assertArraySubset([
'id' => 4,
'name' => "Tested Again",
'email' => "a@b.com",
'name' => 'Tested Again',
'email' => 'a@b.com',
], json_decode($response['content'], true));
}
@@ -418,7 +418,7 @@ abstract class GeneratorTestCase extends TestCase
$route = $this->createRoute('POST', '/withEloquentApiResourceCollection', 'withEloquentApiResourceCollection');
$config = $this->config;
$config['strategies']['responses'] = [\Mpociot\ApiDoc\Strategies\Responses\UseApiResourceTags::class,];
$config['strategies']['responses'] = [\Mpociot\ApiDoc\Strategies\Responses\UseApiResourceTags::class];
$generator = new Generator(new DocumentationConfig($config));
$parsed = $this->generator->processRoute($route);
@@ -432,13 +432,13 @@ abstract class GeneratorTestCase extends TestCase
$this->assertIsArray($content);
$this->assertArraySubset([
'id' => 4,
'name' => "Tested Again",
'email' => "a@b.com",
'name' => 'Tested Again',
'email' => 'a@b.com',
], $content[0]);
$this->assertArraySubset([
'id' => 4,
'name' => "Tested Again",
'email' => "a@b.com",
'name' => 'Tested Again',
'email' => 'a@b.com',
], $content[1]);
}
@@ -448,7 +448,7 @@ abstract class GeneratorTestCase extends TestCase
$route = $this->createRoute('POST', '/withEloquentApiResourceCollectionClass', 'withEloquentApiResourceCollectionClass');
$config = $this->config;
$config['strategies']['responses'] = [\Mpociot\ApiDoc\Strategies\Responses\UseApiResourceTags::class,];
$config['strategies']['responses'] = [\Mpociot\ApiDoc\Strategies\Responses\UseApiResourceTags::class];
$generator = new Generator(new DocumentationConfig($config));
$parsed = $this->generator->processRoute($route);
@@ -461,20 +461,20 @@ abstract class GeneratorTestCase extends TestCase
$content = json_decode($response['content'], true);
$this->assertIsArray($content);
$this->assertArraySubset([
"data" => [
'data' => [
[
'id' => 4,
'name' => "Tested Again",
'email' => "a@b.com",
'name' => 'Tested Again',
'email' => 'a@b.com',
],
[
'id' => 4,
'name' => "Tested Again",
'email' => "a@b.com",
'name' => 'Tested Again',
'email' => 'a@b.com',
],
],
"links" => [
"self" => "link-value",
'links' => [
'self' => 'link-value',
],
], $content);
}
@@ -617,7 +617,7 @@ abstract class GeneratorTestCase extends TestCase
$this->assertEquals(200, $response['status']);
$this->assertSame(
$response['content'],
'{"data":[{"id":1,"description":"Welcome on this test versions","name":"TestName"},' .
'{"data":[{"id":1,"description":"Welcome on this test versions","name":"TestName"},'.
'{"id":1,"description":"Welcome on this test versions","name":"TestName"}]}'
);
}
@@ -636,7 +636,7 @@ abstract class GeneratorTestCase extends TestCase
$this->assertEquals(200, $response['status']);
$this->assertSame(
$response['content'],
'{"data":[{"id":1,"description":"Welcome on this test versions","name":"TestName"},' .
'{"data":[{"id":1,"description":"Welcome on this test versions","name":"TestName"},'.
'{"id":1,"description":"Welcome on this test versions","name":"TestName"}]}'
);
}
@@ -738,7 +738,7 @@ abstract class GeneratorTestCase extends TestCase
public function can_parse_response_file_tag()
{
// copy file to storage
$filePath = __DIR__ . '/../Fixtures/response_test.json';
$filePath = __DIR__.'/../Fixtures/response_test.json';
$fixtureFileJson = file_get_contents($filePath);
copy($filePath, storage_path('response_test.json'));
@@ -763,7 +763,7 @@ abstract class GeneratorTestCase extends TestCase
public function can_add_or_replace_key_value_pair_in_response_file()
{
// copy file to storage
$filePath = __DIR__ . '/../Fixtures/response_test.json';
$filePath = __DIR__.'/../Fixtures/response_test.json';
$fixtureFileJson = file_get_contents($filePath);
copy($filePath, storage_path('response_test.json'));
@@ -788,10 +788,10 @@ abstract class GeneratorTestCase extends TestCase
public function can_parse_multiple_response_file_tags_with_status_codes()
{
// copy file to storage
$successFilePath = __DIR__ . '/../Fixtures/response_test.json';
$successFilePath = __DIR__.'/../Fixtures/response_test.json';
$successFixtureFileJson = file_get_contents($successFilePath);
copy($successFilePath, storage_path('response_test.json'));
$errorFilePath = __DIR__ . '/../Fixtures/response_error_test.json';
$errorFilePath = __DIR__.'/../Fixtures/response_error_test.json';
$errorFixtureFileJson = file_get_contents($errorFilePath);
copy($errorFilePath, storage_path('response_error_test.json'));