Skip to content

Commit

Permalink
ci: fixed static analysis (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
yohang authored Jan 8, 2025
1 parent 0fa5f65 commit 3945ece
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 19 deletions.
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ parameters:
ignoreErrors:
# False positive
- '#Call to an undefined method ReflectionType::getName\(\)\.#'
# False positive : assertNotEmpty assert that count() !== 0 on Countable
- '#Call to static method PHPUnit\\Framework\\Assert::assert(Not)?Empty\(\) with Symfony\\Component\\DomCrawler\\Crawler will always evaluate to (true|false)\.#'
# False positive : getStatus exists for PHPUnit < 10 only
- '#Call to function method_exists\(\) with \$this\(Symfony\\Component\\Panther\\PantherTestCase\) and ''getStatus'' will always evaluate to true\.#'
# False positive : PantherTestCase has no getClient method when symfony/framework-bundle (and WebTestCase) are not available
- '#Call to function method_exists\(\) with ''Symfony\\\\Component\\\\Panther\\\\PantherTestCase'' and ''getClient'' will always evaluate to true\.#'
# To fix in PHP WebDriver
- '#Parameter \#2 \$desired_capabilities of static method Facebook\\WebDriver\\Remote\\RemoteWebDriver::create\(\) expects array\|Facebook\\WebDriver\\Remote\\DesiredCapabilities\|null, Facebook\\WebDriver\\WebDriverCapabilities given\.#'
# Require a redesign of the underlying Symfony components
Expand Down
9 changes: 2 additions & 7 deletions src/DomCrawler/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,7 @@ public function set(FormField $field): void
$this->setValue($field->getName(), $field->getValue());
}

/**
* @return FormField|FormField[]|FormField[][]
*/
public function get($name): FormField|array
public function get($name): FormField
{
return $this->getFormField($this->getFormElement($name));
}
Expand All @@ -238,10 +235,8 @@ public function offsetExists($name): bool
* Gets the value of a field.
*
* @param string $name
*
* @return FormField|FormField[]|FormField[][]
*/
public function offsetGet($name): FormField|array
public function offsetGet($name): FormField
{
return $this->get($name);
}
Expand Down
11 changes: 3 additions & 8 deletions src/WebTestAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ public static function assertSelectorExists(string $selector, string $message =
$client = self::getClient();

if ($client instanceof PantherClient) {
$element = self::findElement($selector);
self::assertNotNull($element, $message);
$by = $client::createWebDriverByFromLocator($selector);
$elements = $client->findElements($by);
self::assertNotEmpty($elements, $message);

return;
}
Expand Down Expand Up @@ -92,12 +93,6 @@ public static function assertPageTitleContains(string $expectedTitle, string $me
{
$client = self::getClient();
if ($client instanceof PantherClient) {
if (method_exists(self::class, 'assertStringContainsString')) {
self::assertStringContainsString($expectedTitle, $client->getTitle());

return;
}

self::assertStringContainsString($expectedTitle, $client->getTitle());

return;
Expand Down
3 changes: 0 additions & 3 deletions tests/DomCrawler/CrawlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,6 @@ public function testParents(callable $clientFactory): void
public function testAncestors(callable $clientFactory): void
{
$crawler = $this->request($clientFactory, '/basic.html');
if (!method_exists($crawler, 'ancestors')) {
$this->markTestSkipped('Crawler::ancestors() doesn\'t exist.');
}

$names = [];
$crawler->filter('main > h1')->ancestors()->each(function (Crawler $c, int $i) use (&$names) {
Expand Down
2 changes: 1 addition & 1 deletion tests/ScreenshotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testTakeScreenshot(): void

$screen = $client->takeScreenshot();

$this->assertIsString($screen);
$this->assertNotEmpty($screen);
}

public function testTakeScreenshotAndSaveToFile(): void
Expand Down

0 comments on commit 3945ece

Please sign in to comment.