Skip to content

Commit

Permalink
Fix phpunit errors
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Jul 28, 2024
1 parent ab87a9c commit e33e6f2
Show file tree
Hide file tree
Showing 25 changed files with 60 additions and 153 deletions.
6 changes: 2 additions & 4 deletions tests/system/Autoloader/AutoloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
use RuntimeException;
use UnnamespacedClass;

Expand Down Expand Up @@ -394,12 +395,9 @@ public function testAutoloaderLoadsNonClassFiles(): void

#[PreserveGlobalState(false)]
#[RunInSeparateProcess]
#[WithoutErrorHandler]
public function testLoadHelpers(): void
{
// Workaround for errors on PHPUnit 10 and PHP 8.3.
// See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619
restore_error_handler();

$config = new Autoload();
$config->helpers[] = 'form';

Expand Down
6 changes: 2 additions & 4 deletions tests/system/CodeIgniterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
use Tests\Support\Filters\Customfilter;
use Tests\Support\Filters\RedirectFilter;

Expand All @@ -48,15 +49,12 @@ final class CodeIgniterTest extends CIUnitTestCase
private CodeIgniter $codeigniter;
protected $routes;

#[WithoutErrorHandler]
protected function setUp(): void
{
parent::setUp();
$this->resetServices();

// Workaround for errors on PHPUnit 10 and PHP 8.3.
// See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619
restore_error_handler();

$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';

$this->codeigniter = new MockCodeIgniter(new App());
Expand Down
6 changes: 2 additions & 4 deletions tests/system/Commands/GenerateKeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\Attributes\WithoutErrorHandler;

/**
* @internal
Expand All @@ -31,6 +32,7 @@ final class GenerateKeyTest extends CIUnitTestCase
private string $envPath;
private string $backupEnvPath;

#[WithoutErrorHandler]
protected function setUp(): void
{
parent::setUp();
Expand All @@ -43,10 +45,6 @@ protected function setUp(): void
}

$this->resetEnvironment();

// Workaround for errors on PHPUnit 10 and PHP 8.3.
// See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619
restore_error_handler();
}

protected function tearDown(): void
Expand Down
6 changes: 2 additions & 4 deletions tests/system/CommonFunctionsSendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,20 @@
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\Attributes\WithoutErrorHandler;

/**
* @internal
*/
#[Group('SeparateProcess')]
final class CommonFunctionsSendTest extends CIUnitTestCase
{
#[WithoutErrorHandler]
protected function setUp(): void
{
parent::setUp();

unset($_ENV['foo'], $_SERVER['foo']);

// Workaround for errors on PHPUnit 10 and PHP 8.3.
// See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619
restore_error_handler();
}

/**
Expand Down
51 changes: 10 additions & 41 deletions tests/system/CommonFunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
use RuntimeException;
use stdClass;
use Tests\Support\Models\JobModel;
Expand Down Expand Up @@ -274,25 +275,19 @@ public function testEscapeRecursiveArrayRaw(): void

#[PreserveGlobalState(false)]
#[RunInSeparateProcess]
#[WithoutErrorHandler]
public function testSessionInstance(): void
{
// Workaround for errors on PHPUnit 10 and PHP 8.3.
// See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619
restore_error_handler();

$this->injectSessionMock();

$this->assertInstanceOf(Session::class, session());
}

#[PreserveGlobalState(false)]
#[RunInSeparateProcess]
#[WithoutErrorHandler]
public function testSessionVariable(): void
{
// Workaround for errors on PHPUnit 10 and PHP 8.3.
// See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619
restore_error_handler();

$this->injectSessionMock();

$_SESSION['notbogus'] = 'Hi there';
Expand All @@ -302,12 +297,9 @@ public function testSessionVariable(): void

#[PreserveGlobalState(false)]
#[RunInSeparateProcess]
#[WithoutErrorHandler]
public function testSessionVariableNotThere(): void
{
// Workaround for errors on PHPUnit 10 and PHP 8.3.
// See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619
restore_error_handler();

$this->injectSessionMock();

$_SESSION['bogus'] = 'Hi there';
Expand Down Expand Up @@ -428,12 +420,9 @@ public function testModelExistsAbsoluteClassname(): void

#[PreserveGlobalState(false)]
#[RunInSeparateProcess]
#[WithoutErrorHandler]
public function testOldInput(): void
{
// Workaround for errors on PHPUnit 10 and PHP 8.3.
// See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619
restore_error_handler();

$this->injectSessionMock();
// setup from RedirectResponseTest...
$_SERVER['REQUEST_METHOD'] = 'GET';
Expand Down Expand Up @@ -465,12 +454,9 @@ public function testOldInput(): void

#[PreserveGlobalState(false)]
#[RunInSeparateProcess]
#[WithoutErrorHandler]
public function testOldInputSerializeData(): void
{
// Workaround for errors on PHPUnit 10 and PHP 8.3.
// See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619
restore_error_handler();

$this->injectSessionMock();
// setup from RedirectResponseTest...
$_SERVER['REQUEST_METHOD'] = 'GET';
Expand Down Expand Up @@ -503,12 +489,9 @@ public function testOldInputSerializeData(): void
*/
#[PreserveGlobalState(false)]
#[RunInSeparateProcess]
#[WithoutErrorHandler]
public function testOldInputArray(): void
{
// Workaround for errors on PHPUnit 10 and PHP 8.3.
// See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619
restore_error_handler();

$this->injectSessionMock();
// setup from RedirectResponseTest...
$_SERVER['REQUEST_METHOD'] = 'GET';
Expand Down Expand Up @@ -622,12 +605,9 @@ public function testRedirectResponseCookies1(): void

#[PreserveGlobalState(false)]
#[RunInSeparateProcess]
#[WithoutErrorHandler]
public function testTrace(): void
{
// Workaround for errors on PHPUnit 10 and PHP 8.3.
// See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619
restore_error_handler();

ob_start();
trace();
$content = ob_get_clean();
Expand All @@ -647,12 +627,9 @@ public function testViewNotSaveData(): void

#[PreserveGlobalState(false)]
#[RunInSeparateProcess]
#[WithoutErrorHandler]
public function testForceHttpsNullRequestAndResponse(): void
{
// Workaround for errors on PHPUnit 10 and PHP 8.3.
// See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619
restore_error_handler();

$this->assertNull(Services::response()->header('Location'));

Services::response()->setCookie('force', 'cookie');
Expand Down Expand Up @@ -763,12 +740,9 @@ public function testDWithCSP(): void

#[PreserveGlobalState(false)]
#[RunInSeparateProcess]
#[WithoutErrorHandler]
public function testTraceWithCSP(): void
{
// Workaround for errors on PHPUnit 10 and PHP 8.3.
// See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619
restore_error_handler();

$this->resetServices();

/** @var App $config */
Expand All @@ -780,11 +754,6 @@ public function testTraceWithCSP(): void

Kint::$cli_detection = false;

// Workaround for errors on PHPUnit 10 and PHP 8.3.
// See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619
// `$app->initialize()` sets error handler.
restore_error_handler();

$this->expectOutputRegex('/<style class="kint-rich-style" nonce="[0-9a-z]{24}">/u');
trace();
}
Expand Down
6 changes: 2 additions & 4 deletions tests/system/Config/BaseConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
use PHPUnit\Framework\MockObject\MockObject;
use RegistrarConfig;
use RuntimeException;
Expand All @@ -35,6 +36,7 @@ final class BaseConfigTest extends CIUnitTestCase
{
private string $fixturesFolder;

#[WithoutErrorHandler]
protected function setUp(): void
{
parent::setUp();
Expand All @@ -54,10 +56,6 @@ protected function setUp(): void
}

BaseConfig::reset();

// Workaround for errors on PHPUnit 10 and PHP 8.3.
// See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619
restore_error_handler();
}

protected function tearDown(): void
Expand Down
6 changes: 2 additions & 4 deletions tests/system/Config/DotEnvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
use TypeError;

/**
Expand All @@ -34,6 +35,7 @@ final class DotEnvTest extends CIUnitTestCase
private string $path;
private string $fixturesFolder;

#[WithoutErrorHandler]
protected function setUp(): void
{
parent::setUp();
Expand All @@ -46,10 +48,6 @@ protected function setUp(): void
$file = 'unreadable.env';
$path = rtrim($this->fixturesFolder, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file;
chmod($path, 0644);

// Workaround for errors on PHPUnit 10 and PHP 8.3.
// See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619
restore_error_handler();
}

protected function tearDown(): void
Expand Down
6 changes: 2 additions & 4 deletions tests/system/Config/ServicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
use RuntimeException;
use Tests\Support\Config\Services;

Expand All @@ -63,15 +64,12 @@ final class ServicesTest extends CIUnitTestCase
{
private array $original;

#[WithoutErrorHandler]
protected function setUp(): void
{
parent::setUp();

$this->original = $_SERVER;

// Workaround for errors on PHPUnit 10 and PHP 8.3.
// See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619
restore_error_handler();
}

protected function tearDown(): void
Expand Down
6 changes: 2 additions & 4 deletions tests/system/Events/EventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\Attributes\WithoutErrorHandler;

/**
* @internal
Expand All @@ -31,17 +32,14 @@ final class EventsTest extends CIUnitTestCase
*/
private Events $manager;

#[WithoutErrorHandler]
protected function setUp(): void
{
parent::setUp();

$this->manager = new MockEvents();

Events::removeAllListeners();

// Workaround for errors on PHPUnit 10 and PHP 8.3.
// See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619
restore_error_handler();
}

protected function tearDown(): void
Expand Down
6 changes: 2 additions & 4 deletions tests/system/Filters/HoneypotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\Attributes\WithoutErrorHandler;

/**
* @internal
Expand All @@ -42,6 +43,7 @@ final class HoneypotTest extends CIUnitTestCase

private ?Response $response = null;

#[WithoutErrorHandler]
protected function setUp(): void
{
parent::setUp();
Expand All @@ -51,10 +53,6 @@ protected function setUp(): void
unset($_POST[$this->honey->name]);
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST[$this->honey->name] = 'hey';

// Workaround for errors on PHPUnit 10 and PHP 8.3.
// See https://github.com/sebastianbergmann/phpunit/issues/5403#issuecomment-1906810619
restore_error_handler();
}

public function testBeforeTriggered(): void
Expand Down
Loading

0 comments on commit e33e6f2

Please sign in to comment.