Skip to content

Commit 24c9922

Browse files
committed
ISSUE-345: PantherTestCase in ci
1 parent 7750874 commit 24c9922

File tree

5 files changed

+36
-22
lines changed

5 files changed

+36
-22
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ jobs:
3737
curl -sS https://get.symfony.com/cli/installer | bash
3838
mv $HOME/.symfony*/bin/symfony /usr/local/bin/symfony
3939
symfony version
40+
- name: Install Google Chrome
41+
run: |
42+
curl -sSL https://dl.google.com/linux/linux_signing_key.pub | gpg --dearmor | sudo tee /usr/share/keyrings/google.gpg > /dev/null
43+
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/google.gpg] http://dl.google.com/linux/chrome/deb/ stable main" | sudo tee /etc/apt/sources.list.d/google-chrome.list
44+
sudo apt-get update
45+
sudo apt-get install -y google-chrome-stable
46+
- name: Set Panther to use Chrome
47+
run: |
48+
echo "PANTHER_NO_HEADLESS=0" >> .env.test
49+
echo "PANTHER_CHROME_BINARY=/usr/bin/google-chrome" >> .env.test
4050
- name: Start mysql service
4151
run: sudo /etc/init.d/mysql start
4252
- name: Verify MySQL connection on host

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@
1616
.phpunit.result.cache
1717
.env
1818
/node_modules
19+
/drivers/

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"phpmd/phpmd": "^2.9.1",
4545
"symfony/process": "^6.4",
4646
"symfony/panther": "*",
47-
"dbrekelmans/bdi": "*"
47+
"dbrekelmans/bdi": "*",
48+
"bshaffer/phpunit-retry-annotations": "^0.3.0"
4849
},
4950
"autoload": {
5051
"psr-4": {

tests/Integration/Auth/LoginTest.php

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,27 @@
44

55
namespace PhpList\WebFrontend\Tests\Integration\Auth;
66

7+
use PHPUnitRetry\RetryAnnotationTrait;
8+
use PHPUnitRetry\RetryTrait;
79
use Symfony\Component\Panther\PantherTestCase;
8-
use Symfony\Component\Panther\Client;
910

11+
/**
12+
* @retryAttempts 5
13+
* @retryIfException Facebook\WebDriver\Exception\NoSuchWindowException
14+
* @retryDelaySeconds 10
15+
*/
1016
class LoginTest extends PantherTestCase
1117
{
12-
protected static ?Client $client = null;
18+
use RetryAnnotationTrait;
19+
use RetryTrait;
1320

14-
public function setUp(): void
21+
public function testLoginPageFormFieldsAreVisible(): void
1522
{
16-
parent::setUp();
17-
self::$client = static::createPantherClient([
23+
$client = static::createPantherClient([
1824
'browser' => static::CHROME,
25+
'connection_timeout_in_ms' => 10000,
1926
]);
20-
}
21-
22-
public function tearDown(): void
23-
{
24-
self::$client?->quit();
25-
parent::tearDown();
26-
}
27-
28-
public function testLoginPageFormFieldsAreVisible(): void
29-
{
30-
self::$client->request('GET', '/app_test.php/login');
27+
$client->request('GET', '/app_test.php/login');
3128

3229
$this->assertPageTitleContains('phpList - Login');
3330

@@ -45,9 +42,13 @@ public function testLoginPageFormFieldsAreVisible(): void
4542

4643
public function testLoginFormSubmission(): void
4744
{
48-
self::$client->request('GET', '/app_test.php/login');
45+
$client = static::createPantherClient([
46+
'browser' => static::CHROME,
47+
'connection_timeout_in_ms' => 20000,
48+
]);
49+
$client->request('GET', '/app_test.php/login');
4950

50-
self::$client->submitForm('Sign in', [
51+
$client->submitForm('Sign in', [
5152
'username' => 'invalid_user',
5253
'password' => 'invalid_password'
5354
]);

tests/Unit/Controller/AuthControllerTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function testLoginWithPostRequestSuccess(): void
119119
$request->setSession($session);
120120

121121
$this->apiClient->method('authenticate')
122-
->with('admin', 'secret')
122+
->with('testuser', 'testpass')
123123
->willReturn(['key' => 'test-token']);
124124

125125
$this->apiClient->expects($this->once())
@@ -128,7 +128,8 @@ public function testLoginWithPostRequestSuccess(): void
128128

129129
$response = $this->controller->login($request);
130130

131-
$this->assertInstanceOf(Response::class, $response);
131+
$this->assertInstanceOf(RedirectResponse::class, $response);
132+
$this->assertStringContainsString('empty_start_page', $response->getTargetUrl());
132133
}
133134

134135
public function testLoginWithPostRequestFailure(): void
@@ -147,7 +148,7 @@ public function testLoginWithPostRequestFailure(): void
147148
$request->setSession($session);
148149

149150
$this->apiClient->method('authenticate')
150-
->with('testuser', 'wrongpass')
151+
->with('testuser', 'testpass')
151152
->willThrowException(new RuntimeException('Invalid credentials'));
152153

153154
$response = $this->controller->login($request);

0 commit comments

Comments
 (0)