|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Swis\JsonApi\Client\Tests; |
| 4 | + |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | +use Swis\JsonApi\Client\Link; |
| 7 | +use Swis\JsonApi\Client\Links; |
| 8 | + |
| 9 | +class LinksTest extends TestCase |
| 10 | +{ |
| 11 | + public function test__get() |
| 12 | + { |
| 13 | + $link = new Link('http://example.com/self'); |
| 14 | + $links = new Links(['self' => $link]); |
| 15 | + |
| 16 | + $this->assertEquals($link, $links->self); |
| 17 | + $this->assertNull($links->related); |
| 18 | + } |
| 19 | + |
| 20 | + public function testOffsetGet() |
| 21 | + { |
| 22 | + $link = new Link('http://example.com/self'); |
| 23 | + $links = new Links(['self' => $link]); |
| 24 | + |
| 25 | + $this->assertEquals($link, $links['self']); |
| 26 | + $this->assertNull($links['related']); |
| 27 | + } |
| 28 | + |
| 29 | + public function test__isset() |
| 30 | + { |
| 31 | + $link = new Link('http://example.com/self'); |
| 32 | + $links = new Links(['self' => $link]); |
| 33 | + |
| 34 | + $this->assertTrue(isset($links->self)); |
| 35 | + $this->assertFalse(isset($links->related)); |
| 36 | + } |
| 37 | + |
| 38 | + public function testOffsetExists() |
| 39 | + { |
| 40 | + $link = new Link('http://example.com/self'); |
| 41 | + $links = new Links(['self' => $link]); |
| 42 | + |
| 43 | + $this->assertTrue(isset($links['self'])); |
| 44 | + $this->assertFalse(isset($links['related'])); |
| 45 | + } |
| 46 | + |
| 47 | + public function test__set() |
| 48 | + { |
| 49 | + $link = new Link('http://example.com/self'); |
| 50 | + $links = new Links([]); |
| 51 | + |
| 52 | + $links->self = $link; |
| 53 | + |
| 54 | + $this->assertEquals($link, $links->self); |
| 55 | + } |
| 56 | + |
| 57 | + public function testOffsetSet() |
| 58 | + { |
| 59 | + $link = new Link('http://example.com/self'); |
| 60 | + $links = new Links([]); |
| 61 | + |
| 62 | + $links['self'] = $link; |
| 63 | + |
| 64 | + $this->assertEquals($link, $links['self']); |
| 65 | + } |
| 66 | + |
| 67 | + public function test__unset() |
| 68 | + { |
| 69 | + $link = new Link('http://example.com/self'); |
| 70 | + $links = new Links(['self' => $link]); |
| 71 | + |
| 72 | + unset($links->self); |
| 73 | + |
| 74 | + $this->assertNull($links->self); |
| 75 | + } |
| 76 | + |
| 77 | + public function testOffsetUnset() |
| 78 | + { |
| 79 | + $link = new Link('http://example.com/self'); |
| 80 | + $links = new Links(['self' => $link]); |
| 81 | + |
| 82 | + unset($links['self']); |
| 83 | + |
| 84 | + $this->assertNull($links['self']); |
| 85 | + } |
| 86 | + |
| 87 | + public function testToArray() |
| 88 | + { |
| 89 | + $link = new Link('http://example.com/self'); |
| 90 | + $links = new Links(['self' => $link]); |
| 91 | + |
| 92 | + $this->assertEquals( |
| 93 | + [ |
| 94 | + 'self' => [ |
| 95 | + 'href' => 'http://example.com/self', |
| 96 | + ], |
| 97 | + ], |
| 98 | + $links->toArray() |
| 99 | + ); |
| 100 | + } |
| 101 | + |
| 102 | + public function testToJson() |
| 103 | + { |
| 104 | + $link = new Link('http://example.com/self'); |
| 105 | + $links = new Links(['self' => $link]); |
| 106 | + |
| 107 | + $this->assertEquals( |
| 108 | + '{"self":{"href":"http:\/\/example.com\/self"}}', |
| 109 | + $links->toJson() |
| 110 | + ); |
| 111 | + } |
| 112 | + |
| 113 | + public function testJsonSerialize() |
| 114 | + { |
| 115 | + $link = new Link('http://example.com/self'); |
| 116 | + $links = new Links(['self' => $link]); |
| 117 | + |
| 118 | + $this->assertEquals( |
| 119 | + [ |
| 120 | + 'self' => [ |
| 121 | + 'href' => 'http://example.com/self', |
| 122 | + ], |
| 123 | + ], |
| 124 | + $links->toArray() |
| 125 | + ); |
| 126 | + } |
| 127 | +} |
0 commit comments