Skip to content

Commit

Permalink
Addressed some missed code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
gapple committed Feb 25, 2023
1 parent 61a3c4d commit 4cdf3ba
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
31 changes: 30 additions & 1 deletion tests/SerializeListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace gapple\Tests\StructuredFields;

use gapple\StructuredFields\Item;
use gapple\StructuredFields\OuterList;
use gapple\StructuredFields\Parameters;
use gapple\StructuredFields\SerializeException;
use gapple\StructuredFields\Serializer;
use PHPUnit\Framework\TestCase;

Expand All @@ -12,7 +14,7 @@ class SerializeListTest extends TestCase
/**
* A list with bare tuples.
*/
public function testUntypedList(): void
public function testUntypedListItems(): void
{
$itemParam = new \stdClass();
$itemParam->item_param = 32;
Expand All @@ -36,4 +38,31 @@ public function testUntypedList(): void
$serialized
);
}

public function testInvalidListItem(): void
{
$this->expectException(SerializeException::class);

$list = [
new Item('test'),
'test', // Lists can't contain bare items.
];

Serializer::serializeList($list); // @phpstan-ignore-line
}

public function testIterable(): void
{
$list = new \ArrayObject([
new Item('test'),
new Item(42),
]);

$serialized = Serializer::serializeList($list);

$this->assertEquals(
'"test", 42',
$serialized
);
}
}
18 changes: 18 additions & 0 deletions tests/TupleTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace gapple\Tests\StructuredFields;

use gapple\StructuredFields\Item;
use PHPUnit\Framework\TestCase;

class TupleTraitTest extends TestCase
{
public function testSetInvalidParameterValue(): void
{
$this->expectException(\InvalidArgumentException::class);

$item = new Item('test');

$item[1] = 'test';
}
}

0 comments on commit 4cdf3ba

Please sign in to comment.