Skip to content

Commit ec5271a

Browse files
committed
Add LinksTest and MetaTest
1 parent 7479384 commit ec5271a

File tree

2 files changed

+234
-0
lines changed

2 files changed

+234
-0
lines changed

tests/LinksTest.php

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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+
}

tests/MetaTest.php

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
3+
namespace Swis\JsonApi\Client\Tests;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Swis\JsonApi\Client\Meta;
7+
8+
class MetaTest extends TestCase
9+
{
10+
public function test__get()
11+
{
12+
$meta = new Meta(['foo' => 'bar']);
13+
14+
$this->assertEquals('bar', $meta->foo);
15+
$this->assertNull($meta->other);
16+
}
17+
18+
public function testOffsetGet()
19+
{
20+
$meta = new Meta(['foo' => 'bar']);
21+
22+
$this->assertEquals('bar', $meta['foo']);
23+
$this->assertNull($meta['other']);
24+
}
25+
26+
public function test__isset()
27+
{
28+
$meta = new Meta(['foo' => 'bar']);
29+
30+
$this->assertTrue(isset($meta->foo));
31+
$this->assertFalse(isset($meta->other));
32+
}
33+
34+
public function testOffsetExists()
35+
{
36+
$meta = new Meta(['foo' => 'bar']);
37+
38+
$this->assertTrue(isset($meta['foo']));
39+
$this->assertFalse(isset($meta['other']));
40+
}
41+
42+
public function test__set()
43+
{
44+
$meta = new Meta([]);
45+
46+
$meta->foo = 'bar';
47+
48+
$this->assertEquals('bar', $meta->foo);
49+
}
50+
51+
public function testOffsetSet()
52+
{
53+
$meta = new Meta([]);
54+
55+
$meta['foo'] = 'bar';
56+
57+
$this->assertEquals('bar', $meta['foo']);
58+
}
59+
60+
public function test__unset()
61+
{
62+
$meta = new Meta(['foo' => 'bar']);
63+
64+
unset($meta->foo);
65+
66+
$this->assertNull($meta->foo);
67+
}
68+
69+
public function testOffsetUnset()
70+
{
71+
$meta = new Meta(['foo' => 'bar']);
72+
73+
unset($meta['foo']);
74+
75+
$this->assertNull($meta['foo']);
76+
}
77+
78+
public function testToArray()
79+
{
80+
$meta = new Meta(['foo' => 'bar']);
81+
82+
$this->assertEquals(
83+
['foo' => 'bar'],
84+
$meta->toArray()
85+
);
86+
}
87+
88+
public function testToJson()
89+
{
90+
$meta = new Meta(['foo' => 'bar']);
91+
92+
$this->assertEquals(
93+
'{"foo":"bar"}',
94+
$meta->toJson()
95+
);
96+
}
97+
98+
public function testJsonSerialize()
99+
{
100+
$meta = new Meta(['foo' => 'bar']);
101+
102+
$this->assertEquals(
103+
['foo' => 'bar'],
104+
$meta->toArray()
105+
);
106+
}
107+
}

0 commit comments

Comments
 (0)