Skip to content

Commit 85b6c3b

Browse files
Merge pull request #194 from utopia-php/chore-assert-same
Replace assertEquals with assertSame
2 parents cb01940 + d83d86a commit 85b6c3b

File tree

9 files changed

+233
-228
lines changed

9 files changed

+233
-228
lines changed

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/HookTest.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,32 @@ public function setUp(): void
2222

2323
public function testDescriptionCanBeSet()
2424
{
25-
$this->assertEquals('', $this->hook->getDesc());
25+
$this->assertSame('', $this->hook->getDesc());
2626

2727
$this->hook->desc('new hook');
2828

29-
$this->assertEquals('new hook', $this->hook->getDesc());
29+
$this->assertSame('new hook', $this->hook->getDesc());
3030
}
3131

3232
public function testGroupsCanBeSet()
3333
{
34-
$this->assertEquals([], $this->hook->getGroups());
34+
$this->assertSame([], $this->hook->getGroups());
3535

3636
$this->hook->groups(['api', 'homepage']);
3737

38-
$this->assertEquals(['api', 'homepage'], $this->hook->getGroups());
38+
$this->assertSame(['api', 'homepage'], $this->hook->getGroups());
3939
}
4040

4141
public function testActionCanBeSet()
4242
{
4343
$this->hook->action(fn () => 'hello world');
4444
$this->assertIsCallable($this->hook->getAction());
45-
$this->assertEquals('hello world', $this->hook->getAction()());
45+
$this->assertSame('hello world', $this->hook->getAction()());
4646
}
4747

4848
public function testParamCanBeSet()
4949
{
50-
$this->assertEquals([], $this->hook->getParams());
50+
$this->assertSame([], $this->hook->getParams());
5151

5252
$this->hook
5353
->param('x', '', new Text(10))
@@ -89,12 +89,12 @@ public function testResourcesCanBeInjected()
8989

9090
$result = $context->inject($main);
9191

92-
$this->assertEquals('user:00:00:00', $result);
92+
$this->assertSame('user:00:00:00', $result);
9393
}
9494

9595
public function testParamValuesCanBeSet()
9696
{
97-
$this->assertEquals([], $this->hook->getParams());
97+
$this->assertSame([], $this->hook->getParams());
9898

9999
$values = [
100100
'x' => 'hello',
@@ -105,13 +105,18 @@ public function testParamValuesCanBeSet()
105105
->param('x', '', new Numeric())
106106
->param('y', '', new Numeric());
107107

108-
foreach ($this->hook->getParams() as $key => $param) {
108+
/**
109+
* @var array $params
110+
*/
111+
$params = $this->hook->getParams();
112+
113+
foreach ($params as $key => $param) {
109114
$this->hook->setParamValue($key, $values[$key]);
110115
}
111116

112117
$this->assertCount(2, $this->hook->getParams());
113-
$this->assertEquals('hello', $this->hook->getParams()['x']['value']);
114-
$this->assertEquals('world', $this->hook->getParams()['y']['value']);
118+
$this->assertSame('hello', $this->hook->getParams()['x']['value']);
119+
$this->assertSame('world', $this->hook->getParams()['y']['value']);
115120
}
116121

117122
public function tearDown(): void

tests/HttpTest.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,21 @@ public function testCanGetDifferentModes(): void
7777

7878
Http::setMode(Http::MODE_TYPE_PRODUCTION);
7979

80-
$this->assertEquals(Http::MODE_TYPE_PRODUCTION, Http::getMode());
80+
$this->assertSame(Http::MODE_TYPE_PRODUCTION, Http::getMode());
8181
$this->assertTrue(Http::isProduction());
8282
$this->assertFalse(Http::isDevelopment());
8383
$this->assertFalse(Http::isStage());
8484

8585
Http::setMode(Http::MODE_TYPE_DEVELOPMENT);
8686

87-
$this->assertEquals(Http::MODE_TYPE_DEVELOPMENT, Http::getMode());
87+
$this->assertSame(Http::MODE_TYPE_DEVELOPMENT, Http::getMode());
8888
$this->assertFalse(Http::isProduction());
8989
$this->assertTrue(Http::isDevelopment());
9090
$this->assertFalse(Http::isStage());
9191

9292
Http::setMode(Http::MODE_TYPE_STAGE);
9393

94-
$this->assertEquals(Http::MODE_TYPE_STAGE, Http::getMode());
94+
$this->assertSame(Http::MODE_TYPE_STAGE, Http::getMode());
9595
$this->assertFalse(Http::isProduction());
9696
$this->assertFalse(Http::isDevelopment());
9797
$this->assertTrue(Http::isStage());
@@ -136,7 +136,7 @@ public function testCanExecuteRoute(): void
136136
$result = \ob_get_contents();
137137
\ob_end_clean();
138138

139-
$this->assertEquals('x-def-y-def', $result);
139+
$this->assertSame('x-def-y-def', $result);
140140
}
141141

142142
public function testCanExecuteRouteWithParams(): void
@@ -191,7 +191,7 @@ public function testCanExecuteRouteWithParams(): void
191191
$result = \ob_get_contents();
192192
\ob_end_clean();
193193
$resource = $context->get('rand');
194-
$this->assertEquals($resource . '-param-x-param-y', $result);
194+
$this->assertSame($resource . '-param-x-param-y', $result);
195195
}
196196

197197
public function testCanExecuteRouteWithParamsWithError(): void
@@ -240,7 +240,7 @@ public function testCanExecuteRouteWithParamsWithError(): void
240240
$result = \ob_get_contents();
241241
\ob_end_clean();
242242

243-
$this->assertEquals('error: Invalid `x` param: Value must be a valid string and no longer than 1 chars', $result);
243+
$this->assertSame('error: Invalid `x` param: Value must be a valid string and no longer than 1 chars', $result);
244244
}
245245

246246
public function testCanExecuteRouteWithParamsWithHooks(): void
@@ -345,7 +345,7 @@ public function testCanExecuteRouteWithParamsWithHooks(): void
345345
$result = \ob_get_contents();
346346
\ob_end_clean();
347347

348-
$this->assertEquals('init-' . $resource . '-(init-api)-param-x-param-y-(shutdown-api)-shutdown', $result);
348+
$this->assertSame('init-' . $resource . '-(init-api)-param-x-param-y-(shutdown-api)-shutdown', $result);
349349

350350
$context = clone $this->context;
351351

@@ -376,7 +376,7 @@ public function testCanExecuteRouteWithParamsWithHooks(): void
376376
$result = \ob_get_contents();
377377
\ob_end_clean();
378378

379-
$this->assertEquals('init-' . $resource . '-(init-homepage)-param-x*param-y-(shutdown-homepage)-shutdown', $result);
379+
$this->assertSame('init-' . $resource . '-(init-homepage)-param-x*param-y-(shutdown-homepage)-shutdown', $result);
380380
}
381381

382382
public function testCanAddAndExecuteHooks()
@@ -420,7 +420,7 @@ public function testCanAddAndExecuteHooks()
420420
$this->http->run($context);
421421
$result = \ob_get_contents();
422422
\ob_end_clean();
423-
$this->assertEquals('(init)-x-def-(shutdown)', $result);
423+
$this->assertSame('(init)-x-def-(shutdown)', $result);
424424

425425
// Default Params
426426
$route = $this->http->addRoute('GET', '/path-4');
@@ -450,7 +450,7 @@ public function testCanAddAndExecuteHooks()
450450
$result = \ob_get_contents();
451451
\ob_end_clean();
452452

453-
$this->assertEquals('x-def', $result);
453+
$this->assertSame('x-def', $result);
454454
}
455455

456456
public function testAllowRouteOverrides()
@@ -468,7 +468,7 @@ public function testAllowRouteOverrides()
468468
$this->fail('Failed to throw exception');
469469
} catch (\Exception $e) {
470470
// Threw exception as expected
471-
$this->assertEquals('Route for (GET:) already registered.', $e->getMessage());
471+
$this->assertSame('Route for (GET:) already registered.', $e->getMessage());
472472
}
473473

474474
// Test success
@@ -533,7 +533,7 @@ public function testCanHookThrowExceptions()
533533
$result = \ob_get_contents();
534534
\ob_end_clean();
535535

536-
$this->assertEquals('error: Param "y" is not optional.', $result);
536+
$this->assertSame('error: Param "y" is not optional.', $result);
537537

538538
$context = clone $this->context;
539539

@@ -555,7 +555,7 @@ public function testCanHookThrowExceptions()
555555
$result = \ob_get_contents();
556556
\ob_end_clean();
557557

558-
$this->assertEquals('(init)-y-def-x-def-(shutdown)', $result);
558+
$this->assertSame('(init)-y-def-x-def-(shutdown)', $result);
559559
}
560560

561561
public function providerRouteMatching(): array
@@ -606,7 +606,7 @@ public function testCanMatchRoute(string $method, string $path, ?string $url = n
606606
$_SERVER['REQUEST_URI'] = $url;
607607

608608
$route = $this->http->match(new Request());
609-
$this->assertEquals($expected, $route);
609+
$this->assertSame($expected, $route);
610610
}
611611

612612
public function testMatchWithNullPath(): void
@@ -619,7 +619,7 @@ public function testMatchWithNullPath(): void
619619
$_SERVER['REQUEST_URI'] = '?param=1'; // This will cause parse_url to return null for PATH component
620620

621621
$matched = $this->http->match(new Request());
622-
$this->assertEquals($expected, $matched);
622+
$this->assertSame($expected, $matched);
623623
}
624624

625625
public function testMatchWithEmptyPath(): void
@@ -632,7 +632,7 @@ public function testMatchWithEmptyPath(): void
632632
$_SERVER['REQUEST_URI'] = 'https://example.com'; // No path component
633633

634634
$matched = $this->http->match(new Request());
635-
$this->assertEquals($expected, $matched);
635+
$this->assertSame($expected, $matched);
636636
}
637637

638638
public function testMatchWithMalformedURL(): void
@@ -645,7 +645,7 @@ public function testMatchWithMalformedURL(): void
645645
$_SERVER['REQUEST_URI'] = '#fragment'; // Malformed scheme
646646

647647
$matched = $this->http->match(new Request());
648-
$this->assertEquals($expected, $matched);
648+
$this->assertSame($expected, $matched);
649649
}
650650

651651
public function testMatchWithOnlyQueryString(): void
@@ -658,7 +658,7 @@ public function testMatchWithOnlyQueryString(): void
658658
$_SERVER['REQUEST_URI'] = '?param=value'; // Only query string, no path
659659

660660
$matched = $this->http->match(new Request());
661-
$this->assertEquals($expected, $matched);
661+
$this->assertSame($expected, $matched);
662662
}
663663

664664
public function testNoMismatchRoute(): void
@@ -697,8 +697,8 @@ public function testNoMismatchRoute(): void
697697

698698
$this->http->run($context);
699699

700-
$this->assertEquals($_SERVER['REQUEST_METHOD'], $context->get('route')->getMethod());
701-
$this->assertEquals($_SERVER['REQUEST_URI'], $context->get('route')->getPath());
700+
$this->assertSame($_SERVER['REQUEST_METHOD'], $context->get('route')->getMethod());
701+
$this->assertSame($_SERVER['REQUEST_URI'], $context->get('route')->getPath());
702702
}
703703
}
704704

@@ -778,15 +778,15 @@ public function testWildcardRoute(): void
778778
$result = \ob_get_contents();
779779
\ob_end_clean();
780780

781-
$this->assertEquals('HELLO', $result);
781+
$this->assertSame('HELLO', $result);
782782

783783
\ob_start();
784784
$context->get('request')->setMethod('OPTIONS');
785785
$this->http->run($context);
786786
$result = \ob_get_contents();
787787
\ob_end_clean();
788788

789-
$this->assertEquals('', $result);
789+
$this->assertSame('', $result);
790790

791791
$_SERVER['REQUEST_METHOD'] = $method;
792792
$_SERVER['REQUEST_URI'] = $uri;
@@ -811,7 +811,7 @@ public function testCallableStringParametersNotExecuted(): void
811811
$result = \ob_get_contents();
812812
\ob_end_clean();
813813

814-
$this->assertEquals('callback-value: phpinfo', $result);
814+
$this->assertSame('callback-value: phpinfo', $result);
815815

816816
// Test with request parameter that is a callable string
817817
$route2 = new Route('GET', '/test-callable-string-param');
@@ -830,7 +830,7 @@ public function testCallableStringParametersNotExecuted(): void
830830
$result = \ob_get_contents();
831831
\ob_end_clean();
832832

833-
$this->assertEquals('func-value: system', $result);
833+
$this->assertSame('func-value: system', $result);
834834

835835
// Test callable closure still works
836836
$route3 = new Route('GET', '/test-callable-closure');
@@ -849,6 +849,6 @@ public function testCallableStringParametersNotExecuted(): void
849849
$result = \ob_get_contents();
850850
\ob_end_clean();
851851

852-
$this->assertEquals('generated: generated-value', $result);
852+
$this->assertSame('generated: generated-value', $result);
853853
}
854854
}

0 commit comments

Comments
 (0)