| @@ 10-49 (lines=40) @@ | ||
| 7 | use TomPHP\HalClient\Resource\FieldCollection; |
|
| 8 | use TomPHP\HalClient\Resource\FieldNode; |
|
| 9 | ||
| 10 | class FieldCollectionSpec extends ObjectBehavior |
|
| 11 | { |
|
| 12 | function let(FieldNode $f1, FieldNode $f2) |
|
| 13 | { |
|
| 14 | $this->beConstructedWith([$f1, $f2]); |
|
| 15 | } |
|
| 16 | ||
| 17 | function it_is_accessible_via_ArrayAccess(FieldNode $f1, FieldNode $f2) |
|
| 18 | { |
|
| 19 | $this[0]->shouldBe($f1); |
|
| 20 | $this[1]->shouldBe($f2); |
|
| 21 | } |
|
| 22 | ||
| 23 | function it_is_accessible_can_be_checked_if_index_exists() |
|
| 24 | { |
|
| 25 | $this->offsetExists(0)->shouldReturn(true); |
|
| 26 | $this->offsetExists(2)->shouldReturn(false); |
|
| 27 | } |
|
| 28 | ||
| 29 | function it_is_immutable() |
|
| 30 | { |
|
| 31 | $this->shouldThrow(new MutabilityException())->duringOffsetSet(0, 'value'); |
|
| 32 | $this->shouldThrow(new MutabilityException())->duringOffsetUnset(0); |
|
| 33 | } |
|
| 34 | ||
| 35 | function it_finds_matching_nodes(FieldNode $f1, FieldNode $f2) |
|
| 36 | { |
|
| 37 | $criteria = ['search' => 'criteria']; |
|
| 38 | ||
| 39 | $f1->matches($criteria)->willReturn(false); |
|
| 40 | $f2->matches($criteria)->willReturn(true); |
|
| 41 | ||
| 42 | $this->findMatching($criteria)->shouldBeLike(new FieldCollection([$f2->getWrappedObject()])); |
|
| 43 | } |
|
| 44 | ||
| 45 | function it_is_countable() |
|
| 46 | { |
|
| 47 | $this->count()->shouldReturn(2); |
|
| 48 | } |
|
| 49 | } |
|
| 50 | ||
| @@ 10-49 (lines=40) @@ | ||
| 7 | use TomPHP\HalClient\Resource\ResourceCollection; |
|
| 8 | use TomPHP\HalClient\Resource\ResourceNode; |
|
| 9 | ||
| 10 | class ResourceCollectionSpec extends ObjectBehavior |
|
| 11 | { |
|
| 12 | function let(ResourceNode $f1, ResourceNode $f2) |
|
| 13 | { |
|
| 14 | $this->beConstructedWith([$f1, $f2]); |
|
| 15 | } |
|
| 16 | ||
| 17 | function it_is_accessible_via_ArrayAccess(ResourceNode $f1, ResourceNode $f2) |
|
| 18 | { |
|
| 19 | $this[0]->shouldBe($f1); |
|
| 20 | $this[1]->shouldBe($f2); |
|
| 21 | } |
|
| 22 | ||
| 23 | function it_is_accessible_can_be_checked_if_index_exists() |
|
| 24 | { |
|
| 25 | $this->offsetExists(0)->shouldReturn(true); |
|
| 26 | $this->offsetExists(2)->shouldReturn(false); |
|
| 27 | } |
|
| 28 | ||
| 29 | function it_is_immutable() |
|
| 30 | { |
|
| 31 | $this->shouldThrow(new MutabilityException())->duringOffsetSet(0, 'value'); |
|
| 32 | $this->shouldThrow(new MutabilityException())->duringOffsetUnset(0); |
|
| 33 | } |
|
| 34 | ||
| 35 | function it_finds_matching_nodes(ResourceNode $f1, ResourceNode $f2) |
|
| 36 | { |
|
| 37 | $criteria = ['search' => 'criteria']; |
|
| 38 | ||
| 39 | $f1->matches($criteria)->willReturn(false); |
|
| 40 | $f2->matches($criteria)->willReturn(true); |
|
| 41 | ||
| 42 | $this->findMatching($criteria)->shouldBeLike(new ResourceCollection([$f2->getWrappedObject()])); |
|
| 43 | } |
|
| 44 | ||
| 45 | function it_is_countable() |
|
| 46 | { |
|
| 47 | $this->count()->shouldReturn(2); |
|
| 48 | } |
|
| 49 | } |
|
| 50 | ||