connection = Mockery::mock(ConnectionInterface::class); $this->clock = new SystemClock(); $this->repository = new SeedRepository($this->connection, $this->clock); }); it('checks if seeder has run', function () { $result = Mockery::mock(); $result->shouldReceive('fetch') ->once() ->andReturn(['count' => 1]); $this->connection->shouldReceive('query') ->once() ->with(Mockery::on(function (SqlQuery $query) { return str_contains($query->sql, 'SELECT COUNT(*)'); })) ->andReturn($result); expect($this->repository->hasRun('TestSeeder'))->toBeTrue(); }); it('returns false when seeder has not run', function () { $result = Mockery::mock(); $result->shouldReceive('fetch') ->once() ->andReturn(['count' => 0]); $this->connection->shouldReceive('query') ->once() ->andReturn($result); expect($this->repository->hasRun('TestSeeder'))->toBeFalse(); }); it('marks seeder as run', function () { $this->connection->shouldReceive('execute') ->once() ->with(Mockery::on(function (SqlQuery $query) { return str_contains($query->sql, 'INSERT INTO seeds'); })); $this->repository->markAsRun('TestSeeder', 'Test description'); }); it('clears all seeds', function () { $this->connection->shouldReceive('execute') ->once() ->with(Mockery::on(function (SqlQuery $query) { return str_contains($query->sql, 'DELETE FROM seeds'); })); $this->repository->clearAll(); }); });