Skip to content

Commit

Permalink
Merge pull request #14 from sunrise-php/release/v2.3.0
Browse files Browse the repository at this point in the history
v2.3.0
  • Loading branch information
fenric authored Mar 21, 2022
2 parents 973bee7 + 252d945 commit d57b175
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/ObjectCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Import classes
*/
use InvalidArgumentException;
use JsonSerializable;
use RuntimeException;

/**
Expand All @@ -25,7 +26,7 @@
/**
* ObjectCollection
*/
abstract class ObjectCollection implements ObjectCollectionInterface
abstract class ObjectCollection implements ObjectCollectionInterface, JsonSerializable
{

/**
Expand Down Expand Up @@ -101,4 +102,14 @@ final public function isEmpty() : bool
{
return [] === $this->objects;
}

/**
* {@inheritdoc}
*
* @since 2.3.0
*/
public function jsonSerialize() : array
{
return $this->objects;
}
}
9 changes: 9 additions & 0 deletions tests/ObjectCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Sunrise\Hydrator\ObjectCollection;
use Sunrise\Hydrator\ObjectCollectionInterface;
use InvalidArgumentException;
use JsonSerializable;
use RuntimeException;

class ObjectCollectionTest extends TestCase
Expand All @@ -17,6 +18,7 @@ public function testContracts() : void
$collection = new Fixtures\BarCollection();

$this->assertInstanceOf(ObjectCollectionInterface::class, $collection);
$this->assertInstanceOf(JsonSerializable::class, $collection);
}

public function testAdd() : void
Expand Down Expand Up @@ -61,4 +63,11 @@ public function testUnexpectedObject() : void

$collection->add(0, new Fixtures\Foo());
}

public function testJsonSerialize() : void
{
$collection = new Fixtures\BarCollection();

$this->assertSame($collection->all(), $collection->jsonSerialize());
}
}

0 comments on commit d57b175

Please sign in to comment.