Skip to content

Commit 06c32de

Browse files
committed
Fix: test
1 parent c3571df commit 06c32de

1 file changed

Lines changed: 5 additions & 108 deletions

File tree

tests/Integration/Controller/PublicSubscribeControllerPantherTest.php

Lines changed: 5 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
use PHPUnitRetry\RetryAnnotationTrait;
88
use PHPUnitRetry\RetryTrait;
9-
use Symfony\Component\Panther\Client;
109
use Symfony\Component\Panther\PantherTestCase;
11-
use Throwable;
1210

1311
/**
1412
* @retryAttempts 1
@@ -74,18 +72,11 @@ public function testAnonymousUserCanAccessPublicSubscribeAndUnsubscribePages(str
7472
public function testSubscribePageDisplaysEmailFieldAndSubmitButton(): void
7573
{
7674
$client = static::createPantherClient(self::PANTHER_OPTIONS);
77-
try {
78-
$client->getCookieJar()->clear();
79-
$client->request('GET', '/index.php/subscribe/1');
80-
81-
$client->takeScreenshot('var/screenshots/public-subscribe-0.png');
82-
$client->waitFor('form.legacy-form', 10);
83-
} catch (Throwable $throwable) {
84-
$client->takeScreenshot('var/screenshots/public-subscribe-error.png');
85-
$this->writePublicSubscribeDiagnostics($client, $throwable);
86-
87-
throw $throwable;
88-
}
75+
$client->getCookieJar()->clear();
76+
$client->request('GET', '/index.php/subscribe/1');
77+
78+
$client->takeScreenshot('var/screenshots/public-subscribe-0.png');
79+
$client->waitFor('form.legacy-form', 10);
8980
$client->takeScreenshot('var/screenshots/public-subscribe-1.png');
9081

9182
$currentPath = (string) parse_url($client->getCurrentURL(), PHP_URL_PATH);
@@ -107,98 +98,4 @@ public function publicSubscribePageRoutesProvider(): array
10798
'unsubscribe page route' => ['/index.php/unsubscribe/1'],
10899
];
109100
}
110-
111-
private function writePublicSubscribeDiagnostics(Client $client, Throwable $throwable): void
112-
{
113-
$diagnosticsDir = __DIR__ . '/../../../var/screenshots';
114-
if (!is_dir($diagnosticsDir)) {
115-
mkdir($diagnosticsDir, 0777, true);
116-
}
117-
118-
$pageSource = $this->readPageSource($client);
119-
file_put_contents($diagnosticsDir . '/public-subscribe-error.html', $pageSource);
120-
file_put_contents(
121-
$diagnosticsDir . '/public-subscribe-error.txt',
122-
implode("\n\n", [
123-
'Exception: ' . $throwable::class,
124-
'Message: ' . $throwable->getMessage(),
125-
'Current URL: ' . $this->readCurrentUrl($client),
126-
'Page title: ' . $this->readPageTitle($client),
127-
'Body text: ' . $this->readBodyText($client),
128-
'Recent Symfony logs:' . "\n" . $this->readRecentSymfonyLogs(),
129-
])
130-
);
131-
132-
fwrite(STDERR, "Public subscribe diagnostics written to var/screenshots/public-subscribe-error.*\n");
133-
}
134-
135-
private function readPageSource(Client $client): string
136-
{
137-
try {
138-
return $client->getPageSource();
139-
} catch (Throwable $throwable) {
140-
return 'Unable to read page source: ' . $throwable->getMessage();
141-
}
142-
}
143-
144-
private function readCurrentUrl(Client $client): string
145-
{
146-
try {
147-
return $client->getCurrentURL();
148-
} catch (Throwable $throwable) {
149-
return 'Unable to read current URL: ' . $throwable->getMessage();
150-
}
151-
}
152-
153-
private function readPageTitle(Client $client): string
154-
{
155-
try {
156-
return $client->getTitle();
157-
} catch (Throwable $throwable) {
158-
return 'Unable to read page title: ' . $throwable->getMessage();
159-
}
160-
}
161-
162-
private function readBodyText(Client $client): string
163-
{
164-
try {
165-
return $client->getCrawler()->filter('body')->text('', true);
166-
} catch (Throwable $throwable) {
167-
return 'Unable to read body text: ' . $throwable->getMessage();
168-
}
169-
}
170-
171-
private function readRecentSymfonyLogs(): string
172-
{
173-
$projectDir = dirname(__DIR__, 3);
174-
$paths = array_merge(
175-
glob($projectDir . '/var/logs/*.log') ?: [],
176-
glob($projectDir . '/var/log/*.log') ?: []
177-
);
178-
179-
if ($paths === []) {
180-
return sprintf('No log files found under %s/var/logs or %s/var/log.', $projectDir, $projectDir);
181-
}
182-
183-
$logs = [];
184-
foreach (array_unique($paths) as $path) {
185-
$logs[] = sprintf("==> %s <==\n%s", $path, $this->readRecentLogLines($path));
186-
}
187-
188-
return implode("\n\n", $logs);
189-
}
190-
191-
private function readRecentLogLines(string $path): string
192-
{
193-
if (!is_file($path)) {
194-
return sprintf('Log file %s does not exist.', $path);
195-
}
196-
197-
$lines = file($path, FILE_IGNORE_NEW_LINES);
198-
if ($lines === false) {
199-
return sprintf('Unable to read log file %s.', $path);
200-
}
201-
202-
return implode("\n", array_slice($lines, -80));
203-
}
204101
}

0 commit comments

Comments
 (0)