Skip to content

Commit 6be19e3

Browse files
committed
test: increase coverage
1 parent 8f59055 commit 6be19e3

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

tests/EntityControlTraitTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function testWith()
8383
$this->assertEquals(['relation'], $attachedRelations);
8484
}
8585

86-
public function withCount()
86+
public function testWithCount()
8787
{
8888
$this->testRepositoryClass->withCount('relation');
8989

@@ -100,7 +100,7 @@ public function testAll()
100100
->withTrashed()
101101
->onlyTrashed()
102102
->with('relation')
103-
->withCount('relation')
103+
->withCount(['relation', 'relation.child_relation'])
104104
->force()
105105
->all();
106106

tests/SearchTraitTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class SearchTraitTest extends HelpersTestCase
2121
protected ReflectionProperty $forceModeProperty;
2222
protected ReflectionProperty $attachedRelationsProperty;
2323
protected ReflectionProperty $attachedRelationsCountProperty;
24-
protected ReflectionProperty $queryProperty;
2524
protected ReflectionProperty $shouldSettablePropertiesBeResetProperty;
2625

2726
protected ReflectionMethod $setAdditionalReservedFiltersMethod;
@@ -58,9 +57,6 @@ public function setUp(): void
5857
);
5958
$this->shouldSettablePropertiesBeResetProperty->setAccessible(true);
6059

61-
$this->queryProperty = new ReflectionProperty(TestRepository::class, 'query');
62-
$this->queryProperty->setAccessible(true);
63-
6460
$reflectionClass = new ReflectionClass(TestRepository::class);
6561
$this->setAdditionalReservedFiltersMethod = $reflectionClass->getMethod('setAdditionalReservedFilters');
6662
$this->setAdditionalReservedFiltersMethod->setAccessible(true);
@@ -79,7 +75,7 @@ public function testSearchQuery()
7975
'with_count' => ['relation']
8076
]);
8177

82-
$sql = $this->queryProperty->getValue($this->testRepositoryClass)->toSql();
78+
$sql = $this->testRepositoryClass->getSearchQuery()->toSql();
8379

8480
$onlyTrashed = $this->onlyTrashedProperty->getValue($this->testRepositoryClass);
8581
$withTrashed = $this->withTrashedProperty->getValue($this->testRepositoryClass);
@@ -218,6 +214,7 @@ public function testSearchQueryWithRelations()
218214
])
219215
->filterByQuery(['query_field', 'relation.another_query_field'])
220216
->filterBy('relation.name', 'relation_name')
217+
->filterBy('relation.another_name')
221218
->getSearchResults();
222219
}
223220

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace RonasIT\Support\Tests\Support\Mock;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class ChildRelationModel extends Model
8+
{
9+
}

tests/support/Mock/RelationModel.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
namespace RonasIT\Support\Tests\Support\Mock;
44

55
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Database\Eloquent\Relations\HasMany;
67

78
class RelationModel extends Model
89
{
10+
public function child_relation(): HasMany
11+
{
12+
return $this->hasMany(ChildRelationModel::class);
13+
}
914
}

tests/support/Traits/SqlMockTrait.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ protected function mockAll(array $selectResult): void
2020
);
2121

2222
$this->mockSelect(
23-
'select * from `relation_models` where `relation_models`.`test_model_id` in (1)'
23+
'select `relation_models`.*, (select count(*) from `child_relation_models` '
24+
. 'where `relation_models`.`id` = `child_relation_models`.`relation_model_id`) as `child_relation_count` '
25+
. 'from `relation_models` where `relation_models`.`test_model_id` in (1)',
2426
);
2527
}
2628

0 commit comments

Comments
 (0)