diff --git a/.gitignore b/.gitignore index 7de504d..223d94d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ npm-debug.log yarn-error.log .env composer.lock -.php_cs.cache \ No newline at end of file +.php_cs.cache +.phpunit.result.cache diff --git a/.travis.yml b/.travis.yml index 47976a1..568eda1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,23 +2,21 @@ language: php matrix: include: - - php: "7.1" - env: LARAVEL_VERSION="5.5.*" - php: "7.2" - env: LARAVEL_VERSION="5.5.*" - - php: "7.2" - env: LARAVEL_VERSION="5.6.*" - - php: "7.2" - env: LARAVEL_VERSION="5.7.*" - - php: "7.2" - env: LARAVEL_VERSION="5.8.*" + env: LARAVEL_VERSION="7.0.*" + - php: "7.3" + env: LARAVEL_VERSION="7.0.*" + - php: "7.4" + env: LARAVEL_VERSION="7.0.*" - php: "7.3" - env: LARAVEL_VERSION="5.8.*" RUN_CS_FIXER=1 + env: LARAVEL_VERSION="8.0.*" + - php: "7.4" + env: LARAVEL_VERSION="8.0.*" $RUN_CS_FIXER=1 sudo: false install: - - composer require "illuminate/support:${LARAVEL_VERSION}" --no-update --no-interaction + - composer require "laravel/framework:${LARAVEL_VERSION}" --no-update --no-interaction - travis_retry composer install --no-interaction --prefer-dist script: diff --git a/README.md b/README.md index 91deb3e..be6e4dd 100644 --- a/README.md +++ b/README.md @@ -236,8 +236,8 @@ If you created your own routes make sure you have the ``auth:api`` middlware on ##### Laravel framework * https://laravel.com/docs/ -##### Dimsav / laravel-translatable -* https://github.com/dimsav/laravel-translatable +##### Astrotomic / laravel-translatable +* https://github.com/Astrotomic/laravel-translatable ## Change log diff --git a/composer.json b/composer.json index 31d51be..d60630f 100644 --- a/composer.json +++ b/composer.json @@ -38,19 +38,20 @@ } ], "require": { - "php": ">=7.1.3", - "dimsav/laravel-translatable": "^8.0|^9.0", - "laravel/framework": "5.5.*|5.6.*|5.7.*|5.8.*" + "php": ">=7.2", + "ext-json": "*", + "astrotomic/laravel-translatable": "^11.6", + "laravel/framework": "^7.0|^8.0" }, "require-dev": { "filp/whoops": "~2.0", - "friendsofphp/php-cs-fixer": "^2.4", + "friendsofphp/php-cs-fixer": "^2.16", "mockery/mockery": "^1.0", - "graham-campbell/testbench": "^4.0|^5.1", - "phpunit/php-code-coverage": "^5.3|^6.0", - "phpunit/phpunit": "^7.0|^6.1", + "orchestra/testbench": "^5.0|^6.0", + "phpunit/php-code-coverage": "^7.0", + "phpunit/phpunit": "^8.0", "spatie/phpunit-watcher": "^1.3", - "squizlabs/php_codesniffer": "^2.3" + "squizlabs/php_codesniffer": "^3.5" }, "autoload": { "psr-4": { diff --git a/resources/templates/model.stub b/resources/templates/model.stub index 1192cd5..51b021c 100644 --- a/resources/templates/model.stub +++ b/resources/templates/model.stub @@ -3,7 +3,7 @@ namespace $NAMESPACE_MODEL$; use Illuminate\Database\Eloquent\Model; -use Dimsav\Translatable\Translatable; +use Astrotomic\Translatable\Translatable; class $MODEL_NAME$ extends Model { diff --git a/sample/Http/SampleController.php b/sample/Http/SampleController.php index 244c9f1..0894853 100644 --- a/sample/Http/SampleController.php +++ b/sample/Http/SampleController.php @@ -9,7 +9,7 @@ class SampleController extends BaseApiController { - /** @var RepositoryInterface $repository */ + /** @var RepositoryInterface */ protected $repository; public function __construct(SampleRepository $repository, Request $request) diff --git a/sample/Sample.php b/sample/Sample.php index 1756d6c..24ecf55 100644 --- a/sample/Sample.php +++ b/sample/Sample.php @@ -2,7 +2,7 @@ namespace App; -use Dimsav\Translatable\Translatable; +use Astrotomic\Translatable\Translatable; use Illuminate\Database\Eloquent\Model; class Sample extends Model diff --git a/sample/Tests/SampleAuthenticationTest.php b/sample/Tests/SampleAuthenticationTest.php index 6e9beb0..5b67cfa 100644 --- a/sample/Tests/SampleAuthenticationTest.php +++ b/sample/Tests/SampleAuthenticationTest.php @@ -30,14 +30,14 @@ public function setUp() } /** @test */ - public function it_creates_an_sample_unauthenticated() + public function itCreatesAnSampleUnauthenticated() { $response = $this->post($this->baseUrl); $response->assertStatus(401); } /** @test */ - public function it_creates_an_sample_authenticated() + public function itCreatesAnSampleAuthenticated() { Passport::actingAs($this->user); @@ -46,7 +46,7 @@ public function it_creates_an_sample_authenticated() } /** @test */ - public function it_updates_an_sample_unauthenticated() + public function itUpdatesAnSampleUnauthenticated() { $sample = factory(Sample::class)->create(); @@ -55,7 +55,7 @@ public function it_updates_an_sample_unauthenticated() } /** @test */ - public function it_updates_an_sample_authenticated() + public function itUpdatesAnSampleAuthenticated() { Passport::actingAs($this->user); @@ -67,7 +67,7 @@ public function it_updates_an_sample_authenticated() } /** @test */ - public function it_retrieves_an_sample_unauthenticated() + public function itRetrievesAnSampleUnauthenticated() { $sample = factory(Sample::class)->create(); @@ -76,7 +76,7 @@ public function it_retrieves_an_sample_unauthenticated() } /** @test */ - public function it_retrieves_an_sample_authenticated() + public function itRetrievesAnSampleAuthenticated() { Passport::actingAs($this->user); @@ -87,7 +87,7 @@ public function it_retrieves_an_sample_authenticated() } /** @test */ - public function it_retrieves_all_samples_unauthenticated() + public function itRetrievesAllSamplesUnauthenticated() { factory(Sample::class, 3)->create(); @@ -96,7 +96,7 @@ public function it_retrieves_all_samples_unauthenticated() } /** @test */ - public function it_retrieves_all_samples_authenticated() + public function itRetrievesAllSamplesAuthenticated() { Passport::actingAs($this->user); @@ -107,7 +107,7 @@ public function it_retrieves_all_samples_authenticated() } /** @test */ - public function it_deletes_an_sample_unauthenticated() + public function itDeletesAnSampleUnauthenticated() { $sample = factory(Sample::class)->create(); @@ -116,7 +116,7 @@ public function it_deletes_an_sample_unauthenticated() } /** @test */ - public function it_deletes_an_sample_authenticated() + public function itDeletesAnSampleAuthenticated() { Passport::actingAs($this->user); diff --git a/src/Http/Controllers/Api/BaseApiController.php b/src/Http/Controllers/Api/BaseApiController.php index 8ff8760..f218126 100644 --- a/src/Http/Controllers/Api/BaseApiController.php +++ b/src/Http/Controllers/Api/BaseApiController.php @@ -16,7 +16,10 @@ abstract class BaseApiController extends Controller { - use DispatchesJobs, ValidatesRequests, HandleResponses, AuthorizesRequests; + use AuthorizesRequests; + use DispatchesJobs; + use HandleResponses; + use ValidatesRequests; protected $respondController; protected $repository; diff --git a/src/Http/Middleware/ConfigureLocale.php b/src/Http/Middleware/ConfigureLocale.php index 16ea77c..2659225 100644 --- a/src/Http/Middleware/ConfigureLocale.php +++ b/src/Http/Middleware/ConfigureLocale.php @@ -10,7 +10,6 @@ class ConfigureLocale * Handle an incoming request. * * @param \Illuminate\Http\Request $request - * @param \Closure $next * * @return mixed */ diff --git a/src/Http/Middleware/InspectContentType.php b/src/Http/Middleware/InspectContentType.php index c7977a6..53c20e1 100644 --- a/src/Http/Middleware/InspectContentType.php +++ b/src/Http/Middleware/InspectContentType.php @@ -9,9 +9,6 @@ class InspectContentType { /** - * @param Request $request - * @param Closure $next - * * @throws ContentTypeNotSupportedException * * @return mixed diff --git a/src/Http/Resources/BaseApiCollectionResource.php b/src/Http/Resources/BaseApiCollectionResource.php index 6bdff3f..a505bb6 100644 --- a/src/Http/Resources/BaseApiCollectionResource.php +++ b/src/Http/Resources/BaseApiCollectionResource.php @@ -32,7 +32,7 @@ public function toArray($request) protected function getIncludedRelationships($items, Request $request) { $includes = explode(',', $request->get('include', null)); - if ($includes === []) { + if ([] === $includes) { return []; } $relations = $this->includeCollectionRelationships($items, $includes); diff --git a/src/Http/Resources/BaseApiResource.php b/src/Http/Resources/BaseApiResource.php index 86f1422..e78907b 100644 --- a/src/Http/Resources/BaseApiResource.php +++ b/src/Http/Resources/BaseApiResource.php @@ -4,11 +4,12 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; -use Illuminate\Http\Resources\Json\Resource; +use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Support\Collection; +use Illuminate\Support\Str; use Swis\JsonApi\Server\Traits\HandlesRelationships; -class BaseApiResource extends Resource +class BaseApiResource extends JsonResource { use HandlesRelationships; @@ -43,7 +44,7 @@ public function setValues() if (!$this->resource) { return; } - $this->resource->addHidden($this->resource->getKeyName()); + $this->resource->makeHidden($this->resource->getKeyName()); $this->jsonApiModel->setId((string) $this->resource->getKey()); $this->jsonApiModel->setType($this->getResourceType()); @@ -193,7 +194,7 @@ protected function getRelationshipData($data) } } - if ($relationshipData->toArray(true) == []) { + if ([] == $relationshipData->toArray(true)) { $relationshipData = []; } } elseif ($data instanceof Model) { @@ -236,7 +237,7 @@ protected function getIncludedRelationships(Request $request) protected function getResourceType() { $resourceClass = class_basename($this->resource); - $resourcePlural = str_plural($resourceClass); + $resourcePlural = Str::plural($resourceClass); // Converts camelcase to dash $lowerCaseResourceType = strtolower(preg_replace('/([a-zA-Z])(?=[A-Z])/', '$1-', $resourcePlural)); diff --git a/src/Http/Resources/IdentifierResource.php b/src/Http/Resources/IdentifierResource.php index 55a53aa..4ea8344 100644 --- a/src/Http/Resources/IdentifierResource.php +++ b/src/Http/Resources/IdentifierResource.php @@ -2,9 +2,10 @@ namespace Swis\JsonApi\Server\Http\Resources; -use Illuminate\Http\Resources\Json\Resource; +use Illuminate\Http\Resources\Json\JsonResource; +use Illuminate\Support\Str; -class IdentifierResource extends Resource +class IdentifierResource extends JsonResource { /** * Transform the resource into an array. @@ -24,7 +25,7 @@ public function toArray($request) protected function getResourceType() { $resourceClass = class_basename($this->resource); - $resourcePlural = str_plural($resourceClass); + $resourcePlural = Str::plural($resourceClass); // Converts camelcase to dash $lowerCaseResourceType = strtolower(preg_replace('/([a-zA-Z])(?=[A-Z])/', '$1-', $resourcePlural)); diff --git a/src/Providers/LaravelApiServiceProvider.php b/src/Providers/LaravelApiServiceProvider.php index 86f7b1b..f1e1378 100644 --- a/src/Providers/LaravelApiServiceProvider.php +++ b/src/Providers/LaravelApiServiceProvider.php @@ -2,7 +2,7 @@ namespace Swis\JsonApi\Server\Providers; -use Dimsav\Translatable\TranslatableServiceProvider; +use Astrotomic\Translatable\TranslatableServiceProvider; use Illuminate\Routing\Router; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Route; diff --git a/src/Repositories/BaseApiRepository.php b/src/Repositories/BaseApiRepository.php index 8d27601..7e4ae50 100644 --- a/src/Repositories/BaseApiRepository.php +++ b/src/Repositories/BaseApiRepository.php @@ -17,7 +17,7 @@ abstract class BaseApiRepository implements RepositoryInterface const PAGE = 1; const PER_PAGE = 15; - /** @var Model $model */ + /** @var Model */ protected $model; protected $user; @@ -25,7 +25,7 @@ abstract class BaseApiRepository implements RepositoryInterface protected $perPage = self::PER_PAGE; protected $parameters; - /** @var Builder $query */ + /** @var Builder */ protected $query; protected $columns = ['*']; @@ -88,7 +88,6 @@ public function create(array $data) } /** - * @param array $data * @param $objectKey * * @throws NotFoundException diff --git a/src/Services/CustomFileGenerator.php b/src/Services/CustomFileGenerator.php index 8d1e39a..bfc726c 100644 --- a/src/Services/CustomFileGenerator.php +++ b/src/Services/CustomFileGenerator.php @@ -2,6 +2,8 @@ namespace Swis\JsonApi\Server\Services; +use Illuminate\Support\Str; + class CustomFileGenerator { private $modelName; @@ -11,11 +13,11 @@ protected function setStubVars() { $this->stubVariables = [ '$MODEL_NAME$' => $this->modelName, - '$CAMEL_CASE_MODEL_NAME$' => camel_case($this->modelName), - '$SNAKE_CASED_MODEL_NAME$' => strtolower(snake_case($this->modelName)), - '$PLURAL_SNAKE_CASED_MODEL_NAME$' => strtolower(str_plural(snake_case($this->modelName))), - '$PLURAL_UPPER_CASED_MODEL_NAME$' => strtoupper(str_plural($this->modelName)), - '$PLURAL_LOWER_CASED_MODEL_NAME$' => strtolower(str_plural($this->modelName)), + '$CAMEL_CASE_MODEL_NAME$' => Str::camel($this->modelName), + '$SNAKE_CASED_MODEL_NAME$' => strtolower(Str::snake($this->modelName)), + '$PLURAL_SNAKE_CASED_MODEL_NAME$' => strtolower(Str::plural(Str::snake($this->modelName))), + '$PLURAL_UPPER_CASED_MODEL_NAME$' => strtoupper(Str::plural($this->modelName)), + '$PLURAL_LOWER_CASED_MODEL_NAME$' => strtolower(Str::plural($this->modelName)), '$UPPER_CASED_MODEL_NAME$' => strtoupper($this->modelName), '$NAMESPACE_MODEL$' => config('laravel_api.namespace.model'), '$NAME_SPACE_REPOSITORY$' => config('laravel_api.namespace.repository'), diff --git a/src/Traits/HandlesRelationships.php b/src/Traits/HandlesRelationships.php index a059c3d..15dcb60 100644 --- a/src/Traits/HandlesRelationships.php +++ b/src/Traits/HandlesRelationships.php @@ -15,6 +15,7 @@ use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Database\Eloquent\Relations\MorphToMany; use Illuminate\Http\Resources\Json\ResourceCollection; +use Illuminate\Support\Str; use Swis\JsonApi\Server\Http\Resources\BaseApiResource; trait HandlesRelationships @@ -72,8 +73,8 @@ public function includeCollectionRelationships($items, $includes) * Loops through all included tags. It checks for each include if there is a nested include. * And also runs that recursively through includeCollectionRelationships. * - * @param $item - * @param $includes + * @param mixed $item + * @param mixed $includes * * @return array */ @@ -90,7 +91,7 @@ protected function handleIncludes($item, $includes) } } else { $included = BaseApiResource::make($item->$include); - $object = str_before($nestedInclude, '.'); + $object = Str::before($nestedInclude, '.'); if (isset($included->$object)) { $relationshipResources[] = $this->handleIncludes($included, [$nestedInclude]); } @@ -151,15 +152,13 @@ protected function removeDuplicates($items) /** * @param $include - * - * @return array */ protected function getNestedRelation($include): array { $nestedInclude = null; - if (str_contains($include, '.')) { - $nestedInclude = str_after($include, '.'); - $include = str_before($include, '.'); + if (Str::contains($include, '.')) { + $nestedInclude = Str::after($include, '.'); + $include = Str::before($include, '.'); } return [$nestedInclude, $include]; diff --git a/tests/TestClasses/TestController.php b/tests/TestClasses/TestController.php index de589da..143b15a 100644 --- a/tests/TestClasses/TestController.php +++ b/tests/TestClasses/TestController.php @@ -14,7 +14,7 @@ class TestController extends BaseApiController { - /** @var RepositoryInterface $repository */ + /** @var RepositoryInterface */ protected $repository; public function __construct(TestRepository $repository, Request $request) diff --git a/tests/Unit/Commands/GenerateAllCommandTest.php b/tests/Unit/Commands/GenerateAllCommandTest.php index 0eeff07..0b23762 100644 --- a/tests/Unit/Commands/GenerateAllCommandTest.php +++ b/tests/Unit/Commands/GenerateAllCommandTest.php @@ -13,7 +13,7 @@ class GenerateAllCommandTest extends CommandTestCase { /** @test */ - public function it_generates_all_files() + public function itGeneratesAllFiles() { $this->artisan('json-api-server:generate-all', ['name' => 'Example', '--path' => 'tests/Data/Output/']); $this->assertTrue(file_exists(config('laravel_api.path.repository').'ExampleRepository.php')); @@ -27,7 +27,7 @@ public function it_generates_all_files() } /** @test */ - public function it_generates_all_files_except_translation() + public function itGeneratesAllFilesExceptTranslation() { $this->artisan('json-api-server:generate-all', ['name' => 'Example', '--path' => 'tests/Data/Output/', '--skip' => 'translation']); $this->assertTrue(file_exists(config('laravel_api.path.repository').'ExampleRepository.php')); diff --git a/tests/Unit/Commands/GenerateApiControllerCommandTest.php b/tests/Unit/Commands/GenerateApiControllerCommandTest.php index 010aba7..0da40c6 100644 --- a/tests/Unit/Commands/GenerateApiControllerCommandTest.php +++ b/tests/Unit/Commands/GenerateApiControllerCommandTest.php @@ -13,7 +13,7 @@ class GenerateApiControllerCommandTest extends CommandTestCase { /** @test */ - public function it_generates_an_api_controller() + public function itGeneratesAnApiController() { $this->artisan('json-api-server:generate-controller', ['name' => 'Example', '--path' => 'tests/Data/Output/']); $this->assertTrue(file_exists(config('laravel_api.path.controller').'ExampleController.php')); @@ -21,7 +21,7 @@ public function it_generates_an_api_controller() } /** @test */ - public function it_generates_an_api_controller_without_override() + public function itGeneratesAnApiControllerWithoutOverride() { $this->artisan('json-api-server:generate-controller', ['name' => 'Example']); $this->assertTrue(file_exists(config('laravel_api.path.controller').'ExampleController.php')); diff --git a/tests/Unit/Commands/GenerateAuthenticationTestCommandTest.php b/tests/Unit/Commands/GenerateAuthenticationTestCommandTest.php index ab6b181..562cc98 100644 --- a/tests/Unit/Commands/GenerateAuthenticationTestCommandTest.php +++ b/tests/Unit/Commands/GenerateAuthenticationTestCommandTest.php @@ -13,7 +13,7 @@ class GenerateAuthenticationTestCommandTest extends CommandTestCase { /** @test */ - public function it_generates_an_authentication_test() + public function itGeneratesAnAuthenticationTest() { $this->artisan('json-api-server:generate-test', ['name' => 'Example', '--path' => 'tests/Data/Output/']); $this->assertTrue(file_exists(config('laravel_api.path.auth_test').'ExampleAuthenticationTest.php')); diff --git a/tests/Unit/Commands/GenerateModelCommandTest.php b/tests/Unit/Commands/GenerateModelCommandTest.php index 8ed85bc..eef8fd3 100644 --- a/tests/Unit/Commands/GenerateModelCommandTest.php +++ b/tests/Unit/Commands/GenerateModelCommandTest.php @@ -13,7 +13,7 @@ class GenerateModelCommandTest extends CommandTestCase { /** @test */ - public function it_generates_a_model() + public function itGeneratesAModel() { $this->artisan('json-api-server:generate-model', ['name' => 'Example', '--path' => 'tests/Data/Output/']); $this->assertTrue(file_exists(config('laravel_api.path.model').'Example.php')); diff --git a/tests/Unit/Commands/GenerateModelPermissionsCommandTest.php b/tests/Unit/Commands/GenerateModelPermissionsCommandTest.php index b34e113..bf1079d 100644 --- a/tests/Unit/Commands/GenerateModelPermissionsCommandTest.php +++ b/tests/Unit/Commands/GenerateModelPermissionsCommandTest.php @@ -13,7 +13,7 @@ class GenerateModelPermissionsCommandTest extends CommandTestCase { /** @test */ - public function it_generates_a_model_permissions() + public function itGeneratesAModelPermissions() { $this->artisan('json-api-server:generate-model-permissions', ['name' => 'Example', '--path' => 'tests/Data/Output/']); $this->assertTrue(file_exists(config('laravel_api.path.model_permissions').'ExamplePermissions.php')); diff --git a/tests/Unit/Commands/GeneratePolicyCommandTest.php b/tests/Unit/Commands/GeneratePolicyCommandTest.php index a5a93d6..bfa93d1 100644 --- a/tests/Unit/Commands/GeneratePolicyCommandTest.php +++ b/tests/Unit/Commands/GeneratePolicyCommandTest.php @@ -13,7 +13,7 @@ class GeneratePolicyCommandTest extends CommandTestCase { /** @test */ - public function it_generates_a_policy() + public function itGeneratesAPolicy() { $this->artisan('json-api-server:generate-policy', ['name' => 'Example', '--path' => 'tests/Data/Output/']); $this->assertTrue(file_exists(config('laravel_api.path.policy').'ExamplePolicy.php')); diff --git a/tests/Unit/Commands/GenerateRepositoryCommandTest.php b/tests/Unit/Commands/GenerateRepositoryCommandTest.php index ad059cf..988d213 100644 --- a/tests/Unit/Commands/GenerateRepositoryCommandTest.php +++ b/tests/Unit/Commands/GenerateRepositoryCommandTest.php @@ -13,7 +13,7 @@ class GenerateRepositoryCommandTest extends CommandTestCase { /** @test */ - public function it_generates_a_repository() + public function itGeneratesARepository() { $this->artisan('json-api-server:generate-repository', ['name' => 'Example', '--path' => 'tests/Data/Output/']); $this->assertTrue(file_exists(config('laravel_api.path.repository').'ExampleRepository.php')); diff --git a/tests/Unit/Commands/GenerateRoutesCommandTest.php b/tests/Unit/Commands/GenerateRoutesCommandTest.php index bb62fef..73494e7 100644 --- a/tests/Unit/Commands/GenerateRoutesCommandTest.php +++ b/tests/Unit/Commands/GenerateRoutesCommandTest.php @@ -13,7 +13,7 @@ class GenerateRoutesCommandTest extends CommandTestCase { /** @test */ - public function it_generates_routes() + public function itGeneratesRoutes() { $this->artisan('json-api-server:generate-routes', ['name' => 'Example', '--path' => 'tests/Data/Output/']); $this->assertTrue(file_exists(config('laravel_api.path.routes').'ExampleRoutes.php')); diff --git a/tests/Unit/Commands/GenerateTranslationCommandTest.php b/tests/Unit/Commands/GenerateTranslationCommandTest.php index 5ec81d2..46955a9 100644 --- a/tests/Unit/Commands/GenerateTranslationCommandTest.php +++ b/tests/Unit/Commands/GenerateTranslationCommandTest.php @@ -5,7 +5,7 @@ class GenerateTranslationCommandTest extends CommandTestCase { /** @test */ - public function it_generates_a_translation() + public function itGeneratesATranslation() { $this->artisan('json-api-server:generate-translation', ['name' => 'Example', '--path' => 'tests/Data/Output/']); $this->assertTrue(file_exists(config('laravel_api.path.translation').'ExampleTranslation.php')); diff --git a/tests/Unit/ControllerTest.php b/tests/Unit/ControllerTest.php index 99e2021..ffb2540 100644 --- a/tests/Unit/ControllerTest.php +++ b/tests/Unit/ControllerTest.php @@ -15,7 +15,7 @@ class ControllerTest extends TestCase { - /** @var TestController $testController */ + /** @var TestController */ protected $testController; /** @var Response */ protected $response; @@ -37,17 +37,17 @@ protected function setUp(): void * * @throws \Swis\JsonApi\Server\Exceptions\ForbiddenException */ - public function test_index() + public function testIndex() { $this->response = $this->testController->index(); $collection = $this->response->getContent(); - $this->assertContains('data', $collection); + $this->assertStringContainsString('data', $collection); } /** * @throws \Swis\JsonApi\Server\Exceptions\ForbiddenException */ - public function test_show() + public function testShow() { $this->response = $this->testController->show(1); $collection = json_decode($this->response->getContent()); @@ -57,7 +57,7 @@ public function test_show() /** * @throws \Swis\JsonApi\Server\Exceptions\ForbiddenException */ - public function test_delete() + public function testDelete() { $this->response = $this->testController->delete(1); $this->assertDatabaseMissing('test_models', [ diff --git a/tests/Unit/CustomFileGeneratorTest.php b/tests/Unit/CustomFileGeneratorTest.php index 7ceff76..38a994a 100644 --- a/tests/Unit/CustomFileGeneratorTest.php +++ b/tests/Unit/CustomFileGeneratorTest.php @@ -9,7 +9,7 @@ class CustomFileGeneratorTest extends TestCase { /** @test */ - public function it_generates_all_desired_custom_api_files() + public function itGeneratesAllDesiredCustomApiFiles() { $modelName = 'Example'; $path = 'tests/Data/Output/'; diff --git a/tests/Unit/EmptyPaginatorTest.php b/tests/Unit/EmptyPaginatorTest.php index 7fbf72c..5bee85d 100644 --- a/tests/Unit/EmptyPaginatorTest.php +++ b/tests/Unit/EmptyPaginatorTest.php @@ -15,13 +15,13 @@ protected function setUp(): void } /** @test */ - public function test_total() + public function testTotal() { $this->assertEquals(0, $this->emptyPaginator->total()); } /** @test */ - public function test_to_array() + public function testToArray() { $this->assertEquals([], $this->emptyPaginator->toArray()['data']); $this->assertEquals(0, $this->emptyPaginator->toArray()['total']); diff --git a/tests/Unit/Exceptions/BadRequestExceptionTest.php b/tests/Unit/Exceptions/BadRequestExceptionTest.php index ebab342..fd3fea6 100644 --- a/tests/Unit/Exceptions/BadRequestExceptionTest.php +++ b/tests/Unit/Exceptions/BadRequestExceptionTest.php @@ -18,6 +18,6 @@ public function testRender() $badRequestException = new BadRequestException('BAD REQUEST'); $response = $badRequestException->render(); $this->assertEquals(400, $response->getStatusCode()); - $this->assertContains('BAD REQUEST', $response->getContent()); + $this->assertStringContainsString('BAD REQUEST', $response->getContent()); } } diff --git a/tests/Unit/Exceptions/ForbiddenExceptionTest.php b/tests/Unit/Exceptions/ForbiddenExceptionTest.php index dc9859f..0e2e0c3 100644 --- a/tests/Unit/Exceptions/ForbiddenExceptionTest.php +++ b/tests/Unit/Exceptions/ForbiddenExceptionTest.php @@ -18,6 +18,6 @@ public function testRender() $forbiddenException = new ForbiddenException('FORBIDDEN'); $response = $forbiddenException->render(); $this->assertEquals(403, $response->getStatusCode()); - $this->assertContains('FORBIDDEN', $response->getContent()); + $this->assertStringContainsString('FORBIDDEN', $response->getContent()); } } diff --git a/tests/Unit/Exceptions/NotFoundExceptionTest.php b/tests/Unit/Exceptions/NotFoundExceptionTest.php index a4c8ecb..684cf4b 100644 --- a/tests/Unit/Exceptions/NotFoundExceptionTest.php +++ b/tests/Unit/Exceptions/NotFoundExceptionTest.php @@ -18,6 +18,6 @@ public function testRender() $notFoundException = new NotFoundException('NOT FOUND'); $response = $notFoundException->render(); $this->assertEquals(404, $response->getStatusCode()); - $this->assertContains('NOT FOUND', $response->getContent()); + $this->assertStringContainsString('NOT FOUND', $response->getContent()); } } diff --git a/tests/Unit/HandleResponsesTest.php b/tests/Unit/HandleResponsesTest.php index 4de711b..df2033c 100644 --- a/tests/Unit/HandleResponsesTest.php +++ b/tests/Unit/HandleResponsesTest.php @@ -14,7 +14,7 @@ class HandleResponsesTest extends TestCase { - /** @var HandleResponses $mock */ + /** @var HandleResponses */ private $mock; protected function setUp(): void @@ -24,7 +24,7 @@ protected function setUp(): void } /** @test */ - public function test_respond_with_forbidden() + public function testRespondWithForbidden() { $response = $this->mock->respondWithForbidden('FORBIDDEN'); @@ -34,7 +34,7 @@ public function test_respond_with_forbidden() } /** @test */ - public function test_respond_with_bad_request() + public function testRespondWithBadRequest() { $response = $this->mock->respondWithBadRequest('BAD REQUEST'); @@ -44,7 +44,7 @@ public function test_respond_with_bad_request() } /** @test */ - public function test_respond_with_not_found() + public function testRespondWithNotFound() { $response = $this->mock->respondWithNotFound('NOT FOUND'); @@ -54,7 +54,7 @@ public function test_respond_with_not_found() } /** @test */ - public function test_respond_with_collection_model() + public function testRespondWithCollectionModel() { $model = new TestModel(); $model->body = 'TEST'; diff --git a/tests/Unit/RepositoryTest.php b/tests/Unit/RepositoryTest.php index 6668d4a..fc24d5b 100644 --- a/tests/Unit/RepositoryTest.php +++ b/tests/Unit/RepositoryTest.php @@ -34,13 +34,13 @@ protected function setUp(): void } /** @test */ - public function model_has_relationships() + public function modelHasRelationships() { $this->assertEquals(['0' => 'testModels'], $this->testRepositoryWithRelationships->getModelRelationships()); } /** @test */ - public function make_model_not_instance_of_model() + public function makeModelNotInstanceOfModel() { $this->testRepository->replaceModel(TestRepository::class); $this->expectException(ModelNotFoundException::class); @@ -48,114 +48,114 @@ public function make_model_not_instance_of_model() } /** @test */ - public function set_ids_with_parameters() + public function setIdsWithParameters() { $this->testRepository->paginate($parameters = ['ids' => '1,2,3']); $this->assertEquals([1, 2, 3], $this->testRepository->getQuery()->wheres[0]['values']); } /** @test */ - public function set_ids_without_parameters() + public function setIdsWithoutParameters() { $this->assertEquals(null, $this->testRepository->setIds()); } /** @test */ - public function exclude_ids_with_parameters() + public function excludeIdsWithParameters() { $this->testRepository->paginate($parameters = ['exclude_ids' => '1,2,3']); $this->assertEquals([1, 2, 3], $this->testRepository->getQuery()->wheres[0]['values']); } /** @test */ - public function exclude_ids_without_parameters() + public function excludeIdsWithoutParameters() { $this->assertEquals(null, $this->testRepository->excludeIds()); } /** @test */ - public function order_by_asc_with_parameters() + public function orderByAscWithParameters() { $this->testRepository->paginate($parameters = ['order_by_asc' => true]); $this->assertEquals('asc', $this->testRepository->getQuery()->orders[0]['direction']); } /** @test */ - public function order_by_asc_without_parameters() + public function orderByAscWithoutParameters() { $this->assertEquals(null, $this->testRepository->orderByAsc()); } /** @test */ - public function order_by_desc_with_parameters() + public function orderByDescWithParameters() { $this->testRepository->paginate($parameters = ['order_by_desc' => true]); $this->assertEquals('desc', $this->testRepository->getQuery()->orders[0]['direction']); } /** @test */ - public function order_by_desc_without_parameters() + public function orderByDescWithoutParameters() { $this->assertEquals(null, $this->testRepository->orderByDesc()); } /** @test */ - public function paginate_with_page() + public function paginateWithPage() { $this->testRepository->paginate($parameters = ['page' => 2]); $this->assertEquals(15, $this->testRepository->getQuery()->offset); } /** @test */ - public function paginate_with_per_page() + public function paginateWithPerPage() { $this->testRepository->paginate($parameters = ['per_page' => 2]); $this->assertEquals(2, $this->testRepository->getQuery()->limit); } /** @test */ - public function paginate_with_all_attribute() + public function paginateWithAllAttribute() { $this->assertEquals(1, $this->testRepository->paginate($parameters = ['all' => true])->total()); } /** @test */ - public function paginate_with_all_attribute_empty_collection() + public function paginateWithAllAttributeEmptyCollection() { $result = $this->testRepositoryWithRelationships->paginate(['all' => true]); $this->assertInstanceOf(EmptyPaginator::class, $result); } /** @test */ - public function set_columns() + public function setColumns() { $this->testRepository->paginate($parameters = ['fields' => 'title']); $this->assertContains('title', $this->testRepository->getColumns()); } /** @test */ - public function find_model_by_id_without_query() + public function findModelByIdWithoutQuery() { $model = $this->testRepository->findById(1); $this->assertEquals($model->title, $this->testModel->title); } /** @test */ - public function find_model_by_id_with_query() + public function findModelByIdWithQuery() { $model = $this->testRepository->setParameters(['order_by_asc' => true])->findById(1); $this->assertEquals($model->title, $this->testModel->title); } /** @test */ - public function eager_load_relation_ships() + public function eagerLoadRelationShips() { $this->testRepositoryWithRelationships->paginate(['include' => 'testModels']); $this->assertCount(1, $this->testRepositoryWithRelationships->getQuery()->getEagerLoads()); } /** @test */ - public function create_model() + public function createModel() { $this->testRepository->create(['title' => 'test', 'body' => 'test']); $this->assertDatabaseHas('test_models', [ @@ -166,7 +166,7 @@ public function create_model() } /** @test */ - public function create_model_with_null_value() + public function createModelWithNullValue() { $this->testRepository->create(['title' => 'test', 'body' => null]); $this->assertDatabaseHas('test_models', [ @@ -179,7 +179,7 @@ public function create_model_with_null_value() /** @test * @throws \Swis\JsonApi\Server\Exceptions\NotFoundException */ - public function update_model() + public function updateModel() { $this->testRepository->update(['title' => 'test2', 'body' => 'test'], 1); $this->assertDatabaseHas('test_models', [ @@ -191,14 +191,14 @@ public function update_model() /** @test * @throws \Swis\JsonApi\Server\Exceptions\NotFoundException */ - public function update_model_not_found() + public function updateModelNotFound() { $this->expectException(NotFoundException::class); $this->testRepository->update(['title' => 'test2', 'body' => 'test'], 2); } /** @test */ - public function destroy_model() + public function destroyModel() { $this->testRepository->destroy(1); $this->assertDatabaseMissing('test_models', [ diff --git a/tests/Unit/ResponseServiceTest.php b/tests/Unit/ResponseServiceTest.php index 2a4e569..4c77bba 100644 --- a/tests/Unit/ResponseServiceTest.php +++ b/tests/Unit/ResponseServiceTest.php @@ -30,7 +30,7 @@ protected function setUp(): void } /** @test */ - public function it_creates_an_OK_response() + public function itCreatesAnOKResponse() { $this->testModel->body = 'OK'; $response = $this->respondWithOK($this->testModel); @@ -41,7 +41,7 @@ public function it_creates_an_OK_response() } /** @test */ - public function it_creates_a_partial_content_response() + public function itCreatesAPartialContentResponse() { $this->testModel->body = 'PARTIAL'; $paginator = new LengthAwarePaginator([$this->testModel], 1, 1); @@ -53,7 +53,7 @@ public function it_creates_a_partial_content_response() } /** @test */ - public function it_creates_a_created_response() + public function itCreatesACreatedResponse() { $this->testModel->body = 'CREATED'; $response = $this->respondWithCreated($this->testModel); @@ -64,7 +64,7 @@ public function it_creates_a_created_response() } /** @test */ - public function it_creates_a_no_content_response() + public function itCreatesANoContentResponse() { $response = $this->respondWithNoContent(); @@ -72,7 +72,7 @@ public function it_creates_a_no_content_response() } /** @test */ - public function it_creates_a_collection_response_with_OK() + public function itCreatesACollectionResponseWithOK() { $this->testModel->body = 'OK'; $paginator = new LengthAwarePaginator([$this->testModel], 1, 1); @@ -84,7 +84,7 @@ public function it_creates_a_collection_response_with_OK() } /** @test */ - public function it_creates_a_collection_response_with_PARTIAL() + public function itCreatesACollectionResponseWithPARTIAL() { $this->testModel->body = 'PARTIAL'; $paginator = new LengthAwarePaginator([$this->testModel], 1, 1); @@ -97,14 +97,14 @@ public function it_creates_a_collection_response_with_PARTIAL() } /** @test */ - public function it_creates_a_not_found_response_in_resource() + public function itCreatesANotFoundResponseInResource() { $this->expectException(NotFoundException::class); $this->respondWithResource($this->testModel, null); } /** @test */ - public function it_creates_a_forbidden_response() + public function itCreatesAForbiddenResponse() { $message = 'FORBIDDEN'; $response = $this->responseService->response(RespondHttpForbidden::class, $message); @@ -114,7 +114,7 @@ public function it_creates_a_forbidden_response() } /** @test */ - public function it_creates_a_not_found_response() + public function itCreatesANotFoundResponse() { $message = 'NOT FOUND'; $response = $this->responseService->response(RespondHttpNotFound::class, $message); @@ -124,7 +124,7 @@ public function it_creates_a_not_found_response() } /** @test */ - public function it_creates_a_unauthorized_response() + public function itCreatesAUnauthorizedResponse() { $message = 'UNAUTHORIZED'; $response = $this->responseService->response(RespondHttpUnauthorized::class, $message);