diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..3c2b265 --- /dev/null +++ b/.php_cs @@ -0,0 +1,29 @@ +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); diff --git a/.travis.yml b/.travis.yml index 02bfbe8..9f60bad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/README.md b/README.md index 3bdcfd7..47fd690 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 diff --git a/composer.json b/composer.json index d56c575..e8978fd 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/phpunit.xml b/phpunit.xml index 76a1e51..b27515e 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,8 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" - syntaxCheck="false"> + stopOnFailure="false"> ./tests/ diff --git a/src/CascadeSoftDeletes.php b/src/CascadeSoftDeletes.php index ce19dfd..1d4aec8 100644 --- a/src/CascadeSoftDeletes.php +++ b/src/CascadeSoftDeletes.php @@ -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 { @@ -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) )); } diff --git a/tests/CascadeSoftDeletesIntegrationTest.php b/tests/CascadeSoftDeletesIntegrationTest.php index e6a7c45..70d205b 100644 --- a/tests/CascadeSoftDeletesIntegrationTest.php +++ b/tests/CascadeSoftDeletesIntegrationTest.php @@ -1,14 +1,13 @@ addConnection([ @@ -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', @@ -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', @@ -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()); } @@ -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',