Skip to content

Commit

Permalink
minor #54785 Remove calls to TestCase::iniSet() and calls to deprec…
Browse files Browse the repository at this point in the history
…ated methods of `MockBuilder` (alexandre-daubois)

This PR was merged into the 5.4 branch.

Discussion
----------

Remove calls to `TestCase::iniSet()` and calls to deprecated methods of `MockBuilder`

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

Last round (before new deprecations 🙂). All deprecations [listed here](https://github.com/sebastianbergmann/phpunit/blob/main/DEPRECATIONS.md) should be gone.

Commits
-------

4d5065ddd9 Remove calls to `TestCase::iniSet()` and calls to deprecated methods of `MockBuilder`
  • Loading branch information
xabbuh committed May 15, 2024
2 parents b4a91a1 + a2622e3 commit e13c456
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 24 deletions.
63 changes: 41 additions & 22 deletions Tests/Session/Storage/NativeSessionStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ class NativeSessionStorageTest extends TestCase
{
private $savePath;

private $initialSessionSaveHandler;
private $initialSessionSavePath;

protected function setUp(): void
{
$this->iniSet('session.save_handler', 'files');
$this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sftest');
$this->initialSessionSaveHandler = ini_set('session.save_handler', 'files');
$this->initialSessionSavePath = ini_set('session.save_path', $this->savePath = sys_get_temp_dir().'/sftest');

if (!is_dir($this->savePath)) {
mkdir($this->savePath);
}
Expand All @@ -52,6 +56,8 @@ protected function tearDown(): void
}

$this->savePath = null;
ini_set('session.save_handler', $this->initialSessionSaveHandler);
ini_set('session.save_path', $this->initialSessionSavePath);
}

protected function getStorage(array $options = []): NativeSessionStorage
Expand Down Expand Up @@ -154,18 +160,26 @@ public function testRegenerationFailureDoesNotFlagStorageAsStarted()

public function testDefaultSessionCacheLimiter()
{
$this->iniSet('session.cache_limiter', 'nocache');
$initialLimiter = ini_set('session.cache_limiter', 'nocache');

new NativeSessionStorage();
$this->assertEquals('', \ini_get('session.cache_limiter'));
try {
new NativeSessionStorage();
$this->assertEquals('', \ini_get('session.cache_limiter'));
} finally {
ini_set('session.cache_limiter', $initialLimiter);
}
}

public function testExplicitSessionCacheLimiter()
{
$this->iniSet('session.cache_limiter', 'nocache');
$initialLimiter = ini_set('session.cache_limiter', 'nocache');

new NativeSessionStorage(['cache_limiter' => 'public']);
$this->assertEquals('public', \ini_get('session.cache_limiter'));
try {
new NativeSessionStorage(['cache_limiter' => 'public']);
$this->assertEquals('public', \ini_get('session.cache_limiter'));
} finally {
ini_set('session.cache_limiter', $initialLimiter);
}
}

public function testCookieOptions()
Expand Down Expand Up @@ -208,20 +222,25 @@ public function testSessionOptions()

public function testSetSaveHandler()
{
$this->iniSet('session.save_handler', 'files');
$storage = $this->getStorage();
$storage->setSaveHandler();
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
$storage->setSaveHandler(null);
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
$storage->setSaveHandler(new SessionHandlerProxy(new NativeFileSessionHandler()));
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
$storage->setSaveHandler(new NativeFileSessionHandler());
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
$storage->setSaveHandler(new SessionHandlerProxy(new NullSessionHandler()));
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
$storage->setSaveHandler(new NullSessionHandler());
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
$initialSaveHandler = ini_set('session.save_handler', 'files');

try {
$storage = $this->getStorage();
$storage->setSaveHandler();
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
$storage->setSaveHandler(null);
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
$storage->setSaveHandler(new SessionHandlerProxy(new NativeFileSessionHandler()));
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
$storage->setSaveHandler(new NativeFileSessionHandler());
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
$storage->setSaveHandler(new SessionHandlerProxy(new NullSessionHandler()));
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
$storage->setSaveHandler(new NullSessionHandler());
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
} finally {
ini_set('session.save_handler', $initialSaveHandler);
}
}

public function testStarted()
Expand Down
10 changes: 8 additions & 2 deletions Tests/Session/Storage/PhpBridgeSessionStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ class PhpBridgeSessionStorageTest extends TestCase
{
private $savePath;

private $initialSessionSaveHandler;
private $initialSessionSavePath;

protected function setUp(): void
{
$this->iniSet('session.save_handler', 'files');
$this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sftest');
$this->initialSessionSaveHandler = ini_set('session.save_handler', 'files');
$this->initialSessionSavePath = ini_set('session.save_path', $this->savePath = sys_get_temp_dir().'/sftest');

if (!is_dir($this->savePath)) {
mkdir($this->savePath);
}
Expand All @@ -48,6 +52,8 @@ protected function tearDown(): void
}

$this->savePath = null;
ini_set('session.save_handler', $this->initialSessionSaveHandler);
ini_set('session.save_path', $this->initialSessionSavePath);
}

protected function getStorage(): PhpBridgeSessionStorage
Expand Down

0 comments on commit e13c456

Please sign in to comment.