Skip to content

Commit 4044b9b

Browse files
authored
Added test function return type hint (#2)
* add: return void type hint * add: param type hint
1 parent ab45ae1 commit 4044b9b

20 files changed

+58
-58
lines changed

tests/Blocks/BlockElementTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
class BlockElementTest extends TestCase
1414
{
15-
public function testCanSetBlockId()
15+
public function testCanSetBlockId(): void
1616
{
1717
$block = new class () extends BlockElement {
1818
public function validate(): void
@@ -26,7 +26,7 @@ public function validate(): void
2626
$this->assertEquals('foo', $block->getBlockId());
2727
}
2828

29-
public function testCanSetBlockIdWhenConstructing()
29+
public function testCanSetBlockIdWhenConstructing(): void
3030
{
3131
$block = new class ('foo') extends BlockElement {
3232
public function validate(): void

tests/Blocks/DividerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
class DividerTest extends TestCase
1515
{
16-
public function testThatDividerRendersToJsonCorrectly()
16+
public function testThatDividerRendersToJsonCorrectly(): void
1717
{
1818
$divider = new Divider();
1919
$this->assertJsonData([

tests/Blocks/FileTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
class FileTest extends TestCase
1515
{
16-
public function testThatFileRendersToJsonCorrectly()
16+
public function testThatFileRendersToJsonCorrectly(): void
1717
{
1818
$file = new File('id1');
1919
$file->externalId('foo');

tests/Blocks/HeaderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
class HeaderTest extends TestCase
1515
{
16-
public function testThatHeaderRendersToJsonCorrectly()
16+
public function testThatHeaderRendersToJsonCorrectly(): void
1717
{
1818
$header = new Header('id1');
1919
$header->text('foo');

tests/ConfigTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
class ConfigTest extends TestCase
1111
{
12-
public function testCanSetConfigValuesWithFluentSyntax()
12+
public function testCanSetConfigValuesWithFluentSyntax(): void
1313
{
1414
$c = Config::new()
1515
->setDefaultEmojiSetting(true)
@@ -19,7 +19,7 @@ public function testCanSetConfigValuesWithFluentSyntax()
1919
$this->assertTrue($c->getDefaultVerbatimSetting());
2020
}
2121

22-
public function testCanUseDefaultConfigValues()
22+
public function testCanUseDefaultConfigValues(): void
2323
{
2424
$c = Config::new();
2525

tests/ElementTest.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
class ElementTest extends TestCase
1818
{
19-
public function testCanSerializeValidElementToJson()
19+
public function testCanSerializeValidElementToJson(): void
2020
{
2121
$element = $this->getMockElement();
2222

@@ -26,14 +26,14 @@ public function testCanSerializeValidElementToJson()
2626
]);
2727
}
2828

29-
public function testThrowsErrorElementIsInvalid()
29+
public function testThrowsErrorElementIsInvalid(): void
3030
{
3131
$this->expectException(Exception::class);
3232
$element = $this->getMockElement(false);
3333
$this->jsonEncode($element);
3434
}
3535

36-
public function testCanSetParentWithFluidInterfaceAndGetParentBack()
36+
public function testCanSetParentWithFluidInterfaceAndGetParentBack(): void
3737
{
3838
$parent = $this->getMockElement();
3939
$element = $this->getMockElement();
@@ -42,14 +42,14 @@ public function testCanSetParentWithFluidInterfaceAndGetParentBack()
4242
$this->assertSame($parent, $element->getParent());
4343
}
4444

45-
public function testCanUseNewAsFactoryForChildClasses()
45+
public function testCanUseNewAsFactoryForChildClasses(): void
4646
{
4747
$element = Section::new();
4848
$this->assertEquals(Type::SECTION, $element->getType());
4949
$this->assertInstanceOf(Section::class, $element);
5050
}
5151

52-
public function testCanSetExtraFieldsForArbitraryData()
52+
public function testCanSetExtraFieldsForArbitraryData(): void
5353
{
5454
$element = $this->getMockElement();
5555

@@ -62,7 +62,7 @@ public function testCanSetExtraFieldsForArbitraryData()
6262
]);
6363
}
6464

65-
public function testCanTapIntoElementForChaining()
65+
public function testCanTapIntoElementForChaining(): void
6666
{
6767
$element = $this->getMockElement()->tap(function (Element $e) {
6868
$e->setExtra('fizz', 'buzz');
@@ -76,7 +76,7 @@ public function testCanTapIntoElementForChaining()
7676
]);
7777
}
7878

79-
public function testCanConditionallyTapIntoElementForChaining()
79+
public function testCanConditionallyTapIntoElementForChaining(): void
8080
{
8181
$callable = function (Element $e) {
8282
$e->setExtra('fizz', 'buzz');
@@ -100,8 +100,8 @@ public function testCanConditionallyTapIntoElementForChaining()
100100
private function getMockElement(bool $valid = true): Element
101101
{
102102
return new class ($valid) extends Element {
103-
private $text;
104-
private $valid;
103+
private string $text;
104+
private bool $valid;
105105

106106
public function __construct(bool $valid)
107107
{
@@ -128,7 +128,7 @@ public function toArray(): array
128128
};
129129
}
130130

131-
public function testHydration()
131+
public function testHydration(): void
132132
{
133133
$beforeJson = <<<JSON
134134
{
@@ -180,13 +180,13 @@ public function testHydration()
180180
$this->assertJsonStringEqualsJsonString($beforeJson, $afterJson);
181181
}
182182

183-
public function testFromJsonThrowsExceptionOnBadJson()
183+
public function testFromJsonThrowsExceptionOnBadJson(): void
184184
{
185185
$this->expectException(HydrationException::class);
186186
Modal::fromJson('{"foo":"Bar",}');
187187
}
188188

189-
public function testCanExportToJsonWithPrettyPrint()
189+
public function testCanExportToJsonWithPrettyPrint(): void
190190
{
191191
$element = $this->getMockElement();
192192
$json = $element->toJson(true);

tests/FormatterTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
class FormatterTest extends TestCase
1111
{
12-
public function testCanDoSimpleTextFormatting()
12+
public function testCanDoSimpleTextFormatting(): void
1313
{
1414
$f = Formatter::new();
1515
$this->assertEquals('*hello*', $f->bold('hello'));
@@ -18,7 +18,7 @@ public function testCanDoSimpleTextFormatting()
1818
$this->assertEquals('`hello`', $f->code('hello'));
1919
}
2020

21-
public function testCanDoEntityReferenceFormatting()
21+
public function testCanDoEntityReferenceFormatting(): void
2222
{
2323
$f = Formatter::new();
2424
$this->assertEquals('<!channel>', $f->atChannel());
@@ -29,7 +29,7 @@ public function testCanDoEntityReferenceFormatting()
2929
$this->assertEquals('<!subteam^G01>', $f->userGroup('G01'));
3030
}
3131

32-
public function testCanInterpolateAndEscapeText()
32+
public function testCanInterpolateAndEscapeText(): void
3333
{
3434
$f = Formatter::new();
3535
$text = $f->escape($f->sub('There is {name} & John.', ['name' => 'Jim']));

tests/Inputs/CheckBoxesTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
class CheckBoxesTest extends TestCase
1717
{
18-
public function testCheckboxesWithConfirm()
18+
public function testCheckboxesWithConfirm(): void
1919
{
2020
$input = (new Checkboxes('checkboxes-identifier'))
2121
->option('foo', 'foo')
@@ -86,7 +86,7 @@ public function testCheckboxesWithConfirm()
8686
], $input);
8787
}
8888

89-
public function testTooManyOptions()
89+
public function testTooManyOptions(): void
9090
{
9191

9292
$this->expectException(Exception::class);
@@ -105,7 +105,7 @@ public function testTooManyOptions()
105105
$input->validate();
106106
}
107107

108-
public function testNoOptions()
108+
public function testNoOptions(): void
109109
{
110110
$this->expectException(Exception::class);
111111
$input = new Checkboxes();

tests/Inputs/DatePickerTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
class DatePickerTest extends TestCase
1515
{
16-
public function testCanConfigureDatePicker()
16+
public function testCanConfigureDatePicker(): void
1717
{
1818
$input = (new DatePicker())
1919
->actionId('my_id')
@@ -31,7 +31,7 @@ public function testCanConfigureDatePicker()
3131
], $input);
3232
}
3333

34-
public function testMustAdhereToCorrectTimeFormat()
34+
public function testMustAdhereToCorrectTimeFormat(): void
3535
{
3636
$this->expectException(Exception::class);
3737
(new DatePicker())->initialDate('nope');

tests/Inputs/InputElementTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
class InputElementTest extends TestCase
1414
{
15-
public function testCanSetActionId()
15+
public function testCanSetActionId(): void
1616
{
1717
$input = new class () extends InputElement {
1818
public function validate(): void
@@ -34,7 +34,7 @@ public function getType(): string
3434
], $input);
3535
}
3636

37-
public function testCanSetActionIdWhenConstructing()
37+
public function testCanSetActionIdWhenConstructing(): void
3838
{
3939
$input = new class ('foo') extends InputElement {
4040
public function validate(): void

tests/Inputs/OverflowMenuTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
class OverflowMenuTest extends TestCase
1717
{
18-
public function testOverflowMenuWithConfirm()
18+
public function testOverflowMenuWithConfirm(): void
1919
{
2020
$input = (new OverflowMenu('overflow-identifier'))
2121
->option('foo', 'foo')
@@ -71,7 +71,7 @@ public function testOverflowMenuWithConfirm()
7171
], $input);
7272
}
7373

74-
public function testTooManyOptions()
74+
public function testTooManyOptions(): void
7575
{
7676
$this->expectException(Exception::class);
7777
$input = (new OverflowMenu())
@@ -84,7 +84,7 @@ public function testTooManyOptions()
8484
$input->validate();
8585
}
8686

87-
public function testTooFewOptions()
87+
public function testTooFewOptions(): void
8888
{
8989
$this->expectException(Exception::class);
9090
$input = (new OverflowMenu())

tests/Inputs/RadioButtonsTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
class RadioButtonsTest extends TestCase
1717
{
18-
public function testRadioButtonsWithConfirm()
18+
public function testRadioButtonsWithConfirm(): void
1919
{
2020
$input = (new RadioButtons('radio-buttons-identifier'))
2121
->option('foo', 'foo')
@@ -77,7 +77,7 @@ public function testRadioButtonsWithConfirm()
7777
], $input);
7878
}
7979

80-
public function testTooManyOptions()
80+
public function testTooManyOptions(): void
8181
{
8282
$this->expectException(Exception::class);
8383
$input = (new RadioButtons())
@@ -95,14 +95,14 @@ public function testTooManyOptions()
9595
$input->validate();
9696
}
9797

98-
public function testNoOptions()
98+
public function testNoOptions(): void
9999
{
100100
$this->expectException(Exception::class);
101101
$input = new RadioButtons();
102102
$input->validate();
103103
}
104104

105-
public function testTooManyInitialOptions()
105+
public function testTooManyInitialOptions(): void
106106
{
107107
$this->expectException(Exception::class);
108108
$input = (new RadioButtons())

tests/Inputs/TextInputTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
class TextInputTest extends TestCase
1515
{
16-
public function testCanConfigureTextInput()
16+
public function testCanConfigureTextInput(): void
1717
{
1818
$input = (new TextInput())
1919
->placeholder('foo')
@@ -40,26 +40,26 @@ public function testCanConfigureTextInput()
4040
], $input);
4141
}
4242

43-
public function testCannotSetMinLengthLessThanZero()
43+
public function testCannotSetMinLengthLessThanZero(): void
4444
{
4545
$this->expectException(Exception::class);
4646
(new TextInput())->minLength(-1);
4747
}
4848

49-
public function testCannotSetMaxLengthLessThanOne()
49+
public function testCannotSetMaxLengthLessThanOne(): void
5050
{
5151
$this->expectException(Exception::class);
5252
(new TextInput())->maxLength(0);
5353
}
5454

55-
public function testCannotSetMaxLengthLessThanMinLength()
55+
public function testCannotSetMaxLengthLessThanMinLength(): void
5656
{
5757
$this->expectException(Exception::class);
5858
$input = (new TextInput())->minLength(5)->maxLength(3);
5959
$input->validate();
6060
}
6161

62-
public function testCannotSetMinLengthGreaterThan3000()
62+
public function testCannotSetMinLengthGreaterThan3000(): void
6363
{
6464
$this->expectException(Exception::class);
6565
$input = (new TextInput())->minLength(3001);

tests/Inputs/TimePickerTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
class TimePickerTest extends TestCase
1515
{
16-
public function testCanConfigureTimePicker()
16+
public function testCanConfigureTimePicker(): void
1717
{
1818
$input = (new TimePicker())
1919
->actionId('my_id')
@@ -31,7 +31,7 @@ public function testCanConfigureTimePicker()
3131
], $input);
3232
}
3333

34-
public function testMustAdhereToCorrectTimeFormat()
34+
public function testMustAdhereToCorrectTimeFormat(): void
3535
{
3636
$this->expectException(Exception::class);
3737
(new TimePicker())->initialTime('nope');

0 commit comments

Comments
 (0)