Skip to content

Commit

Permalink
Merge pull request #473 from creative-commoners/pulls/4/stop-using-depr
Browse files Browse the repository at this point in the history
API Stop using deprecated API
  • Loading branch information
sabina-talipova authored Dec 5, 2022
2 parents 7c3f5a4 + e116df9 commit 8e6a6c8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/php/Store/SessionStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@
use SilverStripe\ORM\Connect\Database;
use SilverStripe\ORM\DB;
use SilverStripe\Security\Member;
use SilverStripe\Dev\Deprecation;

class SessionStoreTest extends SapphireTest
{
public function testSerializeThrowsExceptionOnFailure()
{
if (Deprecation::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessageMatches('/possibly incorrectly encoded/');
$store = new SessionStore($this->createMock(Member::class));
$store->setState(['some binary' => random_bytes(32)]);
// changing this to __serialize() won't cause RunTimeException to
// be thrown because __serialize() does not use json_encode()
$store->serialize();
}

Expand Down Expand Up @@ -83,7 +89,7 @@ public function testDatabaseIsNotAccessedOnDeserialise()
$member = new Member();
$member->ID = 1;
$store = new SessionStore($member);
$serialised = $store->serialize();
$serialised = $store->__serialize();

// Replace the DB connection with a mock
$connection = DB::get_conn();
Expand All @@ -97,7 +103,7 @@ public function testDatabaseIsNotAccessedOnDeserialise()
DB::set_conn($database);

// Replicate the deserialisation that happens on session start
$store->unserialize($serialised);
$store->__unserialize($serialised);

// Finish the test and allow mock assertions to fail the test
DB::set_conn($connection);
Expand Down

0 comments on commit 8e6a6c8

Please sign in to comment.