Skip to content

Commit 2dcb620

Browse files
lucasmichotiget-esoares
authored andcommitted
Always prefer stricter comparisons and assertions. (babenkoivan#317)
1 parent a177879 commit 2dcb620

12 files changed

+55
-56
lines changed

src/Builders/FilterBuilder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function where($field, $value)
8383
{
8484
$args = func_get_args();
8585

86-
if (count($args) == 3) {
86+
if (count($args) === 3) {
8787
[$field, $operator, $value] = $args;
8888
} else {
8989
$operator = '=';
@@ -397,7 +397,7 @@ public function whereGeoShape($field, array $shape, $relation = 'INTERSECTS')
397397
public function orderBy($field, $direction = 'asc')
398398
{
399399
$this->orders[] = [
400-
$field => strtolower($direction) == 'asc' ? 'asc' : 'desc',
400+
$field => strtolower($direction) === 'asc' ? 'asc' : 'desc',
401401
];
402402

403403
return $this;

src/ElasticEngine.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ public function mapIds($results)
291291
*/
292292
public function map(Builder $builder, $results, $model)
293293
{
294-
if ($this->getTotalCount($results) == 0) {
294+
if ($this->getTotalCount($results) === 0) {
295295
return Collection::make();
296296
}
297297

src/Highlight.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __get($key)
3535
if (isset($this->highlight[$field])) {
3636
$value = $this->highlight[$field];
3737

38-
return $field == $key ? $value : implode(' ', $value);
38+
return $field === $key ? $value : implode(' ', $value);
3939
} else {
4040
return;
4141
}

src/Searchable.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static function search($query, $callback = null)
8484
{
8585
$softDelete = static::usesSoftDelete() && config('scout.soft_delete', false);
8686

87-
if ($query == '*') {
87+
if ($query === '*') {
8888
return new FilterBuilder(new static, $callback, $softDelete);
8989
} else {
9090
return new SearchBuilder(new static, $query, $callback, $softDelete);

tests/Builders/FilterBuilderTest.php

+28-29
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function testCreationWithSoftDelete()
1414
{
1515
$builder = new FilterBuilder($this->mockModel(), null, true);
1616

17-
$this->assertEquals(
17+
$this->assertSame(
1818
[
1919
'must' => [
2020
[
@@ -33,7 +33,7 @@ public function testCreationWithoutSoftDelete()
3333
{
3434
$builder = new FilterBuilder($this->mockModel(), null, false);
3535

36-
$this->assertEquals(
36+
$this->assertSame(
3737
[
3838
'must' => [],
3939
'must_not' => [],
@@ -48,7 +48,7 @@ public function testWhereEq()
4848
->where('foo', 0)
4949
->where('bar', '=', 1);
5050

51-
$this->assertEquals(
51+
$this->assertSame(
5252
[
5353
'must' => [
5454
['term' => ['foo' => 0]],
@@ -65,7 +65,7 @@ public function testWhereNotEq()
6565
$builder = (new FilterBuilder($this->mockModel()))
6666
->where('foo', '!=', 'bar');
6767

68-
$this->assertEquals(
68+
$this->assertSame(
6969
[
7070
'must' => [],
7171
'must_not' => [
@@ -81,7 +81,7 @@ public function testWhereGt()
8181
$builder = (new FilterBuilder($this->mockModel()))
8282
->where('foo', '>', 0);
8383

84-
$this->assertEquals(
84+
$this->assertSame(
8585
[
8686
'must' => [
8787
['range' => ['foo' => ['gt' => 0]]],
@@ -97,7 +97,7 @@ public function testWhereGte()
9797
$builder = (new FilterBuilder($this->mockModel()))
9898
->where('foo', '>=', 0);
9999

100-
$this->assertEquals(
100+
$this->assertSame(
101101
[
102102
'must' => [
103103
['range' => ['foo' => ['gte' => 0]]],
@@ -113,7 +113,7 @@ public function testWhereLt()
113113
$builder = (new FilterBuilder($this->mockModel()))
114114
->where('foo', '<', 0);
115115

116-
$this->assertEquals(
116+
$this->assertSame(
117117
[
118118
'must' => [
119119
['range' => ['foo' => ['lt' => 0]]],
@@ -129,7 +129,7 @@ public function testWhereLte()
129129
$builder = (new FilterBuilder($this->mockModel()))
130130
->where('foo', '>=', 0);
131131

132-
$this->assertEquals(
132+
$this->assertSame(
133133
[
134134
'must' => [
135135
['range' => ['foo' => ['gte' => 0]]],
@@ -145,7 +145,7 @@ public function testWhereIn()
145145
$builder = (new FilterBuilder($this->mockModel()))
146146
->whereIn('foo', [0, 1]);
147147

148-
$this->assertEquals(
148+
$this->assertSame(
149149
[
150150
'must' => [
151151
['terms' => ['foo' => [0, 1]]],
@@ -161,7 +161,7 @@ public function testWhereNotIn()
161161
$builder = (new FilterBuilder($this->mockModel()))
162162
->whereNotIn('foo', [0, 1]);
163163

164-
$this->assertEquals(
164+
$this->assertSame(
165165
[
166166
'must' => [],
167167
'must_not' => [
@@ -177,7 +177,7 @@ public function testWhereBetween()
177177
$builder = (new FilterBuilder($this->mockModel()))
178178
->whereBetween('foo', [0, 10]);
179179

180-
$this->assertEquals(
180+
$this->assertSame(
181181
[
182182
'must' => [
183183
['range' => ['foo' => ['gte' => 0, 'lte' => 10]]],
@@ -193,7 +193,7 @@ public function testWhereNotBetween()
193193
$builder = (new FilterBuilder($this->mockModel()))
194194
->whereNotBetween('foo', [0, 10]);
195195

196-
$this->assertEquals(
196+
$this->assertSame(
197197
[
198198
'must' => [],
199199
'must_not' => [
@@ -209,7 +209,7 @@ public function testWhereExists()
209209
$builder = (new FilterBuilder($this->mockModel()))
210210
->whereExists('foo');
211211

212-
$this->assertEquals(
212+
$this->assertSame(
213213
[
214214
'must' => [
215215
['exists' => ['field' => 'foo']],
@@ -225,7 +225,7 @@ public function testWhereNotExists()
225225
$builder = (new FilterBuilder($this->mockModel()))
226226
->whereNotExists('foo');
227227

228-
$this->assertEquals(
228+
$this->assertSame(
229229
[
230230
'must' => [],
231231
'must_not' => [
@@ -242,7 +242,7 @@ public function testWhereRegexp()
242242
->whereRegexp('foo', '.*')
243243
->whereRegexp('bar', '^test.*', 'EMPTY|NONE');
244244

245-
$this->assertEquals(
245+
$this->assertSame(
246246
[
247247
'must' => [
248248
['regexp' => ['foo' => ['value' => '.*', 'flags' => 'ALL']]],
@@ -279,7 +279,7 @@ function (FilterBuilder $builder) {
279279
}
280280
);
281281

282-
$this->assertEquals(
282+
$this->assertSame(
283283
[
284284
'must' => [
285285
['term' => ['case2' => 2]],
@@ -296,7 +296,7 @@ public function testWhereGeoDistance()
296296
$builder = (new FilterBuilder($this->mockModel()))
297297
->whereGeoDistance('foo', [-20, 30], '10m');
298298

299-
$this->assertEquals(
299+
$this->assertSame(
300300
[
301301
'must' => [
302302
['geo_distance' => ['distance' => '10m', 'foo' => [-20, 30]]],
@@ -312,7 +312,7 @@ public function testWhereGeoBoundingBox()
312312
$builder = (new FilterBuilder($this->mockModel()))
313313
->whereGeoBoundingBox('foo', ['top_left' => [-5, 10], 'bottom_right' => [-20, 30]]);
314314

315-
$this->assertEquals(
315+
$this->assertSame(
316316
[
317317
'must' => [
318318
['geo_bounding_box' => ['foo' => ['top_left' => [-5, 10], 'bottom_right' => [-20, 30]]]],
@@ -328,7 +328,7 @@ public function testWhereGeoPolygon()
328328
$builder = (new FilterBuilder($this->mockModel()))
329329
->whereGeoPolygon('foo', [[-70, 40], [-80, 30], [-90, 20]]);
330330

331-
$this->assertEquals(
331+
$this->assertSame(
332332
[
333333
'must' => [
334334
['geo_polygon' => ['foo' => ['points' => [[-70, 40], [-80, 30], [-90, 20]]]]],
@@ -355,7 +355,7 @@ public function testWhereGeoShape()
355355
$builder = (new FilterBuilder($this->mockModel()))
356356
->whereGeoShape('foo', $shape, $relation);
357357

358-
$this->assertEquals(
358+
$this->assertSame(
359359
[
360360
'must' => [
361361
[
@@ -379,7 +379,7 @@ public function testOrderBy()
379379
->orderBy('foo')
380380
->orderBy('bar', 'DESC');
381381

382-
$this->assertEquals(
382+
$this->assertSame(
383383
[
384384
['foo' => 'asc'],
385385
['bar' => 'desc'],
@@ -393,7 +393,7 @@ public function testWith()
393393
$builder = (new FilterBuilder($this->mockModel()))
394394
->with('RelatedModel');
395395

396-
$this->assertEquals(
396+
$this->assertSame(
397397
'RelatedModel',
398398
$builder->with
399399
);
@@ -403,14 +403,13 @@ public function testFrom()
403403
{
404404
$builder = new FilterBuilder($this->mockModel());
405405

406-
$this->assertEquals(
407-
0,
406+
$this->assertNull(
408407
$builder->offset
409408
);
410409

411410
$builder->from(100);
412411

413-
$this->assertEquals(
412+
$this->assertSame(
414413
100,
415414
$builder->offset
416415
);
@@ -421,7 +420,7 @@ public function testCollapse()
421420
$builder = (new FilterBuilder($this->mockModel()))
422421
->collapse('foo');
423422

424-
$this->assertEquals(
423+
$this->assertSame(
425424
'foo',
426425
$builder->collapse
427426
);
@@ -432,7 +431,7 @@ public function testSelect()
432431
$builder = (new FilterBuilder($this->mockModel()))
433432
->select(['foo', 'bar']);
434433

435-
$this->assertEquals(
434+
$this->assertSame(
436435
['foo', 'bar'],
437436
$builder->select
438437
);
@@ -444,7 +443,7 @@ public function testWithTrashed()
444443
->withTrashed()
445444
->where('foo', 'bar');
446445

447-
$this->assertEquals(
446+
$this->assertSame(
448447
[
449448
'must' => [
450449
[
@@ -465,7 +464,7 @@ public function testOnlyTrashed()
465464
->onlyTrashed()
466465
->where('foo', 'bar');
467466

468-
$this->assertEquals(
467+
$this->assertSame(
469468
[
470469
'must' => [
471470
[

tests/Builders/SearchBuilderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testRule()
2727

2828
$builder->rule(SearchRule::class)->rule($ruleFunc);
2929

30-
$this->assertEquals([
30+
$this->assertSame([
3131
SearchRule::class,
3232
$ruleFunc,
3333
], $builder->rules);

tests/ElasticEngineTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public function testMapIds()
298298
],
299299
];
300300

301-
$this->assertEquals(
301+
$this->assertSame(
302302
[1, 2],
303303
$this->engine->mapIds($results)->all()
304304
);
@@ -366,7 +366,7 @@ public function testMapWithoutTrashed()
366366
->disableOriginalConstructor()
367367
->getMock();
368368

369-
$this->assertEquals(
369+
$this->assertSame(
370370
[$model],
371371
$this->engine->map($builder, $results, $model)->all()
372372
);
@@ -434,7 +434,7 @@ public function testMapWithTrashed()
434434
->disableOriginalConstructor()
435435
->getMock();
436436

437-
$this->assertEquals(
437+
$this->assertSame(
438438
[$model],
439439
$this->engine->map($builder, $results, $model)->all()
440440
);
@@ -451,7 +451,7 @@ public function testGetTotalCount()
451451
],
452452
];
453453

454-
$this->assertEquals(
454+
$this->assertSame(
455455
100,
456456
$this->engine->getTotalCount($results)
457457
);

tests/HighlightTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public function testGetter()
1313
'description' => ['Description snippet 1', 'Description snippet 2'],
1414
]);
1515

16-
$this->assertEquals(
16+
$this->assertSame(
1717
['Title snippet 1'],
1818
$highlight->title
1919
);
2020

21-
$this->assertEquals(
21+
$this->assertSame(
2222
'Description snippet 1 Description snippet 2',
2323
$highlight->descriptionAsString
2424
);

tests/Payloads/DocumentPayloadTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function testDefault()
1616

1717
$payload = new DocumentPayload($model);
1818

19-
$this->assertEquals(
19+
$this->assertSame(
2020
[
2121
'index' => 'test',
2222
'type' => 'test',
@@ -43,7 +43,7 @@ public function testSet()
4343
->set('id', 2)
4444
->set('body', []);
4545

46-
$this->assertEquals(
46+
$this->assertSame(
4747
[
4848
'index' => 'foo',
4949
'type' => 'bar',

0 commit comments

Comments
 (0)