NullabilityTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 28
rs 10
c 2
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A test_set_null() 0 6 1
A test_array_allows_null() 0 4 1
A test_array_no_allows_null() 0 4 1
A test_unset_null() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TypedArraysTest\Unit;
6
7
use PHPUnit\Framework\TestCase;
8
use TypedArrays\Exceptions\InvalidTypeException;
9
use TypedArraysTest\Unit\Fixtures\NonNullableSimpleObjectArray;
10
use TypedArraysTest\Unit\Fixtures\NullableSimpleObjectArray;
11
use TypedArraysTest\Unit\Fixtures\SimpleObject;
12
13
final class NullabilityTest extends TestCase
14
{
15
    public function test_array_allows_null(): void
16
    {
17
        $test = new NullableSimpleObjectArray([new SimpleObject('valid'), null]);
18
        self::assertNull($test[1]);
19
    }
20
21
    public function test_array_no_allows_null(): void
22
    {
23
        $this->expectException(InvalidTypeException::class);
24
        new NonNullableSimpleObjectArray([new SimpleObject('invalid'), null]);
25
    }
26
27
    public function test_set_null(): void
28
    {
29
        $test = new NullableSimpleObjectArray([]);
30
        $test[] = null;
31
32
        self::assertNull($test[0]);
33
    }
34
35
    public function test_unset_null(): void
36
    {
37
        $test = new NullableSimpleObjectArray([null]);
38
        unset($test[0]);
39
40
        self::assertEmpty($test);
41
    }
42
}
43