Skip to content

Commit 6175845

Browse files
committed
doAdd now call canAddValue
1 parent 84bddd5 commit 6175845

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
### master
22

3+
- Fix `AbstractCollection::doAdd()` who was not calling `canAddValue()`
4+
35
### [5.0.0](../../compare/4.0.0...5.0.0) - 2023-03-14
46

57
- [BC Break] Rename repository, namespace and everything else from `TypedArray` to `Collection`

src/AbstractCollection.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ protected function doAdd(mixed $value): static
172172
{
173173
$this->assertIsNotReadOnly();
174174

175-
$this->values[] = $value;
175+
if ($this->canAddValue($value)) {
176+
$this->values[] = $value;
177+
}
176178

177179
return $this;
178180
}

tests/Unit/AbstractCollection/ValudAlreadyExistTest.php renamed to tests/Unit/AbstractCollection/ValudAlreadyExistsTest.php

+19-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
ValueAlreadyExistsModeEnum
1111
};
1212

13-
final class ValudAlreadyExistTest extends TestCase
13+
final class ValudAlreadyExistsTest extends TestCase
1414
{
15-
public function testValueAlreadyExistsModeAdd(): void
15+
public function testDefault(): void
1616
{
1717
$collection = new Collection([10, 11, 11, 13]);
1818

@@ -23,7 +23,7 @@ public function testValueAlreadyExistsModeAdd(): void
2323
static::assertSame(13, $collection->callDoGet(3));
2424
}
2525

26-
public function testValueAlreadyExistsModeDoNotAdd(): void
26+
public function testDoNotAdd(): void
2727
{
2828
$collection = new Collection([10, 11, 11, 13], ValueAlreadyExistsModeEnum::DO_NOT_ADD);
2929

@@ -33,7 +33,22 @@ public function testValueAlreadyExistsModeDoNotAdd(): void
3333
static::assertSame(13, $collection->callDoGet(3));
3434
}
3535

36-
public function testValueAlreadyExistsModeException(): void
36+
public function testDoNotAdd2(): void
37+
{
38+
$collection = new Collection([], ValueAlreadyExistsModeEnum::DO_NOT_ADD);
39+
$collection
40+
->callDoAdd(10)
41+
->callDoAdd(11)
42+
->callDoAdd(11)
43+
->callDoAdd(13);
44+
45+
static::assertCount(3, $collection);
46+
static::assertSame(10, $collection->callDoGet(0));
47+
static::assertSame(11, $collection->callDoGet(1));
48+
static::assertSame(13, $collection->callDoGet(2));
49+
}
50+
51+
public function testException(): void
3752
{
3853
static::expectException(ValueAlreadyExistsException::class);
3954
new Collection([10, 11, 11, 13], ValueAlreadyExistsModeEnum::EXCEPTION);

0 commit comments

Comments
 (0)