Skip to content

Commit af961b3

Browse files
authored
Add ConsoleMessage tests (#13)
1 parent c3e6347 commit af961b3

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the playwright-php/playwright package.
7+
* For the full copyright and license information, please view
8+
* the LICENSE file that was distributed with this source code.
9+
*/
10+
11+
namespace PlaywrightPHP\Tests\Unit\Console;
12+
13+
use PHPUnit\Framework\Attributes\CoversClass;
14+
use PHPUnit\Framework\TestCase;
15+
use PlaywrightPHP\Console\ConsoleMessage;
16+
17+
#[CoversClass(ConsoleMessage::class)]
18+
class ConsoleMessageTest extends TestCase
19+
{
20+
public function testType(): void
21+
{
22+
$message = new ConsoleMessage([
23+
'type' => 'log',
24+
'text' => 'Hello, world!',
25+
'args' => [],
26+
'location' => [
27+
'url' => 'http://example.com',
28+
'lineNumber' => 10,
29+
'columnNumber' => 5,
30+
],
31+
]);
32+
33+
$this->assertSame('log', $message->type());
34+
}
35+
36+
public function testText(): void
37+
{
38+
$message = new ConsoleMessage([
39+
'type' => 'log',
40+
'text' => 'Hello, world!',
41+
'args' => [],
42+
'location' => [
43+
'url' => 'http://example.com',
44+
'lineNumber' => 10,
45+
'columnNumber' => 5,
46+
],
47+
]);
48+
49+
$this->assertSame('Hello, world!', $message->text());
50+
}
51+
52+
public function testArgs(): void
53+
{
54+
$message = new ConsoleMessage([
55+
'type' => 'log',
56+
'text' => 'Hello, world!',
57+
'args' => [1, 2, 3],
58+
'location' => [
59+
'url' => 'http://example.com',
60+
'lineNumber' => 10,
61+
'columnNumber' => 5,
62+
],
63+
]);
64+
65+
$this->assertSame([1, 2, 3], $message->args());
66+
}
67+
68+
public function testLocation(): void
69+
{
70+
$location = [
71+
'url' => 'http://example.com',
72+
'lineNumber' => 10,
73+
'columnNumber' => 5,
74+
];
75+
76+
$message = new ConsoleMessage([
77+
'type' => 'log',
78+
'text' => 'Hello, world!',
79+
'args' => [],
80+
'location' => $location,
81+
]);
82+
83+
$this->assertSame($location, $message->location());
84+
}
85+
86+
public function testInvalidType(): void
87+
{
88+
$this->expectException(\RuntimeException::class);
89+
$this->expectExceptionMessage('Invalid console message type');
90+
91+
$message = new ConsoleMessage([
92+
'type' => 123,
93+
'text' => 'Hello, world!',
94+
'args' => [],
95+
'location' => [
96+
'url' => 'http://example.com',
97+
'lineNumber' => 10,
98+
'columnNumber' => 5,
99+
],
100+
]);
101+
102+
$message->type();
103+
}
104+
105+
public function testInvalidText(): void
106+
{
107+
$this->expectException(\RuntimeException::class);
108+
$this->expectExceptionMessage('Invalid console message text');
109+
110+
$message = new ConsoleMessage([
111+
'type' => 'log',
112+
'text' => 123,
113+
'args' => [],
114+
'location' => [
115+
'url' => 'http://example.com',
116+
'lineNumber' => 10,
117+
'columnNumber' => 5,
118+
],
119+
]);
120+
121+
$message->text();
122+
}
123+
124+
public function testInvalidArgs(): void
125+
{
126+
$this->expectException(\RuntimeException::class);
127+
$this->expectExceptionMessage('Invalid console message args');
128+
129+
$message = new ConsoleMessage([
130+
'type' => 'log',
131+
'text' => 'Hello, world!',
132+
'args' => 'not an array',
133+
'location' => [
134+
'url' => 'http://example.com',
135+
'lineNumber' => 10,
136+
'columnNumber' => 5,
137+
],
138+
]);
139+
140+
$message->args();
141+
}
142+
}

0 commit comments

Comments
 (0)