-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle model deletion better to prevent FK exceptions (#1859)
Co-authored-by: alecritson <[email protected]>
- Loading branch information
1 parent
7b15b0b
commit 806009b
Showing
9 changed files
with
249 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
<?php | ||
|
||
uses(\Lunar\Tests\Core\TestCase::class); | ||
uses(\Lunar\Tests\Core\TestCase::class)->group('models'); | ||
|
||
use Lunar\Models\Address; | ||
use Lunar\Models\Country; | ||
use Lunar\Models\Customer; | ||
|
||
use function Pest\Laravel\{assertDatabaseMissing}; | ||
|
||
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class); | ||
|
||
test('can make an address with minimal attributes', function () { | ||
|
@@ -60,3 +63,37 @@ | |
expect($address->customer)->toBeInstanceOf(Customer::class); | ||
expect($address->country)->toBeInstanceOf(Country::class); | ||
}); | ||
|
||
test('can delete address', function () { | ||
$country = Country::factory()->create(); | ||
$customer = Customer::factory()->create(); | ||
|
||
$data = [ | ||
'country_id' => $country->id, | ||
'customer_id' => $customer->id, | ||
'first_name' => 'Tony', | ||
'last_name' => 'Stark', | ||
'line_one' => 'Stark Industries Headquarters', | ||
'line_two' => 'Line Two', | ||
'line_three' => 'Line Three', | ||
'state' => 'Southern California', | ||
'postcode' => 123456, | ||
'delivery_instructions' => 'Pass on to Happy', | ||
'contact_email' => '[email protected]', | ||
'contact_phone' => '123123123', | ||
'meta' => [ | ||
'door_code' => 0000, | ||
], | ||
'shipping_default' => true, | ||
'billing_default' => true, | ||
'city' => 'Los Angeles', | ||
]; | ||
|
||
$address = Address::create($data); | ||
|
||
$address->delete(); | ||
|
||
assertDatabaseMissing(Address::class, [ | ||
'id' => $address->id, | ||
]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters