|
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\MutableFloatArray; |
|
13
|
|
|
|
|
14
|
|
|
final class MutableFloatArrayTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
public function test_construct(): void |
|
17
|
|
|
{ |
|
18
|
|
|
$test = new MutableFloatArray([1.5]); |
|
19
|
|
|
|
|
20
|
|
|
self::assertInstanceOf(MutableFloatArray::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 MutableFloatArray($arguments); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function providerInvalidScalarInputTypeOnInstantiate(): Generator |
|
35
|
|
|
{ |
|
36
|
|
|
yield 'Receiving integers' => [ |
|
37
|
|
|
'arguments' => [1, 2], |
|
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 MutableFloatArray([]); |
|
67
|
|
|
$test[] = $argument; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function providerInvalidScalarInputTypeOnAdd(): Generator |
|
71
|
|
|
{ |
|
72
|
|
|
yield 'Adding integer' => [ |
|
73
|
|
|
'argument' => 1, |
|
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
|
|
|
|