Skip to content

Commit

Permalink
test: add waitFor() calls in submit form tests to ensure crawler state (
Browse files Browse the repository at this point in the history
  • Loading branch information
yohang authored Jan 9, 2025
1 parent 73ca3da commit 1fb612b
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,15 @@ public function testSubmitForm(callable $clientFactory): void
]);

$crawler = $client->submit($form);
$this->assertInstanceOf(DomCrawlerCrawler::class, $crawler);
if ($client instanceof Client) {
try {
$crawler = $client->waitFor('#result');
} catch (TimeoutException) {
$this->markTestSkipped('Test skipped if no result after 30 seconds to prevent inconsistent fail on CI');
}
$this->assertInstanceOf(Crawler::class, $crawler);
}
$this->assertInstanceOf(DomCrawlerCrawler::class, $crawler);
$this->assertSame(self::$baseUri.'/form-handle.php', $crawler->getUri());
$this->assertSame('I1: Reclus', $crawler->filter('#result')->text(null, true));

Expand All @@ -363,6 +368,13 @@ public function testSubmitForm(callable $clientFactory): void
]);

$crawler = $client->submit($form);
if ($client instanceof Client) {
try {
$crawler = $client->waitFor('#result');
} catch (TimeoutException) {
$this->markTestSkipped('Test skipped if no result after 30 seconds to prevent inconsistent fail on CI');
}
}
$this->assertSame(self::$baseUri.'/form-handle.php?i1=Michel&i2=&i3=&i4=i4a', $crawler->getUri());

try {
Expand All @@ -383,7 +395,7 @@ public function testSubmitForm(callable $clientFactory): void
/**
* @dataProvider clientFactoryProvider
*/
public function testSubmitFormWithValues(callable $clientFactory, string $type): void
public function testSubmitFormWithValues(callable $clientFactory): void
{
/** @var AbstractBrowser $client */
$client = $clientFactory();
Expand All @@ -393,10 +405,15 @@ public function testSubmitFormWithValues(callable $clientFactory, string $type):
$crawler = $client->submit($form, [
'i1' => 'Reclus',
]);
$this->assertInstanceOf(DomCrawlerCrawler::class, $crawler);
if (Client::class === $type) {
if ($client instanceof Client) {
try {
$crawler = $client->waitFor('#result');
} catch (TimeoutException) {
$this->markTestSkipped('Test skipped if no result after 30 seconds to prevent inconsistent fail on CI');
}
$this->assertInstanceOf(Crawler::class, $crawler);
}
$this->assertInstanceOf(DomCrawlerCrawler::class, $crawler);
$this->assertSame(self::$baseUri.'/form-handle.php', $crawler->getUri());
$this->assertSame('I1: Reclus', $crawler->filter('#result')->text(null, true));
}
Expand Down

0 comments on commit 1fb612b

Please sign in to comment.