Skip to content

Commit 718c6ea

Browse files
committed
chore: lint, refactor, types
1 parent 544f85b commit 718c6ea

4 files changed

Lines changed: 100 additions & 95 deletions

File tree

src/Support/Selector.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,34 +108,39 @@ public static function escapeForAttributeSelector(string $text, bool $exact = fa
108108

109109
}
110110

111+
/**
112+
* Get selector by role.
113+
*
114+
* @param array<string, string|bool> $options
115+
*/
111116
public static function getByRoleSelector(string $role, array $options = []): string
112117
{
113118
$props = [];
114119

115120
if (isset($options['checked'])) {
116-
$props['checked'] = $options['checked'] ? 'true' : 'false';
121+
$props['checked'] = (bool) $options['checked'] ? 'true' : 'false';
117122
}
118123
if (isset($options['disabled'])) {
119-
$props['disabled'] = $options['disabled'] ? 'true' : 'false';
124+
$props['disabled'] = (bool) $options['disabled'] ? 'true' : 'false';
120125
}
121126
if (isset($options['selected'])) {
122-
$props['selected'] = $options['selected'] ? 'true' : 'false';
127+
$props['selected'] = (bool) $options['selected'] ? 'true' : 'false';
123128
}
124129
if (isset($options['expanded'])) {
125-
$props['expanded'] = $options['expanded'] ? 'true' : 'false';
130+
$props['expanded'] = (bool) $options['expanded'] ? 'true' : 'false';
126131
}
127132
if (isset($options['includeHidden'])) {
128-
$props['include-hidden'] = $options['includeHidden'] ? 'true' : 'false';
133+
$props['include-hidden'] = (bool) $options['includeHidden'] ? 'true' : 'false';
129134
}
130135
if (isset($options['level'])) {
131136
$props['level'] = (string) $options['level'];
132137
}
133138
if (isset($options['name'])) {
134139
$exact = $options['exact'] ?? false;
135-
$props['name'] = self::escapeForAttributeSelector($options['name'], $exact);
140+
$props['name'] = self::escapeForAttributeSelector((string) $options['name'], (bool) $exact);
136141
}
137142
if (isset($options['pressed'])) {
138-
$props['pressed'] = $options['pressed'] ? 'true' : 'false';
143+
$props['pressed'] = (bool) $options['pressed'] ? 'true' : 'false';
139144
}
140145

141146
$propsStr = '';

tests/Browser/Operations/AssertCheckedTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@
44

55
use PHPUnit\Framework\ExpectationFailedException;
66

7-
describe('assertChecked', function () {
8-
it('passes when checkbox is checked', function () {
7+
describe('assertChecked', function (): void {
8+
it('passes when checkbox is checked', function (): void {
99
$page = $this->page(playgroundUrl('/test/form-inputs'));
1010

1111
expect($page->querySelector('input[name="checked-checkbox"]'))->toBeChecked();
1212
});
1313

14-
it('fails when checkbox is checked', function () {
14+
it('fails when checkbox is checked', function (): void {
1515
$page = $this->page(playgroundUrl('/test/form-inputs'));
1616

1717
expect($page->querySelector('input[name="checked-checkbox"]'))->not->toBeChecked();
1818
})->throws(ExpectationFailedException::class);
1919

20-
it('passes when checkbox is not checked', function () {
20+
it('passes when checkbox is not checked', function (): void {
2121
$page = $this->page(playgroundUrl('/test/form-inputs'));
2222

2323
expect($page->querySelector('input[name="unchecked-checkbox"]'))->not->toBeChecked();
2424
});
2525

26-
it('fails when checkbox is not checked', function () {
26+
it('fails when checkbox is not checked', function (): void {
2727
$page = $this->page(playgroundUrl('/test/form-inputs'));
2828

2929
expect($page->querySelector('input[name="unchecked-checkbox"]'))->toBeChecked();

tests/Browser/Playwright/FrameTest.php

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,193 +4,193 @@
44

55
use Pest\Browser\Playwright\Element;
66

7-
describe('Frame', function () {
8-
beforeEach(function () {
7+
describe('Frame', function (): void {
8+
beforeEach(function (): void {
99
$this->page = $this->page(playgroundUrl('/test/selector-tests'));
1010
});
1111

12-
describe('getByTestId', function () {
13-
it('finds an element by test ID', function () {
12+
describe('getByTestId', function (): void {
13+
it('finds an element by test ID', function (): void {
1414
$element = $this->page->getByTestId('profile-section');
1515

1616
expect($element)->toBeInstanceOf(Element::class);
1717
expect($element->isVisible())->toBeTrue();
1818
});
1919

20-
it('finds a nested element by test ID', function () {
20+
it('finds a nested element by test ID', function (): void {
2121
$element = $this->page->getByTestId('user-email');
2222

2323
expect($element)->toBeInstanceOf(Element::class);
2424
expect($element->isVisible())->toBeTrue();
2525
});
2626

27-
it('returns null for non-existent test ID', function () {
27+
it('returns null for non-existent test ID', function (): void {
2828
$element = $this->page->getByTestId('non-existent-id');
2929

3030
expect($element)->toBeNull();
3131
});
3232
});
3333

34-
describe('getByRole', function () {
35-
it('finds an element by role with name option', function () {
34+
describe('getByRole', function (): void {
35+
it('finds an element by role with name option', function (): void {
3636
$element = $this->page->getByRole('button', ['name' => 'Save']);
3737

3838
expect($element)->toBeInstanceOf(Element::class);
3939
expect($element->isVisible())->toBeTrue();
4040
});
4141

42-
it('finds a checkbox by role with name option', function () {
42+
it('finds a checkbox by role with name option', function (): void {
4343
$element = $this->page->getByRole('checkbox', ['name' => 'Remember Me']);
4444

4545
expect($element)->toBeInstanceOf(Element::class);
4646
});
4747

48-
it('returns null for non-existent role', function () {
48+
it('returns null for non-existent role', function (): void {
4949
$element = $this->page->getByRole('tab', ['name' => 'Non-existent']);
5050

5151
expect($element)->toBeNull();
5252
});
5353
});
5454

55-
describe('getByLabel', function () {
56-
it('finds an input element by its associated label', function () {
55+
describe('getByLabel', function (): void {
56+
it('finds an input element by its associated label', function (): void {
5757
$element = $this->page->getByLabel('Username');
5858

5959
expect($element)->toBeInstanceOf(Element::class);
6060
expect($element->getAttribute('value'))->toBe('johndoe');
6161
});
6262

63-
it('finds a password input by its label', function () {
63+
it('finds a password input by its label', function (): void {
6464
$element = $this->page->getByLabel('Password');
6565

6666
expect($element)->toBeInstanceOf(Element::class);
6767
expect($element->getAttribute('type'))->toBe('password');
6868
});
6969

70-
it('returns null for non-existent label', function () {
70+
it('returns null for non-existent label', function (): void {
7171
$element = $this->page->getByLabel('Non-existent Label');
7272

7373
expect($element)->toBeNull();
7474
});
7575
});
7676

77-
describe('getByPlaceholder', function () {
78-
it('finds an input element by placeholder text', function () {
77+
describe('getByPlaceholder', function (): void {
78+
it('finds an input element by placeholder text', function (): void {
7979
$element = $this->page->getByPlaceholder('Search...');
8080

8181
expect($element)->toBeInstanceOf(Element::class);
8282
expect($element->getAttribute('type'))->toBe('text');
8383
});
8484

85-
it('finds a textarea by placeholder text', function () {
85+
it('finds a textarea by placeholder text', function (): void {
8686
$element = $this->page->getByPlaceholder('Enter your comments here');
8787

8888
expect($element)->toBeInstanceOf(Element::class);
8989
expect($element->isVisible())->toBeTrue();
9090
});
9191

92-
it('returns null for non-existent placeholder', function () {
92+
it('returns null for non-existent placeholder', function (): void {
9393
$element = $this->page->getByPlaceholder('Non-existent Placeholder');
9494

9595
expect($element)->toBeNull();
9696
});
9797

98-
it('finds an element with exact matching', function () {
98+
it('finds an element with exact matching', function (): void {
9999
$element = $this->page->getByPlaceholder('Search...', true);
100100

101101
expect($element)->toBeInstanceOf(Element::class);
102102
});
103103
});
104104

105-
describe('getByText', function () {
106-
it('finds an element by its text content', function () {
105+
describe('getByText', function (): void {
106+
it('finds an element by its text content', function (): void {
107107
$element = $this->page->getByText('This is a simple paragraph');
108108

109109
expect($element)->toBeInstanceOf(Element::class);
110110
expect($element->isVisible())->toBeTrue();
111111
});
112112

113-
it('finds a button by its text content', function () {
113+
it('finds a button by its text content', function (): void {
114114
$element = $this->page->getByText('Click Me Button');
115115

116116
expect($element)->toBeInstanceOf(Element::class);
117117
});
118118

119-
it('returns null for non-existent text', function () {
119+
it('returns null for non-existent text', function (): void {
120120
$element = $this->page->getByText('Non-existent Text Content');
121121

122122
expect($element)->toBeNull();
123123
});
124124

125-
it('finds an element with exact matching', function () {
125+
it('finds an element with exact matching', function (): void {
126126
$element = $this->page->getByText('This is a special span element', true);
127127

128128
expect($element)->toBeInstanceOf(Element::class);
129129
});
130130

131-
it('finds partial text without exact matching', function () {
131+
it('finds partial text without exact matching', function (): void {
132132
$element = $this->page->getByText('special span');
133133

134134
expect($element)->toBeInstanceOf(Element::class);
135135
});
136136
});
137137

138-
describe('getByAltText', function () {
139-
it('finds an image by its alt text', function () {
138+
describe('getByAltText', function (): void {
139+
it('finds an image by its alt text', function (): void {
140140
$element = $this->page->getByAltText('Pest Logo');
141141

142142
expect($element)->toBeInstanceOf(Element::class);
143143
expect($element->isVisible())->toBeTrue();
144144
});
145145

146-
it('finds another image by its alt text', function () {
146+
it('finds another image by its alt text', function (): void {
147147
$element = $this->page->getByAltText('Another Image');
148148

149149
expect($element)->toBeInstanceOf(Element::class);
150150
});
151151

152-
it('returns null for non-existent alt text', function () {
152+
it('returns null for non-existent alt text', function (): void {
153153
$element = $this->page->getByAltText('Non-existent Alt Text');
154154

155155
expect($element)->toBeNull();
156156
});
157157

158-
it('finds an element with exact matching', function () {
158+
it('finds an element with exact matching', function (): void {
159159
$element = $this->page->getByAltText('Profile Picture', true);
160160

161161
expect($element)->toBeInstanceOf(Element::class);
162162
});
163163
});
164164

165-
describe('getByTitle', function () {
166-
it('finds an element by its title attribute', function () {
165+
describe('getByTitle', function (): void {
166+
it('finds an element by its title attribute', function (): void {
167167
$element = $this->page->getByTitle('Info Button');
168168

169169
expect($element)->toBeInstanceOf(Element::class);
170170
expect($element->isVisible())->toBeTrue();
171171
});
172172

173-
it('finds a link by its title attribute', function () {
173+
it('finds a link by its title attribute', function (): void {
174174
$element = $this->page->getByTitle('Help Link');
175175

176176
expect($element)->toBeInstanceOf(Element::class);
177177
});
178178

179-
it('returns null for non-existent title', function () {
179+
it('returns null for non-existent title', function (): void {
180180
$element = $this->page->getByTitle('Non-existent Title');
181181

182182
expect($element)->toBeNull();
183183
});
184184

185-
it('finds an element with exact matching', function () {
185+
it('finds an element with exact matching', function (): void {
186186
$element = $this->page->getByTitle('User\'s Name', true);
187187

188188
expect($element)->toBeInstanceOf(Element::class);
189189
});
190190
});
191191

192-
describe('combining selectors', function () {
193-
it('can find elements using multiple methods in sequence', function () {
192+
describe('combining selectors', function (): void {
193+
it('can find elements using multiple methods in sequence', function (): void {
194194
// First get the profile section by testId
195195
$profileSection = $this->page->getByTestId('user-profile');
196196
expect($profileSection)->toBeInstanceOf(Element::class);

0 commit comments

Comments
 (0)