providerInvalidScalarInputTypeOnAdd()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 16
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TypedArraysTest\Unit\Scalars;
6
7
use Generator;
8
use PHPUnit\Framework\TestCase;
9
use stdClass;
10
use TypedArrays\AbstractTypedArray;
11
use TypedArrays\Exceptions\InvalidTypeException;
12
use TypedArrays\Scalars\MutableIntegerArray;
13
14
final class MutableIntegerArrayTest extends TestCase
15
{
16
    public function test_construct(): void
17
    {
18
        $test = new MutableIntegerArray([1]);
19
20
        self::assertInstanceOf(MutableIntegerArray::class, $test);
21
        self::assertInstanceOf(AbstractTypedArray::class, $test);
22
    }
23
24
    /**
25
     * @dataProvider providerInvalidScalarInputTypeOnInstantiate
26
     */
27
    public function test_invalid_scalar_input_type_on_instantiate(array $arguments): void
28
    {
29
        $this->expectException(InvalidTypeException::class);
30
31
        new MutableIntegerArray($arguments);
32
    }
33
34
    public function providerInvalidScalarInputTypeOnInstantiate(): Generator
35
    {
36
        yield 'Receiving floats' => [
37
            'arguments' => [1.23, 4.56],
38
        ];
39
40
        yield 'Receiving booleans' => [
41
            'arguments' => [true, false],
42
        ];
43
44
        yield 'Receiving stdClasses' => [
45
            'arguments' => [new stdClass(), new stdClass()],
46
        ];
47
48
        yield 'Receiving strings' => [
49
            'arguments' => ['str1', 'str2'],
50
        ];
51
52
        yield 'Receiving a mix of all scalars' => [
53
            'arguments' => [true, 1, 2.3, 'string', new stdClass()],
54
        ];
55
    }
56
57
    /**
58
     * @dataProvider providerInvalidScalarInputTypeOnAdd
59
     *
60
     * @param mixed $argument
61
     */
62
    public function test_invalid_scalar_input_type_on_add($argument): void
63
    {
64
        $this->expectException(InvalidTypeException::class);
65
66
        $test = new MutableIntegerArray([]);
67
        $test[] = $argument;
68
    }
69
70
    public function providerInvalidScalarInputTypeOnAdd(): Generator
71
    {
72
        yield 'Adding float' => [
73
            'argument' => 1.23,
74
        ];
75
76
        yield 'Adding boolean' => [
77
            'argument' => true,
78
        ];
79
80
        yield 'Adding stdClass' => [
81
            'argument' => new stdClass(),
82
        ];
83
84
        yield 'Adding string' => [
85
            'argument' => 'str1',
86
        ];
87
    }
88
}
89