Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
54963fb
feat: add lazyEach to EntityControlTrait
Mar 27, 2026
d26eb99
refactor: remove count result in lazyEach
Mar 31, 2026
47e4bdc
chore: merge with master
Mar 31, 2026
e5c1dd0
Update tests/support/Traits/SqlMockTrait.php
pirs1337 Mar 31, 2026
6dffcda
Update tests/EntityControlTraitTest.php
pirs1337 Mar 31, 2026
1fd799d
Merge branch 'master' into add-lazy-each
DenTray Apr 28, 2026
8a9f565
Update tests/EntityControlTraitTest.php
DenTray Apr 28, 2026
aae54a0
Update tests/EntityControlTraitTest.php
DenTray Apr 28, 2026
9bb90e1
Update tests/EntityControlTraitTest.php
DenTray Apr 28, 2026
46680d8
test: update EntityControlTraitTest lazyEach tests
Apr 28, 2026
3d540cf
test: update EntityControlTraitTest lazyEach tests
Apr 29, 2026
9e691ac
chore: merge with master
May 11, 2026
1d33ce3
test: update EntityControlTraitTest lazyEach tests
May 11, 2026
4c4a7a5
style: fix style
May 11, 2026
b8cb00f
chore: mergw with master
May 25, 2026
cd56d28
test: fix tests
May 25, 2026
b570188
Merge branch 'master' into add-lazy-each
DenTray Jun 8, 2026
2f4628f
test: improve lazyEach tests — remove Mockery::pattern, add multi-chu…
DenTray Jun 8, 2026
be33a24
test: simplify testLazyEachEmptyResult
DenTray Jun 8, 2026
42d6f7f
Apply suggestion from @DenTray
DenTray Jun 8, 2026
96436a5
fix: update clearMockAssertionFailures for PHPUnit 10 compatibility
DenTray Jun 8, 2026
14012f6
fix: make clearMockAssertionFailures compatible with PHPUnit 10 and 11
DenTray Jun 8, 2026
e9872d9
fix: handle lazyById null condition difference in Laravel 13
DenTray Jun 8, 2026
9e68833
fix: detect lazyById null condition by inspecting actual SQL instead …
DenTray Jun 8, 2026
d8455cd
fix: use different lazy query for laravel 12.4
DenTray Jun 8, 2026
c7acddd
fix: use withTrashed in testLazyEachEmptyResult to avoid global scope…
DenTray Jun 8, 2026
3da5376
fix: add space after // in single-line comment (pint)
DenTray Jun 8, 2026
c9c360f
fix: add space after // in single-line comment (pint)
DenTray Jun 8, 2026
92faff5
fix: simplify clearMockAssertionFailures — remove dead code for PHPUn…
DenTray Jun 8, 2026
c06622d
Apply suggestion from @DenTray
DenTray Jun 8, 2026
d7444c7
fix: fork clearMockAssertionFailures by Laravel version for PHPUnit 1…
DenTray Jun 8, 2026
e3b757e
fix: fork clearMockAssertionFailures by PHPUnit version instead of La…
DenTray Jun 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Traits/EntityControlTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,16 @@ public function chunk(int $limit, Closure $callback, array $where = []): void
$this->postQueryHook();
}

public function lazyEach(Closure $callback, array $where = [], int $chunkSize = 500): void
{
$this
->getQuery($where)
->lazyById($chunkSize)
->each($callback);

$this->postQueryHook();
}

/**
* Delete rows by list of values a particular field or primary key
*
Expand Down
36 changes: 36 additions & 0 deletions tests/EntityControlTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,42 @@ public function testChunkEmptyResult()
$this->assertSettablePropertiesReset(self::$testRepositoryClass);
}

public function testLazyEach()
{
$this->mockLazyEach(self::$selectResult);

self::$testRepositoryClass
->withTrashed()
->onlyTrashed()
->force()
->with('relation')
->withCount('relation')
->lazyEach(function () {
});
Comment thread
DenTray marked this conversation as resolved.
Outdated

$this->assertSettablePropertiesReset(self::$testRepositoryClass);
}

public function testLazyEachEmptyResult()
{
$this->mockSelect(
'select "test_models".*, (select count(*) from "relation_models" '
. 'where "test_models"."id" = "relation_models"."test_model_id") as "relation_count" '
. 'from "test_models" where "test_models"."deleted_at" is not null order by "id" asc limit 500',
);
Comment thread
DenTray marked this conversation as resolved.

self::$testRepositoryClass
->withTrashed()
->onlyTrashed()
->force()
->with('relation')
->withCount('relation')
->lazyEach(function () {
});

$this->assertSettablePropertiesReset(self::$testRepositoryClass);
Comment thread
DenTray marked this conversation as resolved.
Outdated
}

public function testForceDeleteByList()
{
$this->mockDelete(
Expand Down
14 changes: 14 additions & 0 deletions tests/support/Traits/SqlMockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ protected function mockChunk(array $selectResult): void
);
}

protected function mockLazyEach(array $selectResult): void
{
$this->mockSelect(
'select "test_models".*, (select count(*) from "relation_models" '
. 'where "test_models"."id" = "relation_models"."test_model_id") as "relation_count" '
. 'from "test_models" where "test_models"."deleted_at" is not null order by "id" asc limit 500',
$selectResult,
);

$this->mockSelect(
'select * from "relation_models" where "relation_models"."test_model_id" in (1)',
);
}

protected function mockCreate(array $selectResult, $notFillableValue): void
{
$this->mockInsert(
Expand Down
Loading