Skip to content

Commit

Permalink
Merge pull request phpmyadmin#19074 from kamil-tekiela/testing-phpunit
Browse files Browse the repository at this point in the history
Fixing PHPUnit performance
  • Loading branch information
MauricioFauth authored Mar 25, 2024
2 parents 7d6bddd + abdaefc commit c0e4d31
Show file tree
Hide file tree
Showing 14 changed files with 0 additions and 98 deletions.
2 changes: 0 additions & 2 deletions tests/unit/Controllers/JavaScriptMessagesControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use PhpMyAdmin\Controllers\JavaScriptMessagesController;
use PhpMyAdmin\Http\Factory\ResponseFactory;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\TestCase;

use function json_decode;
Expand All @@ -18,7 +17,6 @@
#[CoversClass(JavaScriptMessagesController::class)]
class JavaScriptMessagesControllerTest extends TestCase
{
#[RunInSeparateProcess]
public function testIndex(): void
{
$response = (new JavaScriptMessagesController(ResponseFactory::create()))();
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/Controllers/SchemaExportControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;

#[CoversClass(SchemaExportController::class)]
class SchemaExportControllerTest extends AbstractTestCase
{
#[RunInSeparateProcess]
public function testExport(): void
{
DatabaseInterface::$instance = $this->createDatabaseInterface();
Expand Down
4 changes: 0 additions & 4 deletions tests/unit/Controllers/Table/GetFieldControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;

use function bin2hex;

#[CoversClass(GetFieldController::class)]
class GetFieldControllerTest extends AbstractTestCase
{
#[PreserveGlobalState(false)]
#[RunInSeparateProcess]
public function testGetFieldController(): void
{
Current::$database = 'test_db';
Expand Down
6 changes: 0 additions & 6 deletions tests/unit/Controllers/ThemeSetControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
use PhpMyAdmin\UserPreferences;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;

#[CoversClass(ThemeSetController::class)]
class ThemeSetControllerTest extends AbstractTestCase
Expand All @@ -28,8 +26,6 @@ protected function setUp(): void
DatabaseInterface::$instance = $this->createDatabaseInterface();
}

#[PreserveGlobalState(false)]
#[RunInSeparateProcess]
public function testSetTheme(): void
{
Config::getInstance()->settings['ThemeManager'] = true;
Expand All @@ -52,8 +48,6 @@ public function testSetTheme(): void

/** @param string[]|string|null $themeName */
#[DataProvider('providerForTestWithoutTheme')]
#[PreserveGlobalState(false)]
#[RunInSeparateProcess]
public function testWithoutTheme(bool $hasThemes, array|string|null $themeName): void
{
Config::getInstance()->settings['ThemeManager'] = $hasThemes;
Expand Down
6 changes: 0 additions & 6 deletions tests/unit/Http/Factory/ServerRequestFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ public function testCreateWithoutProvider(): void
* @psalm-param class-string<UriInterface> $expectedUri
*/
#[DataProvider('providerForTestFromGlobals')]
#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testFromGlobals(string $provider, string $uriFactoryProvider, string $expectedUri): void
{
$this->skipIfNotAvailable($provider);
Expand Down Expand Up @@ -149,8 +147,6 @@ public function testFromGlobals(string $provider, string $uriFactoryProvider, st
* @psalm-param class-string<UriInterface> $expectedUri
*/
#[DataProvider('providerForTestFromGlobals')]
#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testFromGlobals2(string $provider, string $uriFactoryProvider, string $expectedUri): void
{
$this->skipIfNotAvailable($provider);
Expand Down Expand Up @@ -203,8 +199,6 @@ public function testFromGlobals2(string $provider, string $uriFactoryProvider, s
* @psalm-param class-string<UriInterface> $expectedUri
*/
#[DataProvider('providerForTestFromGlobals')]
#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testFromGlobals3(string $provider, string $uriFactoryProvider, string $expectedUri): void
{
$this->skipIfNotAvailable($provider);
Expand Down
6 changes: 0 additions & 6 deletions tests/unit/Plugins/Auth/AuthenticationConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
use PhpMyAdmin\Tests\AbstractTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Medium;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use ReflectionProperty;
use Throwable;

Expand Down Expand Up @@ -57,8 +55,6 @@ protected function tearDown(): void
unset($this->object);
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuth(): void
{
(new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, null);
Expand All @@ -82,8 +78,6 @@ public function testAuthSetUser(): void
);
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthFails(): void
{
Config::getInstance()->settings['Servers'] = [1];
Expand Down
30 changes: 0 additions & 30 deletions tests/unit/Plugins/Auth/AuthenticationCookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Medium;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use ReflectionException;
use ReflectionMethod;
use ReflectionProperty;
Expand Down Expand Up @@ -74,8 +72,6 @@ protected function tearDown(): void
unset($this->object);
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthErrorAJAX(): void
{
$GLOBALS['conn_error'] = true;
Expand Down Expand Up @@ -113,8 +109,6 @@ private function getAuthErrorMockResponse(): void
ErrorHandler::$instance = $mockErrorHandler;
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthError(): void
{
$_REQUEST = [];
Expand Down Expand Up @@ -189,8 +183,6 @@ public function testAuthError(): void
self::assertStringContainsString('<input type="hidden" name="table" value="testTable">', $result);
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthCaptcha(): void
{
$_REQUEST['old_usr'] = '';
Expand Down Expand Up @@ -251,8 +243,6 @@ public function testAuthCaptcha(): void
);
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthCaptchaCheckbox(): void
{
$_REQUEST['old_usr'] = '';
Expand Down Expand Up @@ -315,8 +305,6 @@ public function testAuthCaptchaCheckbox(): void
);
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthHeader(): void
{
$config = Config::getInstance();
Expand All @@ -336,8 +324,6 @@ public function testAuthHeader(): void
self::assertSame(302, $response->getStatusCode());
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthHeaderPartial(): void
{
$config = Config::getInstance();
Expand Down Expand Up @@ -377,8 +363,6 @@ public function testAuthCheckCaptcha(): void
self::assertSame('Missing Captcha verification, maybe it has been blocked by adblock?', $GLOBALS['conn_error']);
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testLogoutDelete(): void
{
$responseStub = new ResponseRendererStub();
Expand Down Expand Up @@ -406,8 +390,6 @@ public function testLogoutDelete(): void
self::assertArrayNotHasKey('pmaAuth-0', $_COOKIE);
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testLogout(): void
{
$responseStub = new ResponseRendererStub();
Expand Down Expand Up @@ -657,8 +639,6 @@ public function testAuthSetUserWithHeaders(): void
$this->object->rememberCredentials();
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthFailsNoPass(): void
{
$this->object = $this->getMockBuilder(AuthenticationCookie::class)
Expand Down Expand Up @@ -727,8 +707,6 @@ public function testAuthFailsTooLongPass(string $password, bool $expected, strin
self::assertSame($GLOBALS['conn_error'], $connError);
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthFailsDeny(): void
{
$this->object = $this->getMockBuilder(AuthenticationCookie::class)
Expand Down Expand Up @@ -759,8 +737,6 @@ public function testAuthFailsDeny(): void
self::assertSame($GLOBALS['conn_error'], 'Access denied!');
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthFailsActivity(): void
{
$this->object = $this->getMockBuilder(AuthenticationCookie::class)
Expand Down Expand Up @@ -798,8 +774,6 @@ public function testAuthFailsActivity(): void
);
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthFailsDBI(): void
{
$this->object = $this->getMockBuilder(AuthenticationCookie::class)
Expand Down Expand Up @@ -841,8 +815,6 @@ public function testAuthFailsDBI(): void
self::assertSame($GLOBALS['conn_error'], '#42 Cannot log in to the MySQL server');
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthFailsErrno(): void
{
$this->object = $this->getMockBuilder(AuthenticationCookie::class)
Expand Down Expand Up @@ -1007,8 +979,6 @@ public function testAuthenticate(): void
* @param mixed[] $rules rules
* @param string $expected expected result
*/
#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
#[DataProvider('checkRulesProvider')]
public function testCheckRules(
string $user,
Expand Down
12 changes: 0 additions & 12 deletions tests/unit/Plugins/Auth/AuthenticationHttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Medium;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use ReflectionProperty;
use Throwable;

Expand Down Expand Up @@ -59,8 +57,6 @@ protected function tearDown(): void
unset($this->object);
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthLogoutUrl(): void
{
$config = Config::getInstance();
Expand All @@ -77,8 +73,6 @@ public function testAuthLogoutUrl(): void
self::assertSame(302, $response->getStatusCode());
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthVerbose(): void
{
$config = Config::getInstance();
Expand All @@ -99,8 +93,6 @@ public function testAuthVerbose(): void
self::assertSame(401, $response->getStatusCode());
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthHost(): void
{
$config = Config::getInstance();
Expand All @@ -122,8 +114,6 @@ public function testAuthHost(): void
self::assertSame(401, $response->getStatusCode());
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthRealm(): void
{
$config = Config::getInstance();
Expand Down Expand Up @@ -276,8 +266,6 @@ public function testAuthSetUser(): void
self::assertSame(3, Current::$server);
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthFails(): void
{
$config = Config::getInstance();
Expand Down
10 changes: 0 additions & 10 deletions tests/unit/Plugins/Auth/AuthenticationSignonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer as ResponseRendererStub;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use ReflectionProperty;
use Throwable;

Expand Down Expand Up @@ -57,8 +55,6 @@ protected function tearDown(): void
unset($this->object);
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuth(): void
{
(new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, null);
Expand All @@ -81,8 +77,6 @@ public function testAuth(): void
self::assertStringContainsString('You must set SignonURL!', $result);
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthLogoutURL(): void
{
$responseStub = new ResponseRendererStub();
Expand All @@ -99,8 +93,6 @@ public function testAuthLogoutURL(): void
self::assertSame(302, $response->getStatusCode());
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthLogout(): void
{
$responseStub = new ResponseRendererStub();
Expand Down Expand Up @@ -151,8 +143,6 @@ public function testAuthCheckSession(): void
self::assertSame('https://example.com/SignonURL', $_SESSION['LAST_SIGNON_URL']);
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testAuthCheckToken(): void
{
$_SESSION = [' PMA_token ' => 'eefefef'];
Expand Down
4 changes: 0 additions & 4 deletions tests/unit/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@

use PhpMyAdmin\Session;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\TestCase;

#[CoversClass(Session::class)]
final class SessionTest extends TestCase
{
#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testSecure(): void
{
$_SESSION[' PMA_token '] = null;
Expand Down
4 changes: 0 additions & 4 deletions tests/unit/Setup/FormProcessingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer as ResponseRendererStub;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use ReflectionProperty;
use Throwable;

Expand All @@ -39,8 +37,6 @@ protected function setUp(): void
Config::getInstance()->settings['ServerDefault'] = 1;
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testProcessFormSet(): void
{
DatabaseInterface::$instance = $this->createDatabaseInterface();
Expand Down
Loading

0 comments on commit c0e4d31

Please sign in to comment.