Skip to content

Commit

Permalink
Fix RiskyTruthyFalsyComparison issues
Browse files Browse the repository at this point in the history
Signed-off-by: George Steel <[email protected]>
  • Loading branch information
gsteel committed Feb 8, 2024
1 parent fff95e0 commit 7342b0b
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions test/PhpSessionPersistenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use function ini_set;
use function is_bool;
use function is_dir;
use function is_string;
use function mkdir;
use function session_id;
use function session_name;
Expand Down Expand Up @@ -89,7 +90,7 @@ protected function tearDown(): void

// remove old session test files if any
$files = glob("{$this->sessionSavePath}/sess_*");
if ($files) {
if ($files !== false) {
foreach ($files as $file) {
unlink($file);
}
Expand All @@ -98,7 +99,7 @@ protected function tearDown(): void

public function startSession(?string $id = null, array $options = []): void
{
$id = $id ?: 'testing';
$id ??= 'testing';
session_id($id);
session_start([
'use_cookies' => false,
Expand All @@ -115,8 +116,8 @@ private function createSessionCookieRequest(
$request = FigRequestCookies::set(
new ServerRequest($serverParams),
Cookie::create(
$sessionName ?: session_name(),
$sessionId ?: 'testing'
$sessionName ?? session_name(),
$sessionId ?? 'testing'
)
);

Expand Down Expand Up @@ -280,7 +281,9 @@ public function testPersistSessionReturnsResponseWithSetCookieHeaderIfSessionCoo
$this->assertSame(ini_get('session.cookie_path'), $setCookie->getPath());

// @see https://github.com/zendframework/zend-expressive-session-ext/pull/31
$this->assertSame(ini_get('session.cookie_domain') ?: null, $setCookie->getDomain());
$iniDomain = ini_get('session.cookie_domain');
$expectDomain = $iniDomain !== false && $iniDomain !== '' ? $iniDomain : null;
$this->assertSame($expectDomain, $setCookie->getDomain());
$this->assertSame((bool) ini_get('session.cookie_secure'), $setCookie->getSecure());
$this->assertSame((bool) ini_get('session.cookie_httponly'), $setCookie->getHttpOnly());
}
Expand Down Expand Up @@ -578,7 +581,7 @@ public function testCookieHasSameSite(?string $sameSite): void

$cookie = $response->getHeaderLine('Set-Cookie');

if ($sameSite) {
if (is_string($sameSite) && $sameSite !== '') {
self::assertStringContainsStringIgnoringCase('SameSite=' . $sameSite, $cookie);
} else {
self::assertStringNotContainsStringIgnoringCase('SameSite=', $cookie);
Expand Down Expand Up @@ -1044,8 +1047,12 @@ public function testRegenerateWhenSessionAlreadyActiveDestroyExistingSessionFirs
{
session_start();

$path = session_save_path() !== false
? session_save_path()
: sys_get_temp_dir();

$_SESSION['test'] = 'value';
$fileSession = (session_save_path() ?: sys_get_temp_dir()) . '/sess_' . session_id();
$fileSession = $path . '/sess_' . session_id();

$this->assertFileExists($fileSession);

Expand Down Expand Up @@ -1100,6 +1107,6 @@ private function getExpectedLastModified()
$lastmod = filemtime($classFile);
}

return $lastmod ? gmdate(Http::DATE_FORMAT, $lastmod) : false;
return $lastmod !== false ? gmdate(Http::DATE_FORMAT, $lastmod) : false;
}
}

0 comments on commit 7342b0b

Please sign in to comment.