-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayAccessConfigTraitTest.php
More file actions
110 lines (87 loc) · 2.93 KB
/
Copy pathArrayAccessConfigTraitTest.php
File metadata and controls
110 lines (87 loc) · 2.93 KB
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
103
104
105
106
107
108
109
110
<?php
declare(strict_types=1);
/**
* This file is part of php-fast-forward/config.
*
* This source file is subject to the license bundled
* with this source code in the file LICENSE.
*
* @link https://github.com/php-fast-forward/config
* @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
* @license https://opensource.org/licenses/MIT MIT License
*/
use FastForward\Config\ArrayAccessConfigTrait;
use PHPUnit\Framework\Attributes\CoversTrait;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
/**
* @internal
*/
#[CoversTrait(ArrayAccessConfigTrait::class)]
final class ArrayAccessConfigTraitTest extends TestCase
{
use ProphecyTrait;
public function testOffsetExistsWillCallHasMethod(): void
{
$object = $this->createTraitInstance(has: true);
self::assertTrue($object->offsetExists('key'));
$object = $this->createTraitInstance(has: false);
self::assertFalse($object->offsetExists('key'));
}
public function testOffsetGetWillCallGetMethod(): void
{
$object = $this->createTraitInstance(get: 'foo');
self::assertSame('foo', $object->offsetGet('bar'));
}
public function testOffsetSetWillCallSetMethod(): void
{
$object = $this->createTraitInstance();
$object->offsetSet('alpha', 'beta');
self::assertSame(['alpha' => 'beta'], $object->getSetCalls());
}
public function testOffsetUnsetWillCallRemoveMethod(): void
{
$object = $this->createTraitInstance();
$object->offsetUnset('delta');
self::assertSame(['delta'], $object->getRemoveCalls());
}
private function createTraitInstance(bool $has = false, mixed $get = null): ArrayAccess
{
return new class($has, $get) implements ArrayAccess {
use ArrayAccessConfigTrait;
private array $setCalls = [];
private array $removeCalls = [];
private bool $hasReturn;
private mixed $getReturn;
public function __construct(bool $has, mixed $get)
{
$this->hasReturn = $has;
$this->getReturn = $get;
}
public function has(mixed $offset): bool
{
return $this->hasReturn;
}
public function get(mixed $offset): mixed
{
return $this->getReturn;
}
public function set(mixed $offset, mixed $value): void
{
$this->setCalls[$offset] = $value;
}
public function remove(mixed $offset): void
{
$this->removeCalls[] = $offset;
}
public function getSetCalls(): array
{
return $this->setCalls;
}
public function getRemoveCalls(): array
{
return $this->removeCalls;
}
};
}
}