8000 [Feature] Support Laravel 5.8 (#312) · acorncom/laravel-json-api@f6796cc · GitHub
[go: up one dir, main page]

Skip to content

Commit f6796cc

Browse files
[Feature] Support Laravel 5.8 (cloudcreativity#312)
Adds support for Laravel 5.8, which is a non-breaking change.
1 parent f9e00f1 commit f6796cc

37 files changed

+82
-45
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ matrix:
2828
env:
2929
- LARAVEL_VERSION=5.7.*
3030
- PHPUNIT_VERSION=^7.0
31+
- php: 7.2
32+
env:
33+
- LARAVEL_VERSION=5.8.*
34+
- PHPUNIT_VERSION=^7.0
3135
- php: 7.3
3236
env:
3337
- LARAVEL_VERSION=5.5.*
@@ -40,6 +44,10 @@ matrix:
4044
env:
4145
- LARAVEL_VERSION=5.7.*
4246
- PHPUNIT_VERSION=^7.0
47+
- php: 7.3
48+
env:
49+
- LARAVEL_VERSION=5.8.*
50+
- PHPUNIT_VERSION=^7.5
4351

4452
install:
4553
- composer require "laravel/framework:${LARAVEL_VERSION}" --no-update -n

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. This projec
44

55
## Unreleased
66

7+
### Added
8+
- Package now supports Laravel 5.8.
9+
710
### Fixed
811
- [#302](https://github.com/cloudcreativity/laravel-json-api/issues/302)
912
Reject resource objects sent in relationships, as the spec defines that only resource identifiers

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ A demo application is available at [here](https://github.com/cloudcreativity/dem
6060

6161
| Laravel | This Package | EOL? |
6262
| --- | --- | --- |
63+
| 5.8.* | `dev-laravel-5.8` | - |
6364
| 5.7.* | `1.0.0-rc.2` | - |
6465
| 5.6.* | `1.0.0-rc.2` | - |
6566
| 5.5.* | `1.0.0-rc.2` | - |

composer.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@
2525
"php": "^7.1",
2626
"ext-json": "*",
2727
"cloudcreativity/utils-object": "^1.0",
28-
"illuminate/console": "5.5.*|5.6.*|5.7.*",
29-
"illuminate/contracts": "5.5.*|5.6.*|5.7.*",
30-
"illuminate/database": "5.5.*|5.6.*|5.7.*",
31-
"illuminate/filesystem": "5.5.*|5.6.*|5.7.*",
32-
"illuminate/http": "5.5.*|5.6.*|5.7.*",
33-
"illuminate/pagination": "5.5.*|5.6.*|5.7.*",
34-
"illuminate/support": "5.5.*|5.6.*|5.7.*",
28+
"illuminate/console": "5.5.*|5.6.*|5.7.*|5.8.*",
29+
"illuminate/contracts": "5.5.*|5.6.*|5.7.*|5.8.*",
30+
"illuminate/database": "5.5.*|5.6.*|5.7.*|5.8.*",
31+
"illuminate/filesystem": "5.5.*|5.6.*|5.7.*|5.8.*",
32+
"illuminate/http": "5.5.*|5.6.*|5.7.*|5.8.*",
33+
"illuminate/pagination": "5.5.*|5.6.*|5.7.*|5.8.*",
34+
"illuminate/support": "5.5.*|5.6.*|5.7.*|5.8.*",
3535
"neomerx/json-api": "^1.0.3",
3636
"ramsey/uuid": "^3.0",
3737
"symfony/psr-http-message-bridge": "^1.0",
3838
"zendframework/zend-diactoros": "^1.3"
3939
},
4040
"require-dev": {
4141
"ext-sqlite3": "*",
42-
"cloudcreativity/json-api-testing": "1.0.0-rc.1",
42+
"cloudcreativity/json-api-testing": "^1.0.0",
4343
"guzzlehttp/guzzle": "^6.3",
4444
"mockery/mockery": "^1.1",
45-
"orchestra/testbench": "3.5.*|3.6.*|3.7.*",
45+
"orchestra/testbench": "3.5.*|3.6.*|3.7.*|3.8.*",
4646
"phpunit/phpunit": "^6.0|^7.0"
4747
},
4848
"suggest": {

src/Schema/CreatesEloquentIdentities.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,24 @@ protected function createBelongsToIdentity(Model $model, $relationshipKey)
5656
));
5757
}
5858

59-
$id = $model->{$relation->getForeignKey()};
59+
// support Laravel 5.8
60+
$foreignKey = method_exists($relation, 'getForeignKeyName') ?
61+
$relation->getForeignKeyName() :
62+
$relation->getForeignKey();
63+
64+
$id = $model->{$foreignKey};
6065

6166
if (is_null($id)) {
6267
return null;
6368
}
6469

70+
// support Laravel 5.8
71+
$ownerKey = method_exists($relation, 'getOwnerKeyName') ?
72+
$relation->getOwnerKeyName() :
73+
$relation->getOwnerKey();
74+ 7802
6575
$related = $relation->getRelated()->replicate();
66-
$related->{$relation->getOwnerKey()} = $id;
76+
$related->{$ownerKey} = $id;
6777

6878
return $related;
6979
}

src/Validation/Validator.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
namespace CloudCreativity\LaravelJsonApi\Validation;
1919

2020
use CloudCreativity\LaravelJsonApi\Contracts\Validation\ValidatorInterface;
21+
use CloudCreativity\LaravelJsonApi\Exceptions\RuntimeException;
2122
use Illuminate\Contracts\Validation\Validator as ValidatorContract;
2223
use Neomerx\JsonApi\Exceptions\ErrorCollection;
2324

@@ -69,6 +70,20 @@ public function validate()
6970
return $this->validator->validate();
7071
}
7172

73+
74+
/**
75+
* @inheritdoc
76+
*/
77+
public function validated()
78+
{
79+
// @TODO remove when only supporting Laravel >=5.8
80+
if (!method_exists($this->validator, 'validated')) {
81+
throw new RuntimeException('Not supported until Laravel 5.8');
82+
}
83+
84+
return $this->validator->validated();
85+
}
86+
7287
/**
7388
* @inheritDoc
7489
*/

tests/dummy/tests/Feature/Avatars/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ abstract class TestCase extends BaseTestCase
3333
/**
3434
* @return void
3535
*/
36-
protected function setUp()
36+
protected function setUp(): void
3737
{
3838
parent::setUp();
3939
Storage::fake('local');

tests/dummy/tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ abstract class TestCase extends BaseTestCase
4040
/**
4141
* @return void
4242
*/
43-
protected function setUp()
43+
protected function setUp(): void
4444
{
4545
parent::setUp();
4646
$this->artisan('migrate');

tests/lib/Integration/Auth/AuthorizerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class AuthorizerTest extends TestCase
3737
/**
3838
* @return void
3939
*/
40-
protected function setUp()
40+
protected function setUp(): void
4141
{
4242
parent::setUp();
4343

tests/lib/Integration/Auth/ControllerAuthorizationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ControllerAuthorizationTest extends TestCase
3636
/**
3737
* @return void
3838
*/
39-
protected function setUp()
39+
protected function setUp(): void
4040
{
4141
parent::setUp();
4242

tests/lib/Integration/Client/DeleteTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class DeleteTest extends TestCase
3232
/**
3333
*
3434
*/
35-
protected function setUp()
35+
protected function setUp(): void
3636
{
3737
parent::setUp();
3838
$this->post = factory(Post::class)->create();

tests/lib/Integration/Client/ReadTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ReadTest extends TestCase
3232
/**
3333
* @return void
3434
*/
35-
protected function setUp()
35+
protected function setUp(): void
3636
{
3737
parent::setUp();
3838
$this->post = factory(Post::class)->create();

tests/lib/Integration/Client/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ abstract class TestCase extends BaseTestCase
4545
/**
4646
* @return void
4747
*/
48-
protected function setUp()
48+
protected function setUp(): void
4949
{
5050
parent::setUp();
5151
$this->handler = HandlerStack::create($this->mo 10000 ck = new MockHandler());

tests/lib/Integration/Client/ToManyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ToManyTest extends TestCase
3131
/**
3232
* @return void
3333
*/
34-
protected function setUp()
34+
protected function setUp(): void
3535
{
3636
parent::setUp();
3737
$this->post = factory(Post::class)->create();

tests/lib/Integration/Client/ToOneTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ToOneTest extends TestCase
3131
/**
3232
* @return void
3333
*/
34-
protected function setUp()
34+
protected function setUp(): void
3535
{
3636
parent::setUp();
3737
$this->post = factory(Post::class)->create();

tests/lib/Integration/Client/UpdateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class UpdateTest extends TestCase
3232
/**
3333
* @return void
3434
*/
35-
protected function setUp()
35+
protected function setUp(): void
3636
{
3737
parent::setUp();
3838
$this->post = factory(Post::class)->create();

tests/lib/Integration/ContentNegotiation/CustomTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class CustomTest extends TestCase
3737
/**
3838
* @return void
3939
*/
40-
protected function setUp()
40+
protected function setUp(): void
4141
{
4242
parent::setUp();
4343

tests/lib/Integration/Eloquent/MorphToTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class MorphToTest extends TestCase
4343
/**
4444
* @return void
4545
*/
46-
public function setUp()
46+
public function setUp(): void
4747
{
4848
parent::setUp();
4949
$this->actingAsUser();

tests/lib/Integration/Eloquent/PolymorphicHasManyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class PolymorphicHasManyTest extends TestCase
4343
/**
4444
* @return void
4545
*/
46-
protected function setUp()
46+
protected function setUp(): void
4747
{
4848
parent::setUp();
4949
$this->actingAsUser('admin', 'author');

tests/lib/Integration/Eloquent/ResourceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ResourceTest extends TestCase
3535
/**
3636
* @return void
3737
*/
38-
protected function setUp()
38+
protected function setUp(): void
3939
{
4040
parent::setUp();
4141
Carbon::setTestNow('2018-12-01 12:00:00');
@@ -44,7 +44,7 @@ protected function setUp()
4444
/**
4545
* @return void
4646
*/
47-
protected function tearDown()
47+
protected function tearDown(): void
4848
{
4949
parent::tearDown();
5050
Carbon::setTestNow();

tests/lib/Integration/ErrorsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ErrorsTest extends TestCase
4141
/**
4242
* @return void
4343
*/
44-
protected function setUp()
44+
protected function setUp(): void
4545
{
4646
parent::setUp();
4747
$this->doNotRethrowExceptions();

tests/lib/Integration/GeneratorsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class GeneratorsTest extends TestCase
4646
/**
4747
* @return void
4848
*/
49-
protected function setUp()
49+
protected function setUp(): void
5050
{
5151
parent::setUp();
5252

@@ -62,7 +62,7 @@ protected function setUp()
6262
/**
6363
* @return void
6464
*/
65-
protected function tearDown()
65+
protected function tearDown(): void
6666
{
6767
parent::tearDown();
6868

tests/lib/Integration/Http/Controllers/HooksTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class HooksTest extends TestCase
4343
/**
4444
* @return void
4545
*/
46-
protected function setUp()
46+
protected function setUp(): void
4747
{
4848
parent::setUp();
4949

tests/lib/Integration/Issue154/IssueTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class IssueTest extends TestCase
3737
/**
3838
* @return void
3939
*/
40-
protected function setUp()
40+
protected function setUp(): void
4141
{
4242
parent::setUp();
4343

tests/lib/Integration/Issue224/IssueTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class IssueTest extends TestCase
4040
/**
4141
* @return void
4242
*/
43-
protected function setUp()
43+
protected function setUp(): void
4444
{
4545
parent::setUp();
4646

tests/lib/Integration/Issue67/IssueTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class IssueTest extends TestCase
3232
/**
3333
* @return void
3434
*/
35-
protected function setUp()
35+
protected function setUp(): void
3636
{
3737
parent::setUp();
3838
$this->app->instance(PostsSchema::class, $this->app->make(Schema::class));

tests/lib/Integration/Pagination/CursorPagingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class CursorPagingTest extends TestCase
4444
/**
4545
* @return void
4646
*/
47-
protected function setUp()
47+
protected function setUp(): void
4848
{
4949
parent::setUp();
5050
$this->faker = $this->app->make(Generator::class);

tests/lib/Integration/Pagination/StandardPagingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class StandardPagingTest extends TestCase
3636
/**
3737
* @return void
3838
*/
39-
protected function setUp()
39+
protected function setUp(): void
4040
{
4141
parent::setUp();
4242
$this->app->instance(StandardStrategy::class, $this->strategy = new StandardStrategy());

tests/lib/Integration/Queue/ClientDispatchTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ClientDispatchTest extends TestCase
3636
/**
3737
* @return void
3838
*/
39-
protected function setUp()
39+
protected function setUp(): void
4040
{
4141
parent::setUp();
4242
Queue::fake();

tests/lib/Integration/Queue/ControllerHooksTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ControllerHooksTest extends TestCase
3838
/**
3939
* @return void
4040
*/
41-
protected function setUp()
41+
protected function setUp(): void
4242
{
4343
parent::setUp();
4444
Queue::fake();

tests/lib/Integration/Queue/CustomiseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class CustomiseTest extends TestCase
4040
/**
4141
* @return void
4242
*/
43-
protected function setUp()
43+
protected function setUp(): void
4444
{
4545
parent::setUp();
4646

tests/lib/Integration/Queue/QueueEventsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class QueueEventsTest extends TestCase
2828
/**
2929
F170 * @return void
3030
*/
31-
protected function setUp()
31+
protected function setUp(): void
3232
{
3333
parent::setUp();
3434
Carbon::setTestNow('2018-10-23 12:00:00.123456');

tests/lib/Integration/Resolver/ResolverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ResolverTest extends TestCase
4040
/**
4141
* @return void
4242
*/
43-
protected function setUp()
43+
protected function setUp(): void
4444
{
4545
parent::setUp();
4646

tests/lib/Integration/Routing/CustomTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class CustomTest extends TestCase
4040
/**
4141
* @return void
4242
*/
43-
protected function setUp()
43+
protected function setUp(): void
4444
{
4545
parent::setUp();
4646

0 commit comments

Comments
 (0)
0