Skip to content

Commit 0be7a76

Browse files
author
nejc
committed
fix: align ByteTest to expect OutOfRangeException for invalid byte values
1 parent 947a9bf commit 0be7a76

File tree

99 files changed

+4322
-847
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+4322
-847
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ yarn-error.log
1919
/.vscode
2020
vendor
2121
vendor/
22-
composer.lock
22+
composer.lock
23+
todo.txt

Tests/ByteSliceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Nejcc\PhpDatatypes\Tests;
@@ -7,7 +8,7 @@
78
use Nejcc\PhpDatatypes\Exceptions\InvalidByteException;
89
use PHPUnit\Framework\TestCase;
910

10-
class ByteSliceTest extends TestCase
11+
final class ByteSliceTest extends TestCase
1112
{
1213
/**
1314
* Test creating a valid ByteSlice instance.
@@ -128,4 +129,3 @@ public function testEmptyByteSlice(): void
128129
$this->assertCount(0, $byteSlice);
129130
}
130131
}
131-

Tests/ByteTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
use Nejcc\PhpDatatypes\Scalar\Byte;
88
use PHPUnit\Framework\TestCase;
99

10-
class ByteTest extends TestCase
10+
final class ByteTest extends TestCase
1111
{
1212
/**
1313
* Test that the constructor throws an exception when the value is out of range.
1414
*/
15-
public function testConstructorThrowsExceptionOnInvalidValue()
15+
public function testConstructorThrowsExceptionOnInvalidValue(): void
1616
{
17-
$this->expectException(\InvalidArgumentException::class);
18-
new Byte(300); // Out of range value
17+
$this->expectException(\OutOfRangeException::class);
18+
new Byte(300);
1919
}
2020

2121
/**

Tests/CharTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Nejcc\PhpDatatypes\Scalar\Char;
88
use PHPUnit\Framework\TestCase;
99

10-
class CharTest extends TestCase
10+
final class CharTest extends TestCase
1111
{
1212
/**
1313
* Test that the constructor throws an exception for a string longer than 1 character.

Tests/DictionaryTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Nejcc\PhpDatatypes\Tests;
@@ -8,7 +9,7 @@
89
use OutOfBoundsException;
910
use PHPUnit\Framework\TestCase;
1011

11-
class DictionaryTest extends TestCase
12+
final class DictionaryTest extends TestCase
1213
{
1314
public function testCanInitializeWithElements()
1415
{

Tests/FloatArrayTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Nejcc\PhpDatatypes\Tests;
@@ -7,10 +8,11 @@
78
use Nejcc\PhpDatatypes\Exceptions\InvalidFloatException;
89
use PHPUnit\Framework\TestCase;
910

10-
class FloatArrayTest extends TestCase
11+
final class FloatArrayTest extends TestCase
1112
{
1213
/**
1314
* Test creating a valid FloatArray instance.
15+
*
1416
* @throws InvalidFloatException
1517
*/
1618
public function testCreateValidFloatArray(): void
@@ -32,6 +34,7 @@ public function testCreateInvalidFloatArray(): void
3234

3335
/**
3436
* Test adding floats to a FloatArray.
37+
*
3538
* @throws InvalidFloatException
3639
*/
3740
public function testAddFloats(): void
@@ -44,6 +47,7 @@ public function testAddFloats(): void
4447

4548
/**
4649
* Test removing floats from a FloatArray.
50+
*
4751
* @throws InvalidFloatException
4852
*/
4953
public function testRemoveFloats(): void
@@ -56,6 +60,7 @@ public function testRemoveFloats(): void
5660

5761
/**
5862
* Test calculating the sum of floats.
63+
*
5964
* @throws InvalidFloatException
6065
*/
6166
public function testSumOfFloats(): void
@@ -66,6 +71,7 @@ public function testSumOfFloats(): void
6671

6772
/**
6873
* Test calculating the average of floats.
74+
*
6975
* @throws InvalidFloatException
7076
*/
7177
public function testAverageOfFloats(): void
@@ -88,6 +94,7 @@ public function testAverageOfEmptyFloatArray(): void
8894

8995
/**
9096
* Test getting the count of floats in a FloatArray.
97+
*
9198
* @throws InvalidFloatException
9299
*/
93100
public function testGetFloatCount(): void
@@ -98,6 +105,7 @@ public function testGetFloatCount(): void
98105

99106
/**
100107
* Test ArrayAccess implementation for accessing a float at a specific index.
108+
*
101109
* @throws InvalidFloatException
102110
*/
103111
public function testArrayAccessGet(): void
@@ -133,6 +141,7 @@ public function testArrayAccessUnsetThrowsException(): void
133141

134142
/**
135143
* Test iterating over FloatArray with IteratorAggregate.
144+
*
136145
* @throws InvalidFloatException
137146
*/
138147
public function testIterationOverFloatArray(): void
@@ -149,6 +158,7 @@ public function testIterationOverFloatArray(): void
149158

150159
/**
151160
* Test creating an empty FloatArray.
161+
*
152162
* @throws InvalidFloatException
153163
*/
154164
public function testEmptyFloatArray(): void

Tests/Floats/Float64Test.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Nejcc\PhpDatatypes\Tests;
66

7-
87
use Nejcc\PhpDatatypes\Scalar\FloatingPoints\Float64;
98
use PHPUnit\Framework\TestCase;
109

Tests/HttpStatusCodeTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3-
namespace Nejcc\PhpDatatypes\Tests;
4-
3+
declare(strict_types=1);
54

5+
namespace Nejcc\PhpDatatypes\Tests;
66

77
use Nejcc\PhpDatatypes\Enums\Http\HttpStatusCode;
88
use PHPUnit\Framework\TestCase;
99

10-
class HttpStatusCodeTest extends TestCase
10+
final class HttpStatusCodeTest extends TestCase
1111
{
1212
public function testIsInformational()
1313
{

Tests/IntArrayTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Nejcc\PhpDatatypes\Composite\Arrays\IntArray;
66
use PHPUnit\Framework\TestCase;
77

8-
class IntArrayTest extends TestCase
8+
final class IntArrayTest extends TestCase
99
{
1010
public function testConstructionAndGet(): void
1111
{
@@ -77,4 +77,4 @@ public function testAppendInvalidType(): void
7777
$this->expectException(\TypeError::class);
7878
$arr->append('not an int');
7979
}
80-
}
80+
}

Tests/Integers/Signed/Int16Test.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
namespace Nejcc\PhpDatatypes\Tests\Integers\Signed;
66

7-
87
use Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int16;
98
use PHPUnit\Framework\TestCase;
109

11-
class Int16Test extends TestCase
10+
final class Int16Test extends TestCase
1211
{
1312
public function testValidInitialization()
1413
{

Tests/Integers/Signed/Int32Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int32;
88
use PHPUnit\Framework\TestCase;
99

10-
class Int32Test extends TestCase
10+
final class Int32Test extends TestCase
1111
{
1212
public function testValidInitialization()
1313
{

Tests/Integers/Signed/Int8Test.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
namespace Nejcc\PhpDatatypes\Tests\Integers\Signed;
66

7-
87
use Nejcc\PhpDatatypes\Scalar\Integers\Signed\Int8;
98
use PHPUnit\Framework\TestCase;
109

11-
class Int8Test extends TestCase
10+
final class Int8Test extends TestCase
1211
{
1312
public function testValidInitialization()
1413
{

Tests/Integers/Unsigned/UInt16Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Nejcc\PhpDatatypes\Scalar\Integers\Unsigned\UInt16;
88
use PHPUnit\Framework\TestCase;
99

10-
class UInt16Test extends TestCase
10+
final class UInt16Test extends TestCase
1111
{
1212
public function testValidInitialization()
1313
{

Tests/Integers/Unsigned/UInt32Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Nejcc\PhpDatatypes\Scalar\Integers\Unsigned\UInt32;
88
use PHPUnit\Framework\TestCase;
99

10-
class UInt32Test extends TestCase
10+
final class UInt32Test extends TestCase
1111
{
1212
public function testValidInitialization()
1313
{

Tests/Integers/Unsigned/UInt8Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Nejcc\PhpDatatypes\Scalar\Integers\Unsigned\UInt8;
88
use PHPUnit\Framework\TestCase;
99

10-
class UInt8Test extends TestCase
10+
final class UInt8Test extends TestCase
1111
{
1212
public function testValidInitialization()
1313
{

Tests/JsonTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
declare(strict_types=1);
44

55
use Nejcc\PhpDatatypes\Composite\Json;
6-
use Nejcc\PhpDatatypes\Interfaces\EncoderInterface;
76
use Nejcc\PhpDatatypes\Interfaces\DecoderInterface;
7+
use Nejcc\PhpDatatypes\Interfaces\EncoderInterface;
88
use PHPUnit\Framework\TestCase;
99

10-
class JsonTest extends TestCase
10+
final class JsonTest extends TestCase
1111
{
1212
public function testValidJsonConstruction(): void
1313
{
@@ -45,11 +45,17 @@ public function testFromArrayAndFromObject(): void
4545
public function testCompressAndDecompress(): void
4646
{
4747
$json = new Json('{"a":1}');
48-
$encoder = new class implements EncoderInterface {
49-
public function encode(string $data): string { return base64_encode($data); }
48+
$encoder = new class () implements EncoderInterface {
49+
public function encode(string $data): string
50+
{
51+
return base64_encode($data);
52+
}
5053
};
51-
$decoder = new class implements DecoderInterface {
52-
public function decode(string $data): string { return base64_decode($data); }
54+
$decoder = new class () implements DecoderInterface {
55+
public function decode(string $data): string
56+
{
57+
return base64_decode($data);
58+
}
5359
};
5460
$compressed = $json->compress($encoder);
5561
$this->assertSame(base64_encode('{"a":1}'), $compressed);
@@ -79,4 +85,4 @@ public function testFromArrayInvalid(): void
7985
$this->expectException(JsonException::class);
8086
Json::fromArray(["bad" => fopen('php://memory', 'r')]);
8187
}
82-
}
88+
}

Tests/ListDataTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
use Nejcc\PhpDatatypes\Composite\ListData;
88
use OutOfBoundsException;
99
use PHPUnit\Framework\TestCase;
10-
class ListDataTest extends TestCase
10+
11+
final class ListDataTest extends TestCase
1112
{
1213
public function testCanInitializeWithElements()
1314
{

Tests/Scalar/BooleanTest.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Scalar;
6+
7+
use Nejcc\PhpDatatypes\Scalar\Boolean;
8+
use PHPUnit\Framework\TestCase;
9+
10+
final class BooleanTest extends TestCase
11+
{
12+
public function testValidValues(): void
13+
{
14+
$true = new Boolean(true);
15+
$false = new Boolean(false);
16+
17+
$this->assertTrue($true->getValue());
18+
$this->assertFalse($false->getValue());
19+
}
20+
21+
public function testStringConversion(): void
22+
{
23+
$true = new Boolean(true);
24+
$false = new Boolean(false);
25+
26+
$this->assertEquals('true', (string)$true);
27+
$this->assertEquals('false', (string)$false);
28+
}
29+
30+
public function testLogicalOperations(): void
31+
{
32+
$true = new Boolean(true);
33+
$false = new Boolean(false);
34+
35+
// AND operations
36+
$this->assertTrue($true->and($true)->getValue());
37+
$this->assertFalse($true->and($false)->getValue());
38+
$this->assertFalse($false->and($true)->getValue());
39+
$this->assertFalse($false->and($false)->getValue());
40+
41+
// OR operations
42+
$this->assertTrue($true->or($true)->getValue());
43+
$this->assertTrue($true->or($false)->getValue());
44+
$this->assertTrue($false->or($true)->getValue());
45+
$this->assertFalse($false->or($false)->getValue());
46+
47+
// XOR operations
48+
$this->assertFalse($true->xor($true)->getValue());
49+
$this->assertTrue($true->xor($false)->getValue());
50+
$this->assertTrue($false->xor($true)->getValue());
51+
$this->assertFalse($false->xor($false)->getValue());
52+
53+
// NOT operations
54+
$this->assertFalse($true->not()->getValue());
55+
$this->assertTrue($false->not()->getValue());
56+
}
57+
58+
public function testEquals(): void
59+
{
60+
$true = new Boolean(true);
61+
$false = new Boolean(false);
62+
$anotherTrue = new Boolean(true);
63+
$anotherFalse = new Boolean(false);
64+
65+
$this->assertTrue($true->equals($anotherTrue));
66+
$this->assertTrue($false->equals($anotherFalse));
67+
$this->assertFalse($true->equals($false));
68+
$this->assertFalse($false->equals($true));
69+
}
70+
71+
public function testFromString(): void
72+
{
73+
$this->assertTrue(Boolean::fromString('true')->getValue());
74+
$this->assertTrue(Boolean::fromString('TRUE')->getValue());
75+
$this->assertTrue(Boolean::fromString('True')->getValue());
76+
$this->assertFalse(Boolean::fromString('false')->getValue());
77+
$this->assertFalse(Boolean::fromString('FALSE')->getValue());
78+
$this->assertFalse(Boolean::fromString('False')->getValue());
79+
}
80+
81+
public function testFromStringInvalidValue(): void
82+
{
83+
$this->expectException(\InvalidArgumentException::class);
84+
Boolean::fromString('invalid');
85+
}
86+
}

0 commit comments

Comments
 (0)