Skip to content

Commit 0319d34

Browse files
committed
Fix errors reported by PHPStan in test/selenium
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent a3228b8 commit 0319d34

5 files changed

Lines changed: 31 additions & 108 deletions

File tree

phpstan-baseline.neon

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10335,48 +10335,3 @@ parameters:
1033510335
count: 1
1033610336
path: test/classes/ZipExtensionTest.php
1033710337

10338-
-
10339-
message: "#^Property PhpMyAdmin\\\\Tests\\\\Selenium\\\\ChangePasswordTest\\:\\:\\$verificationErrors is never written, only read\\.$#"
10340-
count: 1
10341-
path: test/selenium/ChangePasswordTest.php
10342-
10343-
-
10344-
message: "#^Method PhpMyAdmin\\\\Tests\\\\Selenium\\\\ExportTest\\:\\:exportDataProvider\\(\\) return type has no value type specified in iterable type array\\.$#"
10345-
count: 1
10346-
path: test/selenium/ExportTest.php
10347-
10348-
-
10349-
message: "#^Method PhpMyAdmin\\\\Tests\\\\Selenium\\\\ExportTest\\:\\:testDbExport\\(\\) has parameter \\$expected with no value type specified in iterable type array\\.$#"
10350-
count: 1
10351-
path: test/selenium/ExportTest.php
10352-
10353-
-
10354-
message: "#^Method PhpMyAdmin\\\\Tests\\\\Selenium\\\\ExportTest\\:\\:testServerExport\\(\\) has parameter \\$expected with no value type specified in iterable type array\\.$#"
10355-
count: 1
10356-
path: test/selenium/ExportTest.php
10357-
10358-
-
10359-
message: "#^Method PhpMyAdmin\\\\Tests\\\\Selenium\\\\ExportTest\\:\\:testTableExport\\(\\) has parameter \\$expected with no value type specified in iterable type array\\.$#"
10360-
count: 1
10361-
path: test/selenium/ExportTest.php
10362-
10363-
-
10364-
message: "#^Cannot access property \\$automation_session on mixed\\.$#"
10365-
count: 1
10366-
path: test/selenium/TestBase.php
10367-
10368-
-
10369-
message: "#^Method PhpMyAdmin\\\\Tests\\\\Selenium\\\\TestBase\\:\\:waitForElement\\(\\) should return Facebook\\\\WebDriver\\\\Remote\\\\RemoteWebElement but returns mixed\\.$#"
10370-
count: 1
10371-
path: test/selenium/TestBase.php
10372-
10373-
-
10374-
message: "#^Method PhpMyAdmin\\\\Tests\\\\Selenium\\\\TestBase\\:\\:waitUntilElementIsPresent\\(\\) should return Facebook\\\\WebDriver\\\\Remote\\\\RemoteWebElement but returns mixed\\.$#"
10375-
count: 1
10376-
path: test/selenium/TestBase.php
10377-
10378-
-
10379-
message: "#^Method PhpMyAdmin\\\\Tests\\\\Selenium\\\\TestBase\\:\\:waitUntilElementIsVisible\\(\\) should return Facebook\\\\WebDriver\\\\WebDriverElement but returns mixed\\.$#"
10380-
count: 1
10381-
path: test/selenium/TestBase.php
10382-

psalm-baseline.xml

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16151,21 +16151,6 @@
1615116151
<code>$sqlMode</code>
1615216152
</MixedReturnStatement>
1615316153
</file>
16154-
<file src="test/selenium/ExportTest.php">
16155-
<MixedArgument occurrences="3">
16156-
<code>$str</code>
16157-
<code>$str</code>
16158-
<code>$str</code>
16159-
</MixedArgument>
16160-
<MixedAssignment occurrences="3">
16161-
<code>$str</code>
16162-
<code>$str</code>
16163-
<code>$str</code>
16164-
</MixedAssignment>
16165-
<MixedInferredReturnType occurrences="1">
16166-
<code>array</code>
16167-
</MixedInferredReturnType>
16168-
</file>
1616916154
<file src="test/selenium/TestBase.php">
1617016155
<DocblockTypeContradiction occurrences="1">
1617116156
<code>$this-&gt;webDriver === null</code>
@@ -16189,20 +16174,13 @@
1618916174
<code>$proj</code>
1619016175
<code>$this-&gt;sqlWindowHandle</code>
1619116176
</MixedAssignment>
16192-
<MixedInferredReturnType occurrences="3">
16193-
<code>RemoteWebElement</code>
16194-
<code>RemoteWebElement</code>
16195-
<code>WebDriverElement</code>
16196-
</MixedInferredReturnType>
1619716177
<MixedOperand occurrences="2">
1619816178
<code>$ajax_message_count</code>
1619916179
<code>$proj-&gt;automation_session-&gt;public_url</code>
1620016180
</MixedOperand>
16201-
<MixedPropertyFetch occurrences="2">
16202-
<code>$proj-&gt;automation_session</code>
16181+
<MixedPropertyFetch occurrences="1">
1620316182
<code>$proj-&gt;automation_session-&gt;public_url</code>
1620416183
</MixedPropertyFetch>
16205-
<MixedReturnStatement occurrences="3"/>
1620616184
<RedundantConditionGivenDocblockType occurrences="5">
1620716185
<code>$text &amp;&amp; is_string($text)</code>
1620816186
<code>$text &amp;&amp; is_string($text)</code>

test/selenium/ChangePasswordTest.php

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
namespace PhpMyAdmin\Tests\Selenium;
66

7-
use PHPUnit\Framework\AssertionFailedError;
8-
9-
use function array_push;
107
use function trim;
118

129
/**
@@ -21,13 +18,6 @@ class ChangePasswordTest extends TestBase
2118
*/
2219
protected static $createDatabase = false;
2320

24-
/**
25-
* Array of AssertionFailedError->toString
26-
*
27-
* @var string[]
28-
*/
29-
private $verificationErrors;
30-
3121
/**
3222
* Tests the changing of the password
3323
*
@@ -43,26 +33,15 @@ public function testChangePassword(): void
4333
$this->waitAjax();
4434

4535
$this->waitForElement('xpath', "//span[contains(., 'Change password')]");
46-
try {
47-
$ele = $this->waitForElement('name', 'pma_pw');
48-
$this->assertEquals('', $ele->getAttribute('value'));
49-
} catch (AssertionFailedError $e) {
50-
array_push($this->verificationErrors, $e->getMessage());
51-
}
5236

53-
try {
54-
$ele = $this->waitForElement('name', 'pma_pw2');
55-
$this->assertEquals('', $ele->getAttribute('value'));
56-
} catch (AssertionFailedError $e) {
57-
array_push($this->verificationErrors, $e->getMessage());
58-
}
37+
$ele = $this->waitForElement('name', 'pma_pw');
38+
$this->assertEquals('', $ele->getAttribute('value'));
5939

60-
try {
61-
$ele = $this->waitForElement('name', 'generated_pw');
62-
$this->assertEquals('', $ele->getAttribute('value'));
63-
} catch (AssertionFailedError $e) {
64-
array_push($this->verificationErrors, $e->getMessage());
65-
}
40+
$ele = $this->waitForElement('name', 'pma_pw2');
41+
$this->assertEquals('', $ele->getAttribute('value'));
42+
43+
$ele = $this->waitForElement('name', 'generated_pw');
44+
$this->assertEquals('', $ele->getAttribute('value'));
6645

6746
$this->byId('button_generate_password')->click();
6847
$this->assertNotEquals('', $this->byName('pma_pw')->getAttribute('value'));

test/selenium/ExportTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ protected function setUp(): void
3333
/**
3434
* Test for server level export
3535
*
36-
* @param string $plugin Export format
37-
* @param array $expected Array of expected strings
36+
* @param string $plugin Export format
37+
* @param string[] $expected Array of expected strings
3838
*
3939
* @dataProvider exportDataProvider
4040
* @group large
@@ -51,8 +51,8 @@ public function testServerExport(string $plugin, array $expected): void
5151
/**
5252
* Test for db level export
5353
*
54-
* @param string $plugin Export format
55-
* @param array $expected Array of expected strings
54+
* @param string $plugin Export format
55+
* @param string[] $expected Array of expected strings
5656
*
5757
* @dataProvider exportDataProvider
5858
* @group large
@@ -71,8 +71,8 @@ public function testDbExport(string $plugin, array $expected): void
7171
/**
7272
* Test for table level export
7373
*
74-
* @param string $plugin Export format
75-
* @param array $expected Array of expected strings
74+
* @param string $plugin Export format
75+
* @param string[] $expected Array of expected strings
7676
*
7777
* @dataProvider exportDataProvider
7878
* @group large
@@ -91,7 +91,8 @@ public function testTableExport(string $plugin, array $expected): void
9191
}
9292

9393
/**
94-
* Data provider for testServerExport
94+
* @return array<int, array<int, string|array<int, string>>>
95+
* @psalm-return array<int, array{string, string[]}>
9596
*/
9697
public function exportDataProvider(): array
9798
{

test/selenium/TestBase.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@
3333
use function file_put_contents;
3434
use function getenv;
3535
use function is_bool;
36+
use function is_object;
3637
use function is_string;
3738
use function json_decode;
3839
use function json_encode;
3940
use function mb_strtolower;
4041
use function preg_match;
42+
use function property_exists;
4143
use function random_bytes;
4244
use function reset;
4345
use function sprintf;
@@ -732,9 +734,12 @@ public function logOutIfLoggedIn(): void
732734
*/
733735
public function waitForElement(string $func, string $arg): RemoteWebElement
734736
{
735-
return $this->webDriver->wait(30, 500)->until(
737+
$element = $this->webDriver->wait(30, 500)->until(
736738
WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::$func($arg))
737739
);
740+
$this->assertInstanceOf(RemoteWebElement::class, $element);
741+
742+
return $element;
738743
}
739744

740745
/**
@@ -746,9 +751,12 @@ public function waitForElement(string $func, string $arg): RemoteWebElement
746751
*/
747752
public function waitUntilElementIsPresent(string $func, string $arg, int $timeout): RemoteWebElement
748753
{
749-
return $this->webDriver->wait($timeout, 500)->until(
754+
$element = $this->webDriver->wait($timeout, 500)->until(
750755
WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::$func($arg))
751756
);
757+
$this->assertInstanceOf(RemoteWebElement::class, $element);
758+
759+
return $element;
752760
}
753761

754762
/**
@@ -760,9 +768,12 @@ public function waitUntilElementIsPresent(string $func, string $arg, int $timeou
760768
*/
761769
public function waitUntilElementIsVisible(string $func, string $arg, int $timeout): WebDriverElement
762770
{
763-
return $this->webDriver->wait($timeout, 500)->until(
771+
$element = $this->webDriver->wait($timeout, 500)->until(
764772
WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::$func($arg))
765773
);
774+
$this->assertInstanceOf(WebDriverElement::class, $element);
775+
776+
return $element;
766777
}
767778

768779
/**
@@ -1181,8 +1192,7 @@ private function getErrorVideoUrl(): void
11811192
}
11821193

11831194
$proj = json_decode($result);
1184-
// phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
1185-
if (isset($proj->automation_session)) {
1195+
if (is_object($proj) && property_exists($proj, 'automation_session')) {
11861196
// phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
11871197
echo 'Test failed, get more information here: ' . $proj->automation_session->public_url . PHP_EOL;
11881198
}

0 commit comments

Comments
 (0)