Bicycle/tests/Unit/CookieTest.php
Egor Isaev b516ca07dc Initial commit: Bicycle PHP MVC micro-framework
Core MVC, HTTP client, Session, Cookie, Config, HTTPException — 111 PHPUnit tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-04 10:04:19 +03:00

54 lines
1.4 KiB
PHP

<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
use System\Classes\Cookie;
class CookieTest extends TestCase
{
protected function setUp(): void
{
Cookie::$expiration = 0;
Cookie::$path = '/';
Cookie::$domain = null;
Cookie::$secure = false;
Cookie::$httponly = true;
Cookie::$samesite = 'Lax';
}
public function testGetReturnsNullWhenNotSet(): void
{
unset($_COOKIE['test_key']);
$this->assertNull(Cookie::get('test_key'));
}
public function testGetReturnsDefault(): void
{
unset($_COOKIE['test_key']);
$this->assertSame('default', Cookie::get('test_key', 'default'));
}
public function testGetReturnsValue(): void
{
$_COOKIE['test_key'] = 'hello';
$this->assertSame('hello', Cookie::get('test_key'));
unset($_COOKIE['test_key']);
}
public function testDeleteUnsetsFromGlobal(): void
{
$_COOKIE['to_delete'] = 'value';
Cookie::delete('to_delete');
$this->assertArrayNotHasKey('to_delete', $_COOKIE);
}
public function testDefaultsAreCorrect(): void
{
$this->assertSame('/', Cookie::$path);
$this->assertTrue(Cookie::$httponly);
$this->assertFalse(Cookie::$secure);
$this->assertSame('Lax', Cookie::$samesite);
}
}