Skip to content

Commit 9afa2fd

Browse files
author
Petar Pavlović
committed
Added more unit tests
1 parent 4ec8d31 commit 9afa2fd

2 files changed

Lines changed: 131 additions & 6 deletions

File tree

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,22 @@
4343
},
4444
"scripts": {
4545
"unit-test": [
46-
"./vendor/bin/phpunit -c tests/unit/phpunit.xml --colors=always --coverage-html tests/unit/coverage"
46+
"XDEBUG_MODE=coverage php8.3 ./vendor/bin/phpunit -c tests/unit/phpunit.xml --colors=always --coverage-html tests/unit/coverage"
4747
],
4848
"test-coverage": [
49-
"./vendor/bin/phpunit --colors=always -c tests/unit/phpunit.xml --coverage-text"
49+
"XDEBUG_MODE=coverage php8.3 ./vendor/bin/phpunit --colors=always -c tests/unit/phpunit.xml --coverage-text"
5050
],
5151
"test-report": [
52-
"./vendor/bin/phpunit --colors=always -c tests/unit/phpunit.xml --coverage-clover=tests/unit/coverage/code-coverage.xml"
52+
"XDEBUG_MODE=coverage php8.3 ./vendor/bin/phpunit --colors=always -c tests/unit/phpunit.xml --coverage-clover=tests/unit/coverage/code-coverage.xml"
5353
],
5454
"code-coverage": [
55-
"./vendor/bin/code-coverage -p 90 -f tests/unit/coverage/code-coverage.xml"
55+
"XDEBUG_MODE=coverage php8.3 ./vendor/bin/code-coverage -p 90 -f tests/unit/coverage/code-coverage.xml"
5656
],
5757
"psr2": [
58-
"./vendor/bin/phpcs --colors --standard=PSR2 src/"
58+
"XDEBUG_MODE=coverage php8.3 ./vendor/bin/phpcs --colors --standard=PSR2 src/"
5959
],
6060
"psr2-fix": [
61-
"./vendor/bin/phpcbf --colors --standard=PSR2 src/"
61+
"XDEBUG_MODE=coverage php8.3 ./vendor/bin/phpcbf --colors --standard=PSR2 src/"
6262
]
6363
}
6464
}

tests/unit/src/SessionTest.php

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,131 @@ public function testGetDomainNameException()
2929
$this->session->getDomainName();
3030
}
3131

32+
public function testCookiePathDefault()
33+
{
34+
$reflection = new \ReflectionClass($this->session);
35+
$property = $reflection->getProperty('cookiePath');
36+
$property->setAccessible(true);
37+
$this->assertEquals('/', $property->getValue($this->session));
38+
}
39+
40+
public function testCookiePathSetter()
41+
{
42+
$result = $this->session->cookiePath('/custom/path');
43+
$this->assertInstanceOf(Session::class, $result);
44+
45+
$reflection = new \ReflectionClass($this->session);
46+
$property = $reflection->getProperty('cookiePath');
47+
$property->setAccessible(true);
48+
$this->assertEquals('/custom/path', $property->getValue($this->session));
49+
}
50+
51+
public function testCookieHttpOnlyDefault()
52+
{
53+
$reflection = new \ReflectionClass($this->session);
54+
$property = $reflection->getProperty('cookieHttpOnly');
55+
$property->setAccessible(true);
56+
$this->assertFalse($property->getValue($this->session));
57+
}
58+
59+
public function testCookieHttpOnlySetter()
60+
{
61+
$result = $this->session->cookieHttpOnly(true);
62+
$this->assertInstanceOf(Session::class, $result);
63+
64+
$reflection = new \ReflectionClass($this->session);
65+
$property = $reflection->getProperty('cookieHttpOnly');
66+
$property->setAccessible(true);
67+
$this->assertTrue($property->getValue($this->session));
68+
}
69+
70+
public function testCookieSecureDefault()
71+
{
72+
$reflection = new \ReflectionClass($this->session);
73+
$property = $reflection->getProperty('cookieSecure');
74+
$property->setAccessible(true);
75+
$this->assertFalse($property->getValue($this->session));
76+
}
77+
78+
public function testCookieSecureSetter()
79+
{
80+
$result = $this->session->cookieSecure(true);
81+
$this->assertInstanceOf(Session::class, $result);
82+
83+
$reflection = new \ReflectionClass($this->session);
84+
$property = $reflection->getProperty('cookieSecure');
85+
$property->setAccessible(true);
86+
$this->assertTrue($property->getValue($this->session));
87+
}
88+
89+
public function testCookieSameSiteDefault()
90+
{
91+
$reflection = new \ReflectionClass($this->session);
92+
$property = $reflection->getProperty('cookieSameSite');
93+
$property->setAccessible(true);
94+
$this->assertEquals('', $property->getValue($this->session));
95+
}
96+
97+
public function testCookieSameSiteSetterWithEmptyString()
98+
{
99+
$result = $this->session->cookieSameSite('');
100+
$this->assertInstanceOf(Session::class, $result);
101+
102+
$reflection = new \ReflectionClass($this->session);
103+
$property = $reflection->getProperty('cookieSameSite');
104+
$property->setAccessible(true);
105+
$this->assertEquals('', $property->getValue($this->session));
106+
}
107+
108+
public function testCookieSameSiteSetterWithLax()
109+
{
110+
$result = $this->session->cookieSameSite('Lax');
111+
$this->assertInstanceOf(Session::class, $result);
112+
113+
$reflection = new \ReflectionClass($this->session);
114+
$property = $reflection->getProperty('cookieSameSite');
115+
$property->setAccessible(true);
116+
$this->assertEquals('Lax', $property->getValue($this->session));
117+
}
118+
119+
public function testCookieSameSiteSetterWithStrict()
120+
{
121+
$result = $this->session->cookieSameSite('Strict');
122+
$this->assertInstanceOf(Session::class, $result);
123+
124+
$reflection = new \ReflectionClass($this->session);
125+
$property = $reflection->getProperty('cookieSameSite');
126+
$property->setAccessible(true);
127+
$this->assertEquals('Strict', $property->getValue($this->session));
128+
}
129+
130+
public function testCookieSameSiteSetterWithInvalidValue()
131+
{
132+
$this->expectException(\InvalidArgumentException::class);
133+
$this->expectExceptionMessage('Invalid value for cookieSameSite');
134+
$this->session->cookieSameSite('None');
135+
}
136+
137+
public function testCookieSameSiteSetterWithInvalidValueRandom()
138+
{
139+
$this->expectException(\InvalidArgumentException::class);
140+
$this->expectExceptionMessage('Invalid value for cookieSameSite');
141+
$this->session->cookieSameSite('InvalidValue');
142+
}
143+
144+
public function testFluentInterfaceChaining()
145+
{
146+
$result = $this->session
147+
->setDomainName('example.com')
148+
->cookiePath('/app')
149+
->cookieHttpOnly(true)
150+
->cookieSecure(true)
151+
->cookieSameSite('Strict');
152+
153+
$this->assertInstanceOf(Session::class, $result);
154+
$this->assertEquals('example.com', $this->session->getDomainName());
155+
}
156+
32157
protected function setUp(): void
33158
{
34159
$this->session = new Session([]);

0 commit comments

Comments
 (0)