Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 16 additions & 11 deletions tests/HookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,32 @@ public function setUp(): void

public function testDescriptionCanBeSet()
{
$this->assertEquals('', $this->hook->getDesc());
$this->assertSame('', $this->hook->getDesc());

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

$this->assertEquals('new hook', $this->hook->getDesc());
$this->assertSame('new hook', $this->hook->getDesc());
}

public function testGroupsCanBeSet()
{
$this->assertEquals([], $this->hook->getGroups());
$this->assertSame([], $this->hook->getGroups());

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

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

public function testActionCanBeSet()
{
$this->hook->action(fn () => 'hello world');
$this->assertIsCallable($this->hook->getAction());
$this->assertEquals('hello world', $this->hook->getAction()());
$this->assertSame('hello world', $this->hook->getAction()());
}

public function testParamCanBeSet()
{
$this->assertEquals([], $this->hook->getParams());
$this->assertSame([], $this->hook->getParams());

$this->hook
->param('x', '', new Text(10))
Expand Down Expand Up @@ -89,12 +89,12 @@ public function testResourcesCanBeInjected()

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

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

public function testParamValuesCanBeSet()
{
$this->assertEquals([], $this->hook->getParams());
$this->assertSame([], $this->hook->getParams());

$values = [
'x' => 'hello',
Expand All @@ -105,13 +105,18 @@ public function testParamValuesCanBeSet()
->param('x', '', new Numeric())
->param('y', '', new Numeric());

foreach ($this->hook->getParams() as $key => $param) {
/**
* @var array $params
*/
$params = $this->hook->getParams();

foreach ($params as $key => $param) {
$this->hook->setParamValue($key, $values[$key]);
}

$this->assertCount(2, $this->hook->getParams());
$this->assertEquals('hello', $this->hook->getParams()['x']['value']);
$this->assertEquals('world', $this->hook->getParams()['y']['value']);
$this->assertSame('hello', $this->hook->getParams()['x']['value']);
$this->assertSame('world', $this->hook->getParams()['y']['value']);
}

public function tearDown(): void
Expand Down
50 changes: 25 additions & 25 deletions tests/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,21 @@ public function testCanGetDifferentModes(): void

Http::setMode(Http::MODE_TYPE_PRODUCTION);

$this->assertEquals(Http::MODE_TYPE_PRODUCTION, Http::getMode());
$this->assertSame(Http::MODE_TYPE_PRODUCTION, Http::getMode());
$this->assertTrue(Http::isProduction());
$this->assertFalse(Http::isDevelopment());
$this->assertFalse(Http::isStage());

Http::setMode(Http::MODE_TYPE_DEVELOPMENT);

$this->assertEquals(Http::MODE_TYPE_DEVELOPMENT, Http::getMode());
$this->assertSame(Http::MODE_TYPE_DEVELOPMENT, Http::getMode());
$this->assertFalse(Http::isProduction());
$this->assertTrue(Http::isDevelopment());
$this->assertFalse(Http::isStage());

Http::setMode(Http::MODE_TYPE_STAGE);

$this->assertEquals(Http::MODE_TYPE_STAGE, Http::getMode());
$this->assertSame(Http::MODE_TYPE_STAGE, Http::getMode());
$this->assertFalse(Http::isProduction());
$this->assertFalse(Http::isDevelopment());
$this->assertTrue(Http::isStage());
Expand Down Expand Up @@ -136,7 +136,7 @@ public function testCanExecuteRoute(): void
$result = \ob_get_contents();
\ob_end_clean();

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

public function testCanExecuteRouteWithParams(): void
Expand Down Expand Up @@ -191,7 +191,7 @@ public function testCanExecuteRouteWithParams(): void
$result = \ob_get_contents();
\ob_end_clean();
$resource = $context->get('rand');
$this->assertEquals($resource . '-param-x-param-y', $result);
$this->assertSame($resource . '-param-x-param-y', $result);
}

public function testCanExecuteRouteWithParamsWithError(): void
Expand Down Expand Up @@ -240,7 +240,7 @@ public function testCanExecuteRouteWithParamsWithError(): void
$result = \ob_get_contents();
\ob_end_clean();

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

public function testCanExecuteRouteWithParamsWithHooks(): void
Expand Down Expand Up @@ -345,7 +345,7 @@ public function testCanExecuteRouteWithParamsWithHooks(): void
$result = \ob_get_contents();
\ob_end_clean();

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

$context = clone $this->context;

Expand Down Expand Up @@ -376,7 +376,7 @@ public function testCanExecuteRouteWithParamsWithHooks(): void
$result = \ob_get_contents();
\ob_end_clean();

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

public function testCanAddAndExecuteHooks()
Expand Down Expand Up @@ -420,7 +420,7 @@ public function testCanAddAndExecuteHooks()
$this->http->run($context);
$result = \ob_get_contents();
\ob_end_clean();
$this->assertEquals('(init)-x-def-(shutdown)', $result);
$this->assertSame('(init)-x-def-(shutdown)', $result);

// Default Params
$route = $this->http->addRoute('GET', '/path-4');
Expand Down Expand Up @@ -450,7 +450,7 @@ public function testCanAddAndExecuteHooks()
$result = \ob_get_contents();
\ob_end_clean();

$this->assertEquals('x-def', $result);
$this->assertSame('x-def', $result);
}

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

// Test success
Expand Down Expand Up @@ -533,7 +533,7 @@ public function testCanHookThrowExceptions()
$result = \ob_get_contents();
\ob_end_clean();

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

$context = clone $this->context;

Expand All @@ -555,7 +555,7 @@ public function testCanHookThrowExceptions()
$result = \ob_get_contents();
\ob_end_clean();

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

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

$route = $this->http->match(new Request());
$this->assertEquals($expected, $route);
$this->assertSame($expected, $route);
}

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

$matched = $this->http->match(new Request());
$this->assertEquals($expected, $matched);
$this->assertSame($expected, $matched);
}

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

$matched = $this->http->match(new Request());
$this->assertEquals($expected, $matched);
$this->assertSame($expected, $matched);
}

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

$matched = $this->http->match(new Request());
$this->assertEquals($expected, $matched);
$this->assertSame($expected, $matched);
}

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

$matched = $this->http->match(new Request());
$this->assertEquals($expected, $matched);
$this->assertSame($expected, $matched);
}

public function testNoMismatchRoute(): void
Expand Down Expand Up @@ -697,8 +697,8 @@ public function testNoMismatchRoute(): void

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

$this->assertEquals($_SERVER['REQUEST_METHOD'], $context->get('route')->getMethod());
$this->assertEquals($_SERVER['REQUEST_URI'], $context->get('route')->getPath());
$this->assertSame($_SERVER['REQUEST_METHOD'], $context->get('route')->getMethod());
$this->assertSame($_SERVER['REQUEST_URI'], $context->get('route')->getPath());
}
}

Expand Down Expand Up @@ -778,15 +778,15 @@ public function testWildcardRoute(): void
$result = \ob_get_contents();
\ob_end_clean();

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

\ob_start();
$context->get('request')->setMethod('OPTIONS');
$this->http->run($context);
$result = \ob_get_contents();
\ob_end_clean();

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

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

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

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

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

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

$this->assertEquals('generated: generated-value', $result);
$this->assertSame('generated: generated-value', $result);
}
}
Loading