|
1 | 1 | <?php |
2 | 2 |
|
3 | | -use Illuminate\Database\Capsule\Manager; |
4 | | -use Illuminate\Events\Dispatcher; |
5 | 3 | use Illuminate\Container\Container; |
| 4 | +use Illuminate\Database\Capsule\Manager; |
6 | 5 | use Illuminate\Database\Eloquent\Model; |
7 | 6 | use Illuminate\Database\Eloquent\SoftDeletes; |
| 7 | +use Illuminate\Events\Dispatcher; |
8 | 8 |
|
9 | 9 | class CascadeSoftDeletesIntegrationTest extends PHPUnit_Framework_TestCase |
10 | 10 | { |
11 | 11 | public static function setupBeforeClass() |
12 | 12 | { |
13 | 13 | $manager = new Manager(); |
14 | 14 | $manager->addConnection([ |
15 | | - 'driver' => 'sqlite', |
| 15 | + 'driver' => 'sqlite', |
16 | 16 | 'database' => ':memory:', |
17 | 17 | ]); |
18 | 18 |
|
@@ -43,6 +43,13 @@ public static function setupBeforeClass() |
43 | 43 | $table->string('body'); |
44 | 44 | $table->timestamps(); |
45 | 45 | }); |
| 46 | + |
| 47 | + $manager->schema()->create('post_types', function ($table) { |
| 48 | + $table->increments('id'); |
| 49 | + $table->integer('post_id')->unsigned()->nullable(); |
| 50 | + $table->string('label'); |
| 51 | + $table->timestamps(); |
| 52 | + }); |
46 | 53 | } |
47 | 54 |
|
48 | 55 |
|
@@ -201,6 +208,22 @@ public function it_handles_grandchildren() |
201 | 208 | } |
202 | 209 | } |
203 | 210 |
|
| 211 | + /** @test */ |
| 212 | + public function it_cascades_a_has_one_relationship() |
| 213 | + { |
| 214 | + $post = Tests\Entities\Post::create([ |
| 215 | + 'title' => 'Cascae a has one relationship', |
| 216 | + 'body' => 'This is how you cascade a has one relationship', |
| 217 | + ]); |
| 218 | + |
| 219 | + $type = new Tests\Entities\PostType(['label' => 'Test']); |
| 220 | + |
| 221 | + $post->postType()->save($type); |
| 222 | + |
| 223 | + $post->delete(); |
| 224 | + $this->assertCount(0, Tests\Entities\Author::withTrashed()->where('id', $type->id)->get()); |
| 225 | + } |
| 226 | + |
204 | 227 | /** |
205 | 228 | * Attach some dummy posts (w/ comments) to the given author. |
206 | 229 | * |
@@ -241,5 +264,4 @@ private function attachCommentsToPost($post) |
241 | 264 |
|
242 | 265 | return $post; |
243 | 266 | } |
244 | | - |
245 | 267 | } |
0 commit comments