Skip to content

Commit 031a4ee

Browse files
committed
tests: update for changes to map()
1 parent 0f58ad6 commit 031a4ee

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

tests/CollectionManipulationTest.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Ramsey\Collection\Test;
66

7-
use Ramsey\Collection\AbstractCollection;
87
use Ramsey\Collection\Collection;
98
use Ramsey\Collection\Exception\CollectionMismatchException;
109
use Ramsey\Collection\Exception\InvalidSortOrderException;
@@ -185,6 +184,7 @@ public function testDiffShouldRaiseExceptionOnDiverseCollections(): void
185184
$this->expectException(CollectionMismatchException::class);
186185
$this->expectExceptionMessage('Collection must be of type Ramsey\Collection\Test\Mock\BarCollection');
187186

187+
// @phpstan-ignore-next-line
188188
$barCollection->diff(new FooCollection());
189189
}
190190

@@ -249,6 +249,7 @@ public function testIntersectShouldRaiseExceptionOnDiverseCollections(): void
249249
$this->expectException(CollectionMismatchException::class);
250250
$this->expectExceptionMessage('Collection must be of type Ramsey\Collection\Test\Mock\BarCollection');
251251

252+
// @phpstan-ignore-next-line
252253
$barCollection->intersect(new FooCollection());
253254
}
254255

@@ -316,6 +317,7 @@ public function testMergeShouldRaiseExceptionOnDiverseCollection(): void
316317
'Collection with index 1 must be of type Ramsey\Collection\Test\Mock\BarCollection'
317318
);
318319

320+
// @phpstan-ignore-next-line
319321
$barCollection->merge(new BarCollection(), new FooCollection());
320322
}
321323

@@ -367,18 +369,24 @@ public function testMergeGenericCollection(): void
367369

368370
public function testMapConvertsValues(): void
369371
{
370-
$stringCollection = new class (['foo', 'bar']) extends AbstractCollection {
371-
public function getType(): string
372-
{
373-
return 'string';
374-
}
375-
};
376-
377-
$upperStringCollection = $stringCollection->map(function ($item) {
378-
return strtoupper($item);
372+
$bar1 = new Bar(1, 'Jane');
373+
$bar2 = new Bar(2, 'John');
374+
$bar3 = new Bar(3, 'Janice');
375+
376+
$barCollection = new BarCollection();
377+
$barCollection[] = $bar1;
378+
$barCollection[] = $bar2;
379+
$barCollection[] = $bar3;
380+
381+
$names = $barCollection->map(function (Bar $bar): string {
382+
return $bar->getName();
383+
});
384+
385+
$ids = $barCollection->map(function (Bar $bar): int {
386+
return $bar->getId();
379387
});
380388

381-
$this->assertNotSame($stringCollection, $upperStringCollection);
382-
$this->assertSame(['FOO', 'BAR'], $upperStringCollection->toArray());
389+
$this->assertSame(['Jane', 'John', 'Janice'], $names->toArray());
390+
$this->assertSame([1, 2, 3], $ids->toArray());
383391
}
384392
}

tests/CollectionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ public function testSubclassBehavior(): void
154154

155155
$this->expectException(InvalidArgumentException::class);
156156
$this->expectExceptionMessage('Value must be of type ' . Foo::class);
157+
158+
// @phpstan-ignore-next-line
157159
$fooCollection[] = new stdClass();
158160
}
159161

tests/Mock/BarCollection.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
use Ramsey\Collection\AbstractCollection;
88

9+
/**
10+
* @extends AbstractCollection<Bar>
11+
*/
912
class BarCollection extends AbstractCollection
1013
{
1114
public function getType(): string

tests/Mock/FooCollection.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
use Ramsey\Collection\AbstractCollection;
88

9+
/**
10+
* @extends AbstractCollection<Foo>
11+
*/
912
class FooCollection extends AbstractCollection
1013
{
1114
public function getType(): string

0 commit comments

Comments
 (0)