Skip to content

Commit

Permalink
Merge pull request #33 from michaeldyrynda/chore/laravel-6-compat
Browse files Browse the repository at this point in the history
Laravel 6 compatibility
  • Loading branch information
michaeldyrynda authored Sep 6, 2019
2 parents d7d68c8 + 15a8d5d commit dfb4216
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 98 deletions.
29 changes: 29 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

$finder = \PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude(['bootstrap', 'storage', 'vendor'])
->name('*.php')
->name('_ide_helper')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true, // Use PSR-2 formatting by default.
'psr0' => false, // Don't do PSR-0 formatting (implicit under PSR-2).
'not_operator_with_successor_space' => true, // Logical NOT operators (!) should have one trailing whitespace.
'trailing_comma_in_multiline_array' => true, // PHP multi-line arrays should have a trailing comma.
'ordered_imports' => ['sortAlgorithm' => 'length'], // Ordering use statements (alphabetically)
'ordered_class_elements' => true, // Order class elements
'blank_line_before_return' => true, // An empty line feed should precede a return statement
'array_syntax' => ['syntax' => 'short'], // PHP arrays should use the PHP 5.4 short-syntax.
'short_scalar_cast' => true, // Cast "(boolean)" and "(integer)" should be written as "(bool)" and "(int)". "(double)" and "(real)" as "(float)".
'single_blank_line_before_namespace' => true, // An empty line feed should precede the namespace.
'blank_line_after_opening_tag' => true, // An empty line feed should follow a PHP open tag.
'no_unused_imports' => true, // Unused use statements must be removed.
'trim_array_spaces' => true, // Arrays should be formatted like function/method arguments, without leading or trailing single line space.
'no_trailing_comma_in_singleline_array' => true, // PHP single-line arrays should not have a trailing comma.
])
->setFinder($finder);
69 changes: 6 additions & 63 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,14 @@ cache:
- $HOME/.composer/cache

matrix:
fast_finish: true
include:
- php: 5.5.9
env: ILLUMINATE_VERSION=5.1.*
- php: 5.5.9
env: ILLUMINATE_VERSION=5.2.*
- php: 5.6
env: ILLUMINATE_VERSION=5.1.*
- php: 5.6
env: ILLUMINATE_VERSION=5.2.*
- php: 5.6
env: ILLUMINATE_VERSION=5.3.*
- php: 5.6
env: ILLUMINATE_VERSION=5.4.*
- php: 7.0
env: ILLUMINATE_VERSION=5.1.*
- php: 7.0
env: ILLUMINATE_VERSION=5.2.*
- php: 7.0
env: ILLUMINATE_VERSION=5.3.*
- php: 7.0
env: ILLUMINATE_VERSION=5.4.*
- php: 7.0
env: ILLUMINATE_VERSION=5.5.*
- php: 7.1
env: ILLUMINATE_VERSION=5.1.*
- php: 7.1
env: ILLUMINATE_VERSION=5.2.*
- php: 7.1
env: ILLUMINATE_VERSION=5.3.*
- php: 7.1
env: ILLUMINATE_VERSION=5.4.*
- php: 7.1
env: ILLUMINATE_VERSION=5.5.*
- php: 7.1
env: ILLUMINATE_VERSION=5.6.*
- php: 7.1
env: ILLUMINATE_VERSION=5.7.*
- php: 7.2
env: ILLUMINATE_VERSION=5.1.*
- php: 7.2
env: ILLUMINATE_VERSION=5.2.*
- php: 7.2
env: ILLUMINATE_VERSION=5.3.*
- php: 7.2
env: ILLUMINATE_VERSION=5.4.*
- php: 7.2
env: ILLUMINATE_VERSION=5.5.*
- php: 7.2
env: ILLUMINATE_VERSION=5.6.*
- php: 7.2
env: ILLUMINATE_VERSION=5.7.*
- php: nightly
env: ILLUMINATE_VERSION=5.1.*
- php: nightly
env: ILLUMINATE_VERSION=5.2.*
- php: nightly
env: ILLUMINATE_VERSION=5.3.*
- php: nightly
env: ILLUMINATE_VERSION=5.4.*
- php: nightly
env: ILLUMINATE_VERSION=5.5.*
- php: nightly
env: ILLUMINATE_VERSION=5.6.*
- php: nightly
env: ILLUMINATE_VERSION=5.7.*
env: ILLUMINATE_VERSION=6.0.*
- php: 7.3
env: ILLUMINATE_VERSION=6.0.*
- php: 7.4snapshot
env: ILLUMINATE_VERSION=6.0.*

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

Expand Down
16 changes: 1 addition & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Cascading soft deletes for the Laravel PHP Framework
## v1.4.0
## v2.0.0

![Travis Build Status](https://travis-ci.org/michaeldyrynda/laravel-cascade-soft-deletes.svg?branch=master)
[![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)
Expand All @@ -18,20 +18,6 @@ It may be useful to be able to restore a parent record after it was deleted. In

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.

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`.

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)).

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)).

`v1.1.0` adds compatibility with Laravel 5.3.

`v1.2.0` adds compatibility with Laravel 5.4.

`v1.3.0` adds compatibility with Laravel 5.5.

`v1.4.0` adds compatibility with Laravel 5.6.

## Code Samples

```php
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"description": "Cascading deletes for Eloquent models that implement soft deletes",
"type": "utility",
"require": {
"php": ">=5.4",
"illuminate/database": "~5.0",
"illuminate/events": "~5.0"
"php": "^7.2",
"illuminate/database": "^6.0",
"illuminate/events": "^6.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8"
"phpunit/phpunit": "^8.0"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
stopOnFailure="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
Expand Down
5 changes: 3 additions & 2 deletions src/CascadeSoftDeletes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace Iatstuti\Database\Support;

use LogicException;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Relation;
use LogicException;

trait CascadeSoftDeletes
{
Expand All @@ -29,7 +30,7 @@ protected static function bootCascadeSoftDeletes()
if ($invalidCascadingRelationships = $model->hasInvalidCascadingRelationships()) {
throw new LogicException(sprintf(
'%s [%s] must exist and return an object of type Illuminate\Database\Eloquent\Relations\Relation',
str_plural('Relationship', count($invalidCascadingRelationships)),
Str::plural('Relationship', count($invalidCascadingRelationships)),
join(', ', $invalidCascadingRelationships)
));
}
Expand Down
26 changes: 14 additions & 12 deletions tests/CascadeSoftDeletesIntegrationTest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php

use PHPUnit\Framework\TestCase;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
use Illuminate\Database\Capsule\Manager;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Events\Dispatcher;

class CascadeSoftDeletesIntegrationTest extends PHPUnit_Framework_TestCase
class CascadeSoftDeletesIntegrationTest extends TestCase
{
public static function setupBeforeClass()
public static function setupBeforeClass(): void
{
$manager = new Manager();
$manager->addConnection([
Expand Down Expand Up @@ -86,11 +85,12 @@ public function it_cascades_deletes_when_force_deleting_a_parent_model()

/**
* @test
* @expectedException \LogicException
* @expectedExceptionMessageRegExp /.* does not implement Illuminate\\Database\\Eloquent\\SoftDeletes/
*/
public function it_takes_exception_to_models_that_do_not_implement_soft_deletes()
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('Tests\Entities\NonSoftDeletingPost does not implement Illuminate\Database\Eloquent\SoftDeletes');

$post = Tests\Entities\NonSoftDeletingPost::create([
'title' => 'Testing when you can use this trait',
'body' => 'Ensure that you can only use this trait if it uses SoftDeletes',
Expand All @@ -103,11 +103,12 @@ public function it_takes_exception_to_models_that_do_not_implement_soft_deletes(

/**
* @test
* @expectedException \LogicException
* @expectedExceptionMessageRegExp /.* \[.*\] must exist and return an object of type Illuminate\\Database\\Eloquent\\Relations\\Relation/
*/
public function it_takes_exception_to_models_trying_to_cascade_deletes_on_invalid_relationships()
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('Relationships [invalidRelationship, anotherInvalidRelationship] must exist and return an object of type Illuminate\Database\Eloquent\Relations\Relation');

$post = Tests\Entities\InvalidRelationshipPost::create([
'title' => 'Testing invalid cascade relationships',
'body' => 'Ensure you can only use this trait if the model defines valid relationships',
Expand All @@ -130,7 +131,7 @@ public function it_ensures_that_no_deletes_are_performed_if_there_are_invalid_re

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

/**
* @test
* @expectedException \LogicException
* @expectedExceptionMessageRegExp /Relationship \[.*\] must exist and return an object of type Illuminate\\Database\\Eloquent\\Relations\\Relation/
*/
public function it_handles_situations_where_the_relationship_method_does_not_exist()
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('Relationship [comments] must exist and return an object of type Illuminate\Database\Eloquent\Relations\Relation');

$post = Tests\Entities\PostWithMissingRelationshipMethod::create([
'title' => 'Testing that missing relationship methods are accounted for',
'body' => 'In this way, you need not worry about Laravel returning fatal errors',
Expand Down

0 comments on commit dfb4216

Please sign in to comment.