8000 [Feature] Support Laravel 5.8 by lindyhopchris · Pull Request #312 · cloudcreativity/laravel-json-api · GitHub
[go: up one dir, main page]

Skip to content

[Feature] Support Laravel 5.8 #312

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
merged 3 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ matrix:
env:
- LARAVEL_VERSION=5.7.*
- PHPUNIT_VERSION=^7.0
- php: 7.2
env:
- LARAVEL_VERSION=5.8.*
- PHPUNIT_VERSION=^7.0
- php: 7.3
env:
- LARAVEL_VERSION=5.5.*
Expand All @@ -40,6 +44,10 @@ matrix:
env:
- LARAVEL_VERSION=5.7.*
- PHPUNIT_VERSION=^7.0
- php: 7.3
env:
- LARAVEL_VERSION=5.8.*
- PHPUNIT_VERSION=^7.5

install:
- composer require "laravel/framework:${LARAVEL_VERSION}" --no-update -n
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. This projec

## Unreleased

### Added
- Package now supports Laravel 5.8.

### Fixed
- [#295](https://github.com/cloudcreativity/laravel-json-api/issues/295)
Use `null` for empty `from`/`to` fields in cursor page meta.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ A demo application is available at [here](https://github.com/cloudcreativity/dem

| Laravel | This Package | EOL? |
| --- | --- | --- |
| 5.8.* | `dev-laravel-5.8` | - |
| 5.7.* | `1.0.0-rc.2` | - |
| 5.6.* | `1.0.0-rc.2` | - |
| 5.5.* | `1.0.0-rc.2` | - |
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@
"php": "^7.1",
"ext-json": "*",
"cloudcreativity/utils-object": "^1.0",
"illuminate/console": "5.5.*|5.6.*|5.7.*",
"illuminate/contracts": "5.5.*|5.6.*|5.7.*",
"illuminate/database": "5.5.*|5.6.*|5.7.*",
"illuminate/filesystem": "5.5.*|5.6.*|5.7.*",
"illuminate/http": "5.5.*|5.6.*|5.7.*",
"illuminate/pagination": "5.5.*|5.6.*|5.7.*",
"illuminate/support": "5.5.*|5.6.*|5.7.*",
"illuminate/console": "5.5.*|5.6.*|5.7.*|5.8.*",
"illuminate/contracts": "5.5.*|5.6.*|5.7.*|5.8.*",
"illuminate/database": "5.5.*|5.6.*|5.7.*|5.8.*",
"illuminate/filesystem": "5.5.*|5.6.*|5.7.*|5.8.*",
"illuminate/http": "5.5.*|5.6.*|5.7.*|5.8.*",
"illuminate/pagination": "5.5.*|5.6.*|5.7.*|5.8.*",
"illuminate/support": "5.5.*|5.6.*|5.7.*|5.8.*",
"neomerx/json-api": "^1.0.3",
"ramsey/uuid": "^3.0",
"symfony/psr-http-message-bridge": "^1.0",
"zendframework/zend-diactoros": "^1.3"
},
"require-dev": {
"ext-sqlite3": "*",
"cloudcreativity/json-api-testing": "1.0.0-rc.1",
"cloudcreativity/json-api-testing": "^1.0.0",
"guzzlehttp/guzzle": "^6.3",
"mockery/mockery": "^1.1",
"orchestra/testbench": "3.5.*|3.6.*|3.7.*",
"orchestra/testbench": "3.5.*|3.6.*|3.7.*|3.8.*",
"phpunit/phpunit": "^6.0|^7.0"
},
"suggest": {
Expand Down
14 changes: 12 additions & 2 deletions src/Schema/CreatesEloquentIdentities.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,24 @@ protected function createBelongsToIdentity(Model $model, $relationshipKey)
));
}

$id = $model->{$relation->getForeignKey()};
// support Laravel 5.8
$foreignKey = method_exists($relation, 'getForeignKeyName') ?
$relation->getForeignKeyName() :
$relation->getForeignKey();

$id = $model->{$foreignKey};

if (is_null($id)) {
return null;
}

// support Laravel 5.8
$ownerKey = method_exists($relation, 'getOwnerKeyName') ?
$relation->getOwnerKeyName() :
$relation->getOwnerKey();

$related = $relation->getRelated()->replicate();
$related->{$relation->getOwnerKey()} = $id;
$related->{$ownerKey} = $id;

return $related;
}
Expand Down
15 changes: 15 additions & 0 deletions src/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace CloudCreativity\LaravelJsonApi\Validation;

use CloudCreativity\LaravelJsonApi\Contracts\Validation\ValidatorInterface;
use CloudCreativity\LaravelJsonApi\Exceptions\RuntimeException;
use Illuminate\Contracts\Validation\Validator as ValidatorContract;
use Neomerx\JsonApi\Exceptions\ErrorCollection;

Expand Down Expand Up @@ -69,6 +70,20 @@ public function validate()
return $this->validator->validate();
}


/**
* @inheritdoc
*/
public function validated()
{
// @TODO remove when only supporting Laravel >=5.8
if (!method_exists($this->validator, 'validated')) {
throw new RuntimeException('Not supported until Laravel 5.8');
}

return $this->validator->validated();
}

/**
* @inheritDoc
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/tests/Feature/Avatars/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class TestCase extends BaseTestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
Storage::fake('local');
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ abstract class TestCase extends BaseTestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->artisan('migrate');
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Auth/AuthorizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AuthorizerTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Auth/ControllerAuthorizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ControllerAuthorizationTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Client/DeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DeleteTest extends TestCase
/**
*
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->post = factory(Post::class)->create();
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Client/ReadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ReadTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->post = factory(Post::class)->create();
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Client/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ abstract class TestCase extends BaseTestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->handler = HandlerStack::create($this->mock = new MockHandler());
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Client/ToManyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ToManyTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->post = factory(Post::class)->create();
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Client/ToOneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ToOneTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->post = factory(Post::class)->create();
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Client/UpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class UpdateTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->post = factory(Post::class)->create();
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/ContentNegotiation/CustomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CustomTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Eloquent/MorphToTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MorphToTest extends TestCase
/**
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->actingAsUser();
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Eloquent/PolymorphicHasManyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PolymorphicHasManyTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->actingAsUser('admin', 'author');
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Integration/Eloquent/ResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ResourceTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
Carbon::setTestNow('2018-12-01 12:00:00');
Expand All @@ -44,7 +44,7 @@ protected function setUp()
/**
* @return void
*/
protected function tearDown()
protected function tearDown(): void
{
parent::tearDown();
Carbon::setTestNow();
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/ErrorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ErrorsTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->doNotRethrowExceptions();
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Integration/GeneratorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class GeneratorsTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand All @@ -62,7 +62,7 @@ protected function setUp()
/**
* @return void
*/
protected function tearDown()
protected function tearDown(): void
{
parent::tearDown();

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Http/Controllers/HooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class HooksTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Issue154/IssueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class IssueTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Issue224/IssueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class IssueTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Issue67/IssueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class IssueTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->app->instance(PostsSchema::class, $this->app->make(Schema::class));
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Pagination/CursorPagingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CursorPagingTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->faker = $this->app->make(Generator::class);
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Pagination/StandardPagingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class StandardPagingTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->app->instance(StandardStrategy::class, $this->strategy = new StandardStrategy());
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Queue/ClientDispatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ClientDispatchTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
Queue::fake();
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Queue/ControllerHooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ControllerHooksTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
Queue::fake();
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Queue/CustomiseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CustomiseTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Queue/QueueEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class QueueEventsTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
Carbon::setTestNow('2018-10-23 12:00:00.123456');
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Resolver/ResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ResolverTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Integration/Routing/CustomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CustomTest extends TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down
Loading
0