Skip to content

Commit 2cbe028

Browse files
authored
[FEATURE] Add unit tests for the existing Settings methods (#449)
1 parent 79f7865 commit 2cbe028

File tree

2 files changed

+157
-0
lines changed

2 files changed

+157
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
77

88
### Added
99

10+
- Add more tests (#449)
11+
1012
### Changed
1113

1214
### Deprecated

tests/SettingsTest.php

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sabberworm\CSS\Tests;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Sabberworm\CSS\Settings;
9+
10+
/**
11+
* @covers \Sabberworm\CSS\Settings
12+
*/
13+
final class SettingsTest extends TestCase
14+
{
15+
/**
16+
* @var Settings
17+
*/
18+
private $subject;
19+
20+
protected function setUp(): void
21+
{
22+
$this->subject = Settings::create();
23+
}
24+
25+
/**
26+
* @test
27+
*/
28+
public function createReturnsInstance(): void
29+
{
30+
$settings = Settings::create();
31+
32+
self::assertInstanceOf(Settings::class, $settings);
33+
}
34+
35+
/**
36+
* @test
37+
*/
38+
public function createReturnsANewInstanceForEachCall(): void
39+
{
40+
$settings1 = Settings::create();
41+
$settings2 = Settings::create();
42+
43+
self::assertNotSame($settings1, $settings2);
44+
}
45+
46+
/**
47+
* @test
48+
*/
49+
public function multibyteSupportByDefaultStateOfMbStringExtension(): void
50+
{
51+
self::assertSame(extension_loaded('mbstring'), $this->subject->bMultibyteSupport);
52+
}
53+
54+
/**
55+
* @test
56+
*/
57+
public function withMultibyteSupportProvidesFluentInterface(): void
58+
{
59+
self::assertSame($this->subject, $this->subject->withMultibyteSupport());
60+
}
61+
62+
/**
63+
* @return array<string, array{0: bool}>
64+
*/
65+
public static function booleanDataProvider(): array
66+
{
67+
return [
68+
'true' => [true],
69+
'false' => [false],
70+
];
71+
}
72+
73+
/**
74+
* @test
75+
* @dataProvider booleanDataProvider
76+
*/
77+
public function withMultibyteSupportSetsMultibyteSupport(bool $value): void
78+
{
79+
$this->subject->withMultibyteSupport($value);
80+
81+
self::assertSame($value, $this->subject->bMultibyteSupport);
82+
}
83+
84+
/**
85+
* @test
86+
*/
87+
public function defaultCharsetByDefaultIsUtf8(): void
88+
{
89+
self::assertSame('utf-8', $this->subject->sDefaultCharset);
90+
}
91+
92+
/**
93+
* @test
94+
*/
95+
public function withDefaultCharsetProvidesFluentInterface(): void
96+
{
97+
self::assertSame($this->subject, $this->subject->withDefaultCharset('UTF-8'));
98+
}
99+
100+
/**
101+
* @test
102+
*/
103+
public function withDefaultCharsetSetsDefaultCharset(): void
104+
{
105+
$charset = 'ISO-8859-1';
106+
$this->subject->withDefaultCharset($charset);
107+
108+
self::assertSame($charset, $this->subject->sDefaultCharset);
109+
}
110+
111+
/**
112+
* @test
113+
*/
114+
public function lenientParsingByDefaultIsTrue(): void
115+
{
116+
self::assertTrue($this->subject->bLenientParsing);
117+
}
118+
119+
/**
120+
* @test
121+
*/
122+
public function withLenientParsingProvidesFluentInterface(): void
123+
{
124+
self::assertSame($this->subject, $this->subject->withLenientParsing());
125+
}
126+
127+
/**
128+
* @test
129+
* @dataProvider booleanDataProvider
130+
*/
131+
public function withLenientParsingSetsLenientParsing(bool $value): void
132+
{
133+
$this->subject->withLenientParsing($value);
134+
135+
self::assertSame($value, $this->subject->bLenientParsing);
136+
}
137+
138+
/**
139+
* @test
140+
*/
141+
public function beStrictProvidesFluentInterface(): void
142+
{
143+
self::assertSame($this->subject, $this->subject->beStrict());
144+
}
145+
146+
/**
147+
* @test
148+
*/
149+
public function beStrictSetsLenientParsingToFalse(): void
150+
{
151+
$this->subject->beStrict();
152+
153+
self::assertFalse($this->subject->bLenientParsing);
154+
}
155+
}

0 commit comments

Comments
 (0)