Skip to content

Commit ed40813

Browse files
committed
changed tests to expected behavior
1 parent b8a0ec7 commit ed40813

File tree

2 files changed

+45
-21
lines changed

2 files changed

+45
-21
lines changed

tests/Relay/Connection/ConnectionBuilderTest.php

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public function testRespectsFirstAndAfter(): void
7171
['first' => 2, 'after' => 'YXJyYXljb25uZWN0aW9uOjE=']
7272
);
7373

74-
$expected = $this->getExpectedConnection(['C', 'D'], false, true);
74+
// there actually is previous page for ['A', 'B']
75+
$expected = $this->getExpectedConnection(['C', 'D'], true, true);
7576

7677
$this->assertSameConnection($expected, $actual);
7778
}
@@ -83,7 +84,8 @@ public function testRespectsFirstAndAfterWithLongFirst(): void
8384
['first' => 10, 'after' => 'YXJyYXljb25uZWN0aW9uOjE=']
8485
);
8586

86-
$expected = $this->getExpectedConnection(['C', 'D', 'E'], false, false);
87+
// there actually is previous page for ['A', 'B']
88+
$expected = $this->getExpectedConnection(['C', 'D', 'E'], true, false);
8789

8890
$this->assertSameConnection($expected, $actual);
8991
}
@@ -95,7 +97,8 @@ public function testRespectsLastAndBefore(): void
9597
['last' => 2, 'before' => 'YXJyYXljb25uZWN0aW9uOjM=']
9698
);
9799

98-
$expected = $this->getExpectedConnection(['B', 'C'], true, false);
100+
// there actually is next page for ['D', 'E']
101+
$expected = $this->getExpectedConnection(['B', 'C'], true, true);
99102

100103
$this->assertSameConnection($expected, $actual);
101104
}
@@ -107,7 +110,8 @@ public function testRespectsLastAndBeforeWithLongLast(): void
107110
['last' => 10, 'before' => 'YXJyYXljb25uZWN0aW9uOjM=']
108111
);
109112

110-
$expected = $this->getExpectedConnection(['A', 'B', 'C'], false, false);
113+
// there actually is next page for ['E']
114+
$expected = $this->getExpectedConnection(['A', 'B', 'C'], false, true);
111115

112116
$this->assertSameConnection($expected, $actual);
113117
}
@@ -119,7 +123,8 @@ public function testRespectsFirstAndAfterAndBeforeTooFew(): void
119123
['first' => 2, 'after' => 'YXJyYXljb25uZWN0aW9uOjA=', 'before' => 'YXJyYXljb25uZWN0aW9uOjQ=']
120124
);
121125

122-
$expected = $this->getExpectedConnection(['B', 'C'], false, true);
126+
// there actually is previous page for ['A']
127+
$expected = $this->getExpectedConnection(['B', 'C'], true, true);
123128

124129
$this->assertSameConnection($expected, $actual);
125130
}
@@ -131,7 +136,8 @@ public function testRespectsFirstAndAfterAndBeforeTooMany(): void
131136
['first' => 4, 'after' => 'YXJyYXljb25uZWN0aW9uOjA=', 'before' => 'YXJyYXljb25uZWN0aW9uOjQ=']
132137
);
133138

134-
$expected = $this->getExpectedConnection(['B', 'C', 'D'], false, false);
139+
// there actually is previous and next page (for ['A'] or ['E'])
140+
$expected = $this->getExpectedConnection(['B', 'C', 'D'], true, true);
135141

136142
$this->assertSameConnection($expected, $actual);
137143
}
@@ -143,7 +149,8 @@ public function testRespectsFirstAndAfterAndBeforeExactlyRight(): void
143149
['first' => 3, 'after' => 'YXJyYXljb25uZWN0aW9uOjA=', 'before' => 'YXJyYXljb25uZWN0aW9uOjQ=']
144150
);
145151

146-
$expected = $this->getExpectedConnection(['B', 'C', 'D'], false, false);
152+
// there actually is previous and next page (for ['A'] or ['E'])
153+
$expected = $this->getExpectedConnection(['B', 'C', 'D'], true, true);
147154

148155
$this->assertSameConnection($expected, $actual);
149156
}
@@ -155,7 +162,8 @@ public function testRespectsLastAndAfterAndBeforeTooFew(): void
155162
['last' => 2, 'after' => 'YXJyYXljb25uZWN0aW9uOjA=', 'before' => 'YXJyYXljb25uZWN0aW9uOjQ=']
156163
);
157164

158-
$expected = $this->getExpectedConnection(['C', 'D'], true, false);
165+
// there actually is next page for ['E']
166+
$expected = $this->getExpectedConnection(['C', 'D'], true, true);
159167

160168
$this->assertSameConnection($expected, $actual);
161169
}
@@ -167,7 +175,8 @@ public function testRespectsLastAndAfterAndBeforeTooMany(): void
167175
['last' => 4, 'after' => 'YXJyYXljb25uZWN0aW9uOjA=', 'before' => 'YXJyYXljb25uZWN0aW9uOjQ=']
168176
);
169177

170-
$expected = $this->getExpectedConnection(['B', 'C', 'D'], false, false);
178+
// there actually is previous and next page (for ['A'] or ['E'])
179+
$expected = $this->getExpectedConnection(['B', 'C', 'D'], true, true);
171180

172181
$this->assertSameConnection($expected, $actual);
173182
}
@@ -179,7 +188,8 @@ public function testRespectsLastAndAfterAndBeforeExactlyRight(): void
179188
['last' => 3, 'after' => 'YXJyYXljb25uZWN0aW9uOjA=', 'before' => 'YXJyYXljb25uZWN0aW9uOjQ=']
180189
);
181190

182-
$expected = $this->getExpectedConnection(['B', 'C', 'D'], false, false);
191+
// there actually is previous and next page (for ['A'] or ['E'])
192+
$expected = $this->getExpectedConnection(['B', 'C', 'D'], true, true);
183193

184194
$this->assertSameConnection($expected, $actual);
185195
}
@@ -266,7 +276,8 @@ public function testWorksWithAJustRightArraySlice(): void
266276
['sliceStart' => 1, 'arrayLength' => 5]
267277
);
268278

269-
$expected = $this->getExpectedConnection(['B', 'C'], false, true);
279+
// there actually is previous page for ['A']
280+
$expected = $this->getExpectedConnection(['B', 'C'], true, true);
270281

271282
$this->assertSameConnection($expected, $actual);
272283
}
@@ -282,7 +293,8 @@ public function testWorksWithAnOversizedArraySliceLeftSide(): void
282293
['sliceStart' => 0, 'arrayLength' => 5]
283294
);
284295

285-
$expected = $this->getExpectedConnection(['B', 'C'], false, true);
296+
// there actually is previous page for ['A']
297+
$expected = $this->getExpectedConnection(['B', 'C'], true, true);
286298

287299
$this->assertSameConnection($expected, $actual);
288300
}
@@ -298,7 +310,8 @@ public function testWorksWithAnOversizedArraySliceRightSide(): void
298310
['sliceStart' => 2, 'arrayLength' => 5]
299311
);
300312

301-
$expected = $this->getExpectedConnection(['C'], false, true);
313+
// there actually is previous page for ['A', 'B']
314+
$expected = $this->getExpectedConnection(['C'], true, true);
302315

303316
$this->assertSameConnection($expected, $actual);
304317
}
@@ -314,7 +327,8 @@ public function testWorksWithAnOversizedArraySliceBothSides(): void
314327
['sliceStart' => 1, 'arrayLength' => 5]
315328
);
316329

317-
$expected = $this->getExpectedConnection(['C'], false, true);
330+
// there actually is previous page for ['A', 'B']
331+
$expected = $this->getExpectedConnection(['C'], true, true);
318332

319333
$this->assertSameConnection($expected, $actual);
320334
}
@@ -330,7 +344,8 @@ public function testWorksWithAnUndersizedArraySliceLeftSide(): void
330344
['sliceStart' => 3, 'arrayLength' => 5]
331345
);
332346

333-
$expected = $this->getExpectedConnection(['D', 'E'], false, false);
347+
// there actually is previous page for ['A', 'B', 'C']
348+
$expected = $this->getExpectedConnection(['D', 'E'], true, false);
334349

335350
$this->assertSameConnection($expected, $actual);
336351
}
@@ -346,7 +361,8 @@ public function testWorksWithAnUndersizedArraySliceRightSide(): void
346361
['sliceStart' => 2, 'arrayLength' => 5]
347362
);
348363

349-
$expected = $this->getExpectedConnection(['C', 'D'], false, true);
364+
// there actually is previous page for ['A', 'B']
365+
$expected = $this->getExpectedConnection(['C', 'D'], true, true);
350366

351367
$this->assertSameConnection($expected, $actual);
352368
}
@@ -362,7 +378,8 @@ public function worksWithAnUndersizedArraySliceBothSides(): void
362378
['sliceStart' => 3, 'arrayLength' => 5]
363379
);
364380

365-
$expected = $this->getExpectedConnection(['D'], false, true);
381+
// there actually is previous page for ['A', 'B', 'C']
382+
$expected = $this->getExpectedConnection(['D'], true, true);
366383

367384
$this->assertSameConnection($expected, $actual);
368385
}

tests/Relay/Connection/PaginatorTest.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testForward(): void
6565
public function testForwardAfterInMiddle(): void
6666
{
6767
$paginator = new Paginator(function ($offset, $limit) {
68-
$this->assertSame(2, $offset);
68+
$this->assertSame(2, $offset); // offset should equal to 1 to provide information about previous page
6969
$this->assertSame(3, $limit); // Includes the extra element to check if next page is available
7070

7171
return $this->getData($offset);
@@ -77,12 +77,13 @@ public function testForwardAfterInMiddle(): void
7777
$this->assertCount(1, $result->getEdges());
7878
$this->assertSameEdgeNodeValue(['D'], $result);
7979
$this->assertTrue($result->getPageInfo()->getHasNextPage());
80+
$this->assertTrue($result->getPageInfo()->getHasPreviousPage()); // on previous page there is still ['A', 'B', 'C']
8081
}
8182

8283
public function testForwardAfterAtTheEnd(): void
8384
{
8485
$paginator = new Paginator(function ($offset, $limit) {
85-
$this->assertSame(2, $offset);
86+
$this->assertSame(2, $offset); // offset should equal to 1 to provide information about previous page
8687
$this->assertSame(4, $limit); // Includes the extra element to check if next page is available
8788

8889
return $this->getData($offset);
@@ -94,12 +95,13 @@ public function testForwardAfterAtTheEnd(): void
9495
$this->assertCount(2, $result->getEdges());
9596
$this->assertSameEdgeNodeValue(['D', 'E'], $result);
9697
$this->assertFalse($result->getPageInfo()->getHasNextPage());
98+
$this->assertTrue($result->getPageInfo()->getHasPreviousPage()); // on previous page there is still ['A', 'B', 'C']
9799
}
98100

99101
public function testForwardAfterLast(): void
100102
{
101103
$paginator = new Paginator(function ($offset, $limit) {
102-
$this->assertSame(4, $offset);
104+
$this->assertSame(4, $offset); // offset should equal to 3 to provide information about previous page
103105
$this->assertSame(7, $limit); // Includes the extra element to check if next page is available
104106

105107
return $this->getData($offset);
@@ -111,6 +113,7 @@ public function testForwardAfterLast(): void
111113
$this->assertCount(0, $result->getEdges());
112114
$this->assertSameEdgeNodeValue([], $result);
113115
$this->assertFalse($result->getPageInfo()->getHasNextPage());
116+
$this->assertTrue($result->getPageInfo()->getHasPreviousPage()); // on previous page there is still ['A', 'B', 'C', 'D', 'E']
114117
}
115118

116119
public function testForwardAfterWithUnvalidCursorAndSlice(): void
@@ -181,6 +184,7 @@ public function testBackwardBeforeLast(): void
181184
$this->assertCount(4, $result->getEdges());
182185
$this->assertSameEdgeNodeValue(['A', 'B', 'C', 'D'], $result);
183186
$this->assertFalse($result->getPageInfo()->getHasPreviousPage());
187+
$this->assertTrue($result->getPageInfo()->getHasNextPage()); // on next page there is still ['E']
184188
}
185189

186190
public function testBackwardPartialBeforeInMiddle(): void
@@ -198,6 +202,7 @@ public function testBackwardPartialBeforeInMiddle(): void
198202
$this->assertCount(2, $result->getEdges());
199203
$this->assertSameEdgeNodeValue(['B', 'C'], $result);
200204
$this->assertTrue($result->getPageInfo()->getHasPreviousPage());
205+
$this->assertTrue($result->getPageInfo()->getHasNextPage()); // on next page there is still ['D', 'E']
201206
}
202207

203208
public function testAutoBackward(): void
@@ -215,7 +220,7 @@ public function testAutoBackward(): void
215220
$this->assertCount(4, $result->getEdges());
216221
$this->assertSameEdgeNodeValue(['B', 'C', 'D', 'E'], $result);
217222
$this->assertTrue($result->getPageInfo()->getHasPreviousPage());
218-
$this->assertFalse($result->getPageInfo()->getHasNextPage());
223+
$this->assertTrue($result->getPageInfo()->getHasNextPage()); // on previous page there is still ['A']
219224
}
220225

221226
public function testAutoForward(): void
@@ -233,6 +238,7 @@ public function testAutoForward(): void
233238
$this->assertCount(4, $result->getEdges());
234239
$this->assertSameEdgeNodeValue(['A', 'B', 'C', 'D'], $result);
235240
$this->assertTrue($result->getPageInfo()->getHasNextPage());
241+
$this->assertFalse($result->getPageInfo()->getHasPreviousPage());
236242
}
237243

238244
public function testAutoBackwardWithCallable(): void
@@ -257,6 +263,7 @@ public function testAutoBackwardWithCallable(): void
257263
$this->assertCount(4, $result->getEdges());
258264
$this->assertSameEdgeNodeValue(['B', 'C', 'D', 'E'], $result);
259265
$this->assertTrue($result->getPageInfo()->getHasPreviousPage());
266+
$this->assertFalse($result->getPageInfo()->getHasNextPage());
260267
}
261268

262269
public function testTotalCallableWithArguments(): void

0 commit comments

Comments
 (0)