-
-
Notifications
You must be signed in to change notification settings - Fork 330
/
Copy pathParameterValueTest.php
102 lines (83 loc) · 2.8 KB
/
ParameterValueTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/*
* This file is part of the Alice package.
*
* (c) Nelmio <hello@nelm.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Nelmio\Alice\Definition\Value;
use Nelmio\Alice\Definition\ValueInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use stdClass;
use TypeError;
/**
* @covers \Nelmio\Alice\Definition\Value\ParameterValue
* @internal
*/
class ParameterValueTest extends TestCase
{
public function testIsAValue(): void
{
self::assertTrue(is_a(ParameterValue::class, ValueInterface::class, true));
}
#[DataProvider('provideInputValues')]
public function testThrowsErrorIfInvalidTypeGiven(mixed $value, mixed $errorMessage): void
{
try {
new ParameterValue($value);
self::fail('Expected error to be thrown.');
} catch (TypeError $error) {
self::assertEquals($errorMessage, $error->getMessage());
}
}
public function testReadAccessorsReturnPropertiesValues(): void
{
$parameterKey = 'dummy_param';
$value = new ParameterValue($parameterKey);
self::assertEquals($parameterKey, $value->getValue());
$parameterKey = new FakeValue();
$value = new ParameterValue($parameterKey);
self::assertEquals($parameterKey, $value->getValue());
}
public function testIsImmutable(): void
{
$injectedValue = new MutableValue('v0');
$value = new ParameterValue($injectedValue);
// Mutate injected value
$injectedValue->setValue('v1');
// Mutate returned value
$value->getValue()->setValue('v2');
self::assertNotSame(new MutableValue('v0'), $value->getValue());
}
public function testCanBeCastedIntoAString(): void
{
$value = new ParameterValue('foo');
self::assertEquals('<{foo}>', $value);
$value = new ParameterValue(
new DummyValue('foo'),
);
self::assertEquals('<{foo}>', $value);
}
public static function provideInputValues(): iterable
{
yield 'null' => [
null,
'Expected parameter key to be either a string or an instance of "Nelmio\Alice\Definition\ValueInterface". '
.'Got "NULL" instead.',
];
yield 'array' => [
[],
'Expected parameter key to be either a string or an instance of "Nelmio\Alice\Definition\ValueInterface". '
.'Got "array" instead.',
];
yield 'stdClass' => [
new stdClass(),
'Expected parameter key to be either a string or an instance of "Nelmio\Alice\Definition\ValueInterface". '
.'Got "stdClass" instead.',
];
}
}