Skip to content

Commit eae7e9e

Browse files
committed
Fix tests
1 parent 3ef0969 commit eae7e9e

26 files changed

+361
-331
lines changed

test/Builder/CliMenuBuilderTest.php

+18-8
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,12 @@ public function test256ColoursCodes() : void
233233
{
234234
$terminal = static::createMock(Terminal::class);
235235
$terminal
236-
->expects($this->any())
236+
->method('getWidth')
237+
->willReturn(100);
238+
239+
$terminal
237240
->method('getColourSupport')
238-
->will($this->returnValue(256));
241+
->willReturn(256);
239242

240243
$builder = new CliMenuBuilder($terminal);
241244
$builder->setBackgroundColour(16, 'white');
@@ -248,9 +251,12 @@ public function test256ColoursCodes() : void
248251

249252
$terminal = static::createMock(Terminal::class);
250253
$terminal
251-
->expects($this->any())
254+
->method('getWidth')
255+
->willReturn(100);
256+
257+
$terminal
252258
->method('getColourSupport')
253-
->will($this->returnValue(8));
259+
->willReturn(8);
254260

255261
$builder = new CliMenuBuilder($terminal);
256262
$builder->setBackgroundColour(16, 'white');
@@ -269,9 +275,11 @@ public function testSetFgThrowsExceptionWhenColourCodeIsNotInRange() : void
269275

270276
$terminal = static::createMock(Terminal::class);
271277
$terminal
272-
->expects($this->any())
278+
->method('getWidth')
279+
->willReturn(100);
280+
$terminal
273281
->method('getColourSupport')
274-
->will($this->returnValue(256));
282+
->willReturn(256);
275283

276284
$builder = new CliMenuBuilder($terminal);
277285
$builder->setForegroundColour(512, 'white');
@@ -284,9 +292,11 @@ public function testSetBgThrowsExceptionWhenColourCodeIsNotInRange() : void
284292

285293
$terminal = static::createMock(Terminal::class);
286294
$terminal
287-
->expects($this->any())
295+
->method('getWidth')
296+
->willReturn(100);
297+
$terminal
288298
->method('getColourSupport')
289-
->will($this->returnValue(256));
299+
->willReturn(256);
290300

291301
$builder = new CliMenuBuilder($terminal);
292302
$builder->setBackgroundColour(257, 'white');

test/CliMenuTest.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,7 @@ public function testGetItems() : void
283283
$item2 = new LineBreakItem();
284284

285285

286-
$terminal = $this->createMock(Terminal::class);
287-
$style = $this->getStyle($terminal);
286+
$style = $this->getStyle($terminal = new MockTerminal);
288287

289288
$menu = new CliMenu(
290289
'PHP School FTW',
@@ -304,8 +303,7 @@ public function testRemoveItem() : void
304303
$item1 = new LineBreakItem();
305304
$item2 = new LineBreakItem();
306305

307-
$terminal = $this->createMock(Terminal::class);
308-
$style = $this->getStyle($terminal);
306+
$style = $this->getStyle($terminal = new MockTerminal);
309307

310308
$menu = new CliMenu(
311309
'PHP School FTW',
@@ -355,6 +353,10 @@ public function testThrowsExceptionIfTerminalIsNotValidTTY() : void
355353
$this->expectException(\PhpSchool\CliMenu\Exception\InvalidTerminalException::class);
356354

357355
$terminal = $this->createMock(Terminal::class);
356+
$terminal
357+
->method('getWidth')
358+
->willReturn(100);
359+
358360
$terminal->expects($this->once())
359361
->method('isInteractive')
360362
->willReturn(false);

test/Input/InputIOTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class InputIOTest extends TestCase
4444
public function setUp() : void
4545
{
4646
$this->terminal = $this->createMock(Terminal::class);
47+
$this->terminal
48+
->method('getWidth')
49+
->willReturn(100);
50+
4751
$this->output = new BufferedOutput;
4852
$this->menu = $this->createMock(CliMenu::class);
4953
$this->style = new MenuStyle($this->terminal);
@@ -52,10 +56,6 @@ public function setUp() : void
5256
$this->style->setBg('yellow');
5357
$this->style->setFg('red');
5458

55-
$this->terminal
56-
->method('getWidth')
57-
->willReturn(100);
58-
5959
$parentStyle = new MenuStyle($this->terminal);
6060
$parentStyle->setBg('blue');
6161

test/MenuStyleTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -640,4 +640,22 @@ public function testSetMarginThrowsExceptionIfValueIsNotZeroOrAbove(int $value)
640640

641641
$this->getMenuStyle()->setMargin($value);
642642
}
643+
644+
public function testHasChangedFromDefaultsReturnsFalseWhenAutoShrunk() : void
645+
{
646+
$terminal = $this
647+
->getMockBuilder(UnixTerminal::class)
648+
->disableOriginalConstructor()
649+
->onlyMethods(['getWidth'])
650+
->getMock();
651+
652+
$terminal
653+
->expects(self::any())
654+
->method('getWidth')
655+
->willReturn(80);
656+
657+
$menuStyle = new MenuStyle($terminal);
658+
659+
self::assertFalse($menuStyle->hasChangedFromDefaults());
660+
}
643661
}
+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22

3-
 
4-
 PHP School FTW 
5-
 ========================================== 
6-
 ● Item 1 
7-
 
3+
 
4+
 PHP School FTW 
5+
 ======================================== 
6+
 ● Item 1 
7+
 
88

99

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22

3-
 
4-
 PHP School FTW 
5-
 ========================================== 
6-
 ● Item 1 
7-
 
3+
 
4+
 PHP School FTW 
5+
 ======================================== 
6+
 ● Item 1 
7+
 
88

99

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22

3-
 
4-
 PHP School FTW 
5-
 ========================================== 
6-
 ● Item 1 
7-
 
3+
 
4+
 PHP School FTW 
5+
 ======================================== 
6+
 ● Item 1 
7+
 
88

99

1010
 
@@ -14,10 +14,10 @@
1414
 
1515

1616

17-
 
18-
 PHP School FTW 
19-
 ========================================== 
20-
 ● Item 1 
21-
 
17+
 
18+
 PHP School FTW 
19+
 ======================================== 
20+
 ● Item 1 
21+
 
2222

2323

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22

3-
 
4-
 PHP School FTW 
5-
 ========================================== 
6-
 ● Item 1 
7-
 
3+
 
4+
 PHP School FTW 
5+
 ======================================== 
6+
 ● Item 1 
7+
 
88

99

1010
 
@@ -14,10 +14,10 @@
1414
 
1515

1616

17-
 
18-
 PHP School FTW 
19-
 ========================================== 
20-
 ● Item 1 
21-
 
17+
 
18+
 PHP School FTW 
19+
 ======================================== 
20+
 ● Item 1 
21+
 
2222

2323

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22

3-
 
4-
 PHP School FTW 
5-
 ========================================== 
6-
 ● Item 1 
7-
 
3+
 
4+
 PHP School FTW 
5+
 ======================================== 
6+
 ● Item 1 
7+
 
88

99

1010
 
@@ -14,10 +14,10 @@
1414
 
1515

1616

17-
 
18-
 PHP School FTW 
19-
 ========================================== 
20-
 ● Item 1 
21-
 
17+
 
18+
 PHP School FTW 
19+
 ======================================== 
20+
 ● Item 1 
21+
 
2222

2323

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22

3-
 
4-
 PHP School FTW 
5-
 ========================================== 
6-
 ● Item 1 
7-
 
3+
 
4+
 PHP School FTW 
5+
 ======================================== 
6+
 ● Item 1 
7+
 
88

99

1010
 
@@ -14,10 +14,10 @@
1414
 
1515

1616

17-
 
18-
 PHP School FTW 
19-
 ========================================== 
20-
 ● Item 1 
21-
 
17+
 
18+
 PHP School FTW 
19+
 ======================================== 
20+
 ● Item 1 
21+
 
2222

2323

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22

3-
 
4-
 PHP School FTW 
5-
 ========================================== 
6-
 ● Item 1 
7-
 
3+
 
4+
 PHP School FTW 
5+
 ======================================== 
6+
 ● Item 1 
7+
 
88

99

1010
 
@@ -14,10 +14,10 @@
1414
 
1515

1616

17-
 
18-
 PHP School FTW 
19-
 ========================================== 
20-
 ● Item 1 
21-
 
17+
 
18+
 PHP School FTW 
19+
 ======================================== 
20+
 ● Item 1 
21+
 
2222

2323

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11

22

3-
 
4-
 PHP School FTW 
5-
 ========================================== 
6-
 ● Item 1 
7-
 
3+
 
4+
 PHP School FTW 
5+
 ======================================== 
6+
 ● Item 1 
7+
 
88

99

1010
 
1111
 PHP School FTW! 
1212
 
1313

1414

15-
 
16-
 PHP School FTW 
17-
 ========================================== 
18-
 ● Item 1 
19-
 
15+
 
16+
 PHP School FTW 
17+
 ======================================== 
18+
 ● Item 1 
19+
 
2020

2121

test/res/testFlashWithEvenLength.txt

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11

22

3-
 
4-
 PHP School FTW 
5-
 ========================================== 
6-
 ● Item 1 
7-
 
3+
 
4+
 PHP School FTW 
5+
 ======================================== 
6+
 ● Item 1 
7+
 
88

99

1010
 
1111
 PHP School FTW 
1212
 
1313

1414

15-
 
16-
 PHP School FTW 
17-
 ========================================== 
18-
 ● Item 1 
19-
 
15+
 
16+
 PHP School FTW 
17+
 ======================================== 
18+
 ● Item 1 
19+
 
2020

2121

0 commit comments

Comments
 (0)