Skip to content

Commit dfb4216

Browse files
Merge pull request #33 from michaeldyrynda/chore/laravel-6-compat
Laravel 6 compatibility
2 parents d7d68c8 + 15a8d5d commit dfb4216

File tree

7 files changed

+58
-98
lines changed

7 files changed

+58
-98
lines changed

.php_cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
$finder = \PhpCsFixer\Finder::create()
4+
->in(__DIR__)
5+
->exclude(['bootstrap', 'storage', 'vendor'])
6+
->name('*.php')
7+
->name('_ide_helper')
8+
->notName('*.blade.php')
9+
->ignoreDotFiles(true)
10+
->ignoreVCS(true);
11+
12+
return PhpCsFixer\Config::create()
13+
->setRules([
14+
'@PSR2' => true, // Use PSR-2 formatting by default.
15+
'psr0' => false, // Don't do PSR-0 formatting (implicit under PSR-2).
16+
'not_operator_with_successor_space' => true, // Logical NOT operators (!) should have one trailing whitespace.
17+
'trailing_comma_in_multiline_array' => true, // PHP multi-line arrays should have a trailing comma.
18+
'ordered_imports' => ['sortAlgorithm' => 'length'], // Ordering use statements (alphabetically)
19+
'ordered_class_elements' => true, // Order class elements
20+
'blank_line_before_return' => true, // An empty line feed should precede a return statement
21+
'array_syntax' => ['syntax' => 'short'], // PHP arrays should use the PHP 5.4 short-syntax.
22+
'short_scalar_cast' => true, // Cast "(boolean)" and "(integer)" should be written as "(bool)" and "(int)". "(double)" and "(real)" as "(float)".
23+
'single_blank_line_before_namespace' => true, // An empty line feed should precede the namespace.
24+
'blank_line_after_opening_tag' => true, // An empty line feed should follow a PHP open tag.
25+
'no_unused_imports' => true, // Unused use statements must be removed.
26+
'trim_array_spaces' => true, // Arrays should be formatted like function/method arguments, without leading or trailing single line space.
27+
'no_trailing_comma_in_singleline_array' => true, // PHP single-line arrays should not have a trailing comma.
28+
])
29+
->setFinder($finder);

.travis.yml

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,71 +5,14 @@ cache:
55
- $HOME/.composer/cache
66

77
matrix:
8+
fast_finish: true
89
include:
9-
- php: 5.5.9
10-
env: ILLUMINATE_VERSION=5.1.*
11-
- php: 5.5.9
12-
env: ILLUMINATE_VERSION=5.2.*
13-
- php: 5.6
14-
env: ILLUMINATE_VERSION=5.1.*
15-
- php: 5.6
16-
env: ILLUMINATE_VERSION=5.2.*
17-
- php: 5.6
18-
env: ILLUMINATE_VERSION=5.3.*
19-
- php: 5.6
20-
env: ILLUMINATE_VERSION=5.4.*
21-
- php: 7.0
22-
env: ILLUMINATE_VERSION=5.1.*
23-
- php: 7.0
24-
env: ILLUMINATE_VERSION=5.2.*
25-
- php: 7.0
26-
env: ILLUMINATE_VERSION=5.3.*
27-
- php: 7.0
28-
env: ILLUMINATE_VERSION=5.4.*
29-
- php: 7.0
30-
env: ILLUMINATE_VERSION=5.5.*
31-
- php: 7.1
32-
env: ILLUMINATE_VERSION=5.1.*
33-
- php: 7.1
34-
env: ILLUMINATE_VERSION=5.2.*
35-
- php: 7.1
36-
env: ILLUMINATE_VERSION=5.3.*
37-
- php: 7.1
38-
env: ILLUMINATE_VERSION=5.4.*
39-
- php: 7.1
40-
env: ILLUMINATE_VERSION=5.5.*
41-
- php: 7.1
42-
env: ILLUMINATE_VERSION=5.6.*
43-
- php: 7.1
44-
env: ILLUMINATE_VERSION=5.7.*
4510
- php: 7.2
46-
env: ILLUMINATE_VERSION=5.1.*
47-
- php: 7.2
48-
env: ILLUMINATE_VERSION=5.2.*
49-
- php: 7.2
50-
env: ILLUMINATE_VERSION=5.3.*
51-
- php: 7.2
52-
env: ILLUMINATE_VERSION=5.4.*
53-
- php: 7.2
54-
env: ILLUMINATE_VERSION=5.5.*
55-
- php: 7.2
56-
env: ILLUMINATE_VERSION=5.6.*
57-
- php: 7.2
58-
env: ILLUMINATE_VERSION=5.7.*
59-
- php: nightly
60-
env: ILLUMINATE_VERSION=5.1.*
61-
- php: nightly
62-
env: ILLUMINATE_VERSION=5.2.*
63-
- php: nightly
64-
env: ILLUMINATE_VERSION=5.3.*
65-
- php: nightly
66-
env: ILLUMINATE_VERSION=5.4.*
67-
- php: nightly
68-
env: ILLUMINATE_VERSION=5.5.*
69-
- php: nightly
70-
env: ILLUMINATE_VERSION=5.6.*
71-
- php: nightly
72-
env: ILLUMINATE_VERSION=5.7.*
11+
env: ILLUMINATE_VERSION=6.0.*
12+
- php: 7.3
13+
env: ILLUMINATE_VERSION=6.0.*
14+
- php: 7.4snapshot
15+
env: ILLUMINATE_VERSION=6.0.*
7316

7417
before_install: travis_retry composer require "illuminate/database:${ILLUMINATE_VERSION}" "illuminate/events:${ILLUMINATE_VERSION}" --no-update -v
7518

README.md

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Cascading soft deletes for the Laravel PHP Framework
2-
## v1.4.0
2+
## v2.0.0
33

44
![Travis Build Status](https://travis-ci.org/michaeldyrynda/laravel-cascade-soft-deletes.svg?branch=master)
55
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/michaeldyrynda/laravel-cascade-soft-deletes/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/michaeldyrynda/laravel-cascade-soft-deletes/?branch=master)
@@ -18,20 +18,6 @@ It may be useful to be able to restore a parent record after it was deleted. In
1818

1919
In doing so, however, you lose the ability to use the cascading delete functionality that your database would otherwise provide. That is where this package aims to bridge the gap in functionality when using the `SoftDeletes` trait.
2020

21-
As of `v1.0.2`, you can inherit `CascadeSoftDeletes` from a base model class, you no longer need to use the trait on each child if all of your models happen to implement `SoftDeletes`.
22-
23-
As of `v1.0.4`, the package supports cascading deletes of grandchildren records ([#8](https://github.com/michaeldyrynda/laravel-cascade-soft-deletes/issues/8), [#9](https://github.com/michaeldyrynda/laravel-cascade-soft-deletes/pull/9)).
24-
25-
As of `v1.0.5`, the package has better support of `hasOne` relationships ([#10](https://github.com/michaeldyrynda/laravel-cascade-soft-deletes/issues/10), [#11](https://github.com/michaeldyrynda/laravel-cascade-soft-deletes/issues/11)).
26-
27-
`v1.1.0` adds compatibility with Laravel 5.3.
28-
29-
`v1.2.0` adds compatibility with Laravel 5.4.
30-
31-
`v1.3.0` adds compatibility with Laravel 5.5.
32-
33-
`v1.4.0` adds compatibility with Laravel 5.6.
34-
3521
## Code Samples
3622

3723
```php

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
"description": "Cascading deletes for Eloquent models that implement soft deletes",
44
"type": "utility",
55
"require": {
6-
"php": ">=5.4",
7-
"illuminate/database": "~5.0",
8-
"illuminate/events": "~5.0"
6+
"php": "^7.2",
7+
"illuminate/database": "^6.0",
8+
"illuminate/events": "^6.0"
99
},
1010
"require-dev": {
11-
"phpunit/phpunit": "^4.8"
11+
"phpunit/phpunit": "^8.0"
1212
},
1313
"autoload": {
1414
"psr-4": {

phpunit.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
convertNoticesToExceptions="true"
77
convertWarningsToExceptions="true"
88
processIsolation="false"
9-
stopOnFailure="false"
10-
syntaxCheck="false">
9+
stopOnFailure="false">
1110
<testsuites>
1211
<testsuite name="Application Test Suite">
1312
<directory>./tests/</directory>

src/CascadeSoftDeletes.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace Iatstuti\Database\Support;
44

5+
use LogicException;
6+
use Illuminate\Support\Str;
57
use Illuminate\Database\Eloquent\Model;
68
use Illuminate\Database\Eloquent\Relations\Relation;
7-
use LogicException;
89

910
trait CascadeSoftDeletes
1011
{
@@ -29,7 +30,7 @@ protected static function bootCascadeSoftDeletes()
2930
if ($invalidCascadingRelationships = $model->hasInvalidCascadingRelationships()) {
3031
throw new LogicException(sprintf(
3132
'%s [%s] must exist and return an object of type Illuminate\Database\Eloquent\Relations\Relation',
32-
str_plural('Relationship', count($invalidCascadingRelationships)),
33+
Str::plural('Relationship', count($invalidCascadingRelationships)),
3334
join(', ', $invalidCascadingRelationships)
3435
));
3536
}

tests/CascadeSoftDeletesIntegrationTest.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<?php
22

3+
use PHPUnit\Framework\TestCase;
4+
use Illuminate\Events\Dispatcher;
35
use Illuminate\Container\Container;
46
use Illuminate\Database\Capsule\Manager;
5-
use Illuminate\Database\Eloquent\Model;
6-
use Illuminate\Database\Eloquent\SoftDeletes;
7-
use Illuminate\Events\Dispatcher;
87

9-
class CascadeSoftDeletesIntegrationTest extends PHPUnit_Framework_TestCase
8+
class CascadeSoftDeletesIntegrationTest extends TestCase
109
{
11-
public static function setupBeforeClass()
10+
public static function setupBeforeClass(): void
1211
{
1312
$manager = new Manager();
1413
$manager->addConnection([
@@ -86,11 +85,12 @@ public function it_cascades_deletes_when_force_deleting_a_parent_model()
8685

8786
/**
8887
* @test
89-
* @expectedException \LogicException
90-
* @expectedExceptionMessageRegExp /.* does not implement Illuminate\\Database\\Eloquent\\SoftDeletes/
9188
*/
9289
public function it_takes_exception_to_models_that_do_not_implement_soft_deletes()
9390
{
91+
$this->expectException(LogicException::class);
92+
$this->expectExceptionMessage('Tests\Entities\NonSoftDeletingPost does not implement Illuminate\Database\Eloquent\SoftDeletes');
93+
9494
$post = Tests\Entities\NonSoftDeletingPost::create([
9595
'title' => 'Testing when you can use this trait',
9696
'body' => 'Ensure that you can only use this trait if it uses SoftDeletes',
@@ -103,11 +103,12 @@ public function it_takes_exception_to_models_that_do_not_implement_soft_deletes(
103103

104104
/**
105105
* @test
106-
* @expectedException \LogicException
107-
* @expectedExceptionMessageRegExp /.* \[.*\] must exist and return an object of type Illuminate\\Database\\Eloquent\\Relations\\Relation/
108106
*/
109107
public function it_takes_exception_to_models_trying_to_cascade_deletes_on_invalid_relationships()
110108
{
109+
$this->expectException(LogicException::class);
110+
$this->expectExceptionMessage('Relationships [invalidRelationship, anotherInvalidRelationship] must exist and return an object of type Illuminate\Database\Eloquent\Relations\Relation');
111+
111112
$post = Tests\Entities\InvalidRelationshipPost::create([
112113
'title' => 'Testing invalid cascade relationships',
113114
'body' => 'Ensure you can only use this trait if the model defines valid relationships',
@@ -130,7 +131,7 @@ public function it_ensures_that_no_deletes_are_performed_if_there_are_invalid_re
130131

131132
try {
132133
$post->delete();
133-
} catch (\LogicException $e) {
134+
} catch (LogicException $e) {
134135
$this->assertNotNull(Tests\Entities\InvalidRelationshipPost::find($post->id));
135136
$this->assertCount(3, Tests\Entities\Comment::where('post_id', $post->id)->get());
136137
}
@@ -155,11 +156,12 @@ public function it_can_accept_cascade_deletes_as_a_single_string()
155156

156157
/**
157158
* @test
158-
* @expectedException \LogicException
159-
* @expectedExceptionMessageRegExp /Relationship \[.*\] must exist and return an object of type Illuminate\\Database\\Eloquent\\Relations\\Relation/
160159
*/
161160
public function it_handles_situations_where_the_relationship_method_does_not_exist()
162161
{
162+
$this->expectException(LogicException::class);
163+
$this->expectExceptionMessage('Relationship [comments] must exist and return an object of type Illuminate\Database\Eloquent\Relations\Relation');
164+
163165
$post = Tests\Entities\PostWithMissingRelationshipMethod::create([
164166
'title' => 'Testing that missing relationship methods are accounted for',
165167
'body' => 'In this way, you need not worry about Laravel returning fatal errors',

0 commit comments

Comments
 (0)