Skip to content

Commit e8253d2

Browse files
author
Coen Zimmerman
committed
Cleaned up tests
1 parent 7a21dfa commit e8253d2

8 files changed

+331
-240
lines changed

tests/BaseRepositoryTest.php

Lines changed: 139 additions & 99 deletions
Large diffs are not rendered by default.

tests/CommonCriteriaTest.php

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected function seedDatabase(): void
5858
'active' => true,
5959
]);
6060

61-
// set some translations
61+
// Set some translations.
6262
$testModel->translateOrNew('nl')->translated_string = 'vertaalde_attribuutwaarde hoepla';
6363
$testModel->translateOrNew('en')->translated_string = 'translated_attribute_value hoopla';
6464
$testModel->save();
@@ -72,7 +72,7 @@ public function field_is_value_criteria_works(): void
7272
{
7373
$this->repository->pushCriteria(new FieldIsValue('name', 'special name'));
7474

75-
$this->assertCount(1, $this->repository->all(), "FieldIsValue Criteria doesn't work");
75+
static::assertCount(1, $this->repository->all(), "FieldIsValue Criteria doesn't work");
7676
}
7777

7878
/**
@@ -82,13 +82,19 @@ public function has_criteria_works(): void
8282
{
8383
$this->repository->pushCriteria(new Has('translations', '>', 1));
8484

85-
$this->assertCount(1, $this->repository->all(), "Has Criteria simple use fails");
85+
static::assertCount(1, $this->repository->all(), 'Has Criteria simple use fails');
8686

87-
$this->repository->pushCriteria(new Has('translations', '=', 1, 'and', function($query) {
88-
return $query->where('translated_string', 'vertaalde_attribuutwaarde hoepla');
89-
}));
87+
$this->repository->pushCriteria(
88+
new Has(
89+
'translations',
90+
'=',
91+
1,
92+
'and',
93+
fn ($query) => $query->where('translated_string', 'vertaalde_attribuutwaarde hoepla')
94+
)
95+
);
9096

91-
$this->assertCount(1, $this->repository->all(), "Has Criteria use with callback fails");
97+
static::assertCount(1, $this->repository->all(), 'Has Criteria use with callback fails');
9298
}
9399

94100
/**
@@ -98,7 +104,7 @@ public function is_active_criteria_works(): void
98104
{
99105
$this->repository->pushCriteria(new IsActive('active'));
100106

101-
$this->assertCount(2, $this->repository->all(), "IsActive Criteria doesn't work");
107+
static::assertCount(2, $this->repository->all(), "IsActive Criteria doesn't work");
102108
}
103109

104110
/**
@@ -108,7 +114,7 @@ public function order_by_criteria_works(): void
108114
{
109115
$this->repository->pushCriteria(new OrderBy('position', 'desc'));
110116

111-
$this->assertEquals([3, 2, 1], $this->repository->pluck('position')->all(), "OrderBy Criteria doesn't work");
117+
static::assertEquals([3, 2, 1], $this->repository->pluck('position')->all(), "OrderBy Criteria doesn't work");
112118
}
113119

114120
/**
@@ -118,11 +124,11 @@ public function scope_criteria_works(): void
118124
{
119125
$this->repository->pushCriteria(new Scope('testing'), CriteriaKey::SCOPE);
120126

121-
$this->assertCount(2, $this->repository->all(), "Scope Criteria without parameters doesn't work");
127+
static::assertCount(2, $this->repository->all(), "Scope Criteria without parameters doesn't work");
122128

123-
$this->repository->pushCriteria(new Scope('moreTesting', [ self::SECOND_FIELD, '434' ]), CriteriaKey::SCOPE);
129+
$this->repository->pushCriteria(new Scope('moreTesting', [self::SECOND_FIELD, '434']), CriteriaKey::SCOPE);
124130

125-
$this->assertCount(1, $this->repository->all(), "Scope Criteria with parameter doesn't work");
131+
static::assertCount(1, $this->repository->all(), "Scope Criteria with parameter doesn't work");
126132
}
127133

128134
/**
@@ -132,48 +138,63 @@ public function scopes_criteria_works(): void
132138
{
133139
$this->repository->pushCriteria(new Scopes([
134140
'testing',
135-
'moreTesting' => [ 'active', false ],
141+
'moreTesting' => ['active', false],
136142
]), CriteriaKey::SCOPE);
137143

138-
$this->assertCount(1, $this->repository->all(), "Multiple Scopes Criteria doesn't work (value & key => value)");
144+
static::assertCount(
145+
1,
146+
$this->repository->all(),
147+
"Multiple Scopes Criteria doesn't work (value & key => value)"
148+
);
139149

140150
$this->repository->pushCriteria(new Scopes([
141-
[ 'testing' ],
142-
[ 'moreTesting', [ 'active', false ] ],
151+
['testing'],
152+
['moreTesting', ['active', false]],
143153
]), CriteriaKey::SCOPE);
144154

145-
$this->assertCount(1, $this->repository->all(), "Multiple Scopes Criteria doesn't work (array sets, no keys)");
155+
static::assertCount(
156+
1,
157+
$this->repository->all(),
158+
"Multiple Scopes Criteria doesn't work (array sets, no keys)"
159+
);
146160
}
147161

148162
/**
149163
* @test
150164
*/
151165
public function where_has_criteria_works(): void
152166
{
153-
$this->repository->pushCriteria(new WhereHas('translations', function($query) {
154-
return $query->where('translated_string', 'vertaalde_attribuutwaarde hoepla');
155-
}));
167+
$this->repository->pushCriteria(
168+
new WhereHas(
169+
'translations',
170+
fn ($query) => $query->where('translated_string', 'vertaalde_attribuutwaarde hoepla')
171+
)
172+
);
156173

157174
$result = $this->repository->all();
158-
$this->assertCount(1, $result, "WhereHas Criteria doesn't work (wrong count)");
159-
$this->assertEquals('1337', $result->first()->{self::UNIQUE_FIELD}, "WhereHas Criteria doesn't work (wrong model)");
175+
static::assertCount(1, $result, "WhereHas Criteria doesn't work (wrong count)");
176+
static::assertEquals(
177+
'1337',
178+
$result->first()->{self::UNIQUE_FIELD},
179+
"WhereHas Criteria doesn't work (wrong model)"
180+
);
160181
}
161182

162183
/**
163184
* @test
164185
*/
165-
public function with_relations_criteria_works(): void
186+
public function with_relations_criteria_works(): void
166187
{
167-
$this->assertEmpty(
188+
static::assertEmpty(
168189
$this->repository->findBy(self::UNIQUE_FIELD, '1337')->getRelations(),
169-
"Model already includes translations relation without WithRelations Criteria"
190+
'Model already includes translations relation without WithRelations Criteria'
170191
);
171192

172193
$this->repository->pushCriteria(new WithRelations(['translations']));
173194

174-
$this->assertNotEmpty(
195+
static::assertNotEmpty(
175196
$this->repository->findBy(self::UNIQUE_FIELD, '1337')->getRelations(),
176-
"Model does not include translations relation with WithRelations Criteria"
197+
'Model does not include translations relation with WithRelations Criteria'
177198
);
178199
}
179200

@@ -183,8 +204,6 @@ public function with_relations_criteria_works(): void
183204
public function take_criteria_works(): void
184205
{
185206
$this->repository->pushCriteria(new Take(2));
186-
187-
$this->assertCount(2, $this->repository->all(), "Take Criteria doesn't work");
207+
static::assertCount(2, $this->repository->all(), "Take Criteria doesn't work");
188208
}
189-
190209
}

0 commit comments

Comments
 (0)