Skip to content

Commit

Permalink
tests: update for changes to map()
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsey committed Jan 21, 2021
1 parent 0f58ad6 commit 031a4ee
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
32 changes: 20 additions & 12 deletions tests/CollectionManipulationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Ramsey\Collection\Test;

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

// @phpstan-ignore-next-line
$barCollection->diff(new FooCollection());
}

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

// @phpstan-ignore-next-line
$barCollection->intersect(new FooCollection());
}

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

// @phpstan-ignore-next-line
$barCollection->merge(new BarCollection(), new FooCollection());
}

Expand Down Expand Up @@ -367,18 +369,24 @@ public function testMergeGenericCollection(): void

public function testMapConvertsValues(): void
{
$stringCollection = new class (['foo', 'bar']) extends AbstractCollection {
public function getType(): string
{
return 'string';
}
};

$upperStringCollection = $stringCollection->map(function ($item) {
return strtoupper($item);
$bar1 = new Bar(1, 'Jane');
$bar2 = new Bar(2, 'John');
$bar3 = new Bar(3, 'Janice');

$barCollection = new BarCollection();
$barCollection[] = $bar1;
$barCollection[] = $bar2;
$barCollection[] = $bar3;

$names = $barCollection->map(function (Bar $bar): string {
return $bar->getName();
});

$ids = $barCollection->map(function (Bar $bar): int {
return $bar->getId();
});

$this->assertNotSame($stringCollection, $upperStringCollection);
$this->assertSame(['FOO', 'BAR'], $upperStringCollection->toArray());
$this->assertSame(['Jane', 'John', 'Janice'], $names->toArray());
$this->assertSame([1, 2, 3], $ids->toArray());
}
}
2 changes: 2 additions & 0 deletions tests/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ public function testSubclassBehavior(): void

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Value must be of type ' . Foo::class);

// @phpstan-ignore-next-line
$fooCollection[] = new stdClass();
}

Expand Down
3 changes: 3 additions & 0 deletions tests/Mock/BarCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Ramsey\Collection\AbstractCollection;

/**
* @extends AbstractCollection<Bar>
*/
class BarCollection extends AbstractCollection
{
public function getType(): string
Expand Down
3 changes: 3 additions & 0 deletions tests/Mock/FooCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Ramsey\Collection\AbstractCollection;

/**
* @extends AbstractCollection<Foo>
*/
class FooCollection extends AbstractCollection
{
public function getType(): string
Expand Down

0 comments on commit 031a4ee

Please sign in to comment.