Skip to content

Commit

Permalink
Add test to lock for delete
Browse files Browse the repository at this point in the history
  • Loading branch information
xalaida committed Sep 10, 2023
1 parent 4ad2f1f commit 7441c8a
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tests/LockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class LockTest extends TestCase
/**
* @test
*/
public function it_locks_positions(): void
public function it_locks_positions_on_create(): void
{
Category::query()->getConnection()->enableQueryLog();

Expand All @@ -25,4 +25,22 @@ public function it_locks_positions(): void
static::assertSame(0, $categories[1]->fresh()->getPosition());
static::assertSame(0, $categories[2]->fresh()->getPosition());
}

/**
* @test
*/
public function it_locks_positions_on_delete(): void
{
$categories = CategoryFactory::new()->createMany(3);

Category::query()->getConnection()->enableQueryLog();

Category::withPositionLock(function () use ($categories) {
$categories[0]->delete();
});

static::assertCount(1, Category::query()->getConnection()->getQueryLog());
static::assertSame(1, $categories[1]->fresh()->getPosition());
static::assertSame(2, $categories[2]->fresh()->getPosition());
}
}

0 comments on commit 7441c8a

Please sign in to comment.