Skip to content

Commit

Permalink
Merge pull request #567 from creative-commoners/pulls/6/phpunit12
Browse files Browse the repository at this point in the history
MNT Fix PHPUnit 12 deprecations
  • Loading branch information
GuySartorelli authored Sep 23, 2024
2 parents 54d8092 + 114065e commit a52ef44
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions tests/php/Store/SessionStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use SilverStripe\Dev\SapphireTest;
use SilverStripe\MFA\Store\SessionStore;
use SilverStripe\ORM\Connect\Database;
use SilverStripe\ORM\Connect\MySQLDatabase;
use SilverStripe\ORM\DB;
use SilverStripe\Security\Member;

Expand Down Expand Up @@ -78,18 +79,26 @@ public function testDatabaseIsNotAccessedOnDeserialise()

// Replace the DB connection with a mock
$connection = DB::get_conn();
$database = $this->getMockBuilder(Database::class)
->enableProxyingToOriginalMethods()
->setProxyTarget($connection)
->getMock();

$database->expects($this->never())->method('query');
$database->expects($this->never())->method('preparedQuery');
DB::set_conn($database);
$mock = new class ($connection) extends MySQLDatabase {
public int $queryNum = 0;
public int $preparedQueryNum = 0;
public function query($sql, $errorLevel = E_USER_ERROR)
{
$this->queryNum++;
}
public function preparedQuery($sql, $parameters, $errorLevel = E_USER_ERROR)
{
$this->preparedQueryNum++;
}
};
DB::set_conn($mock);

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

$this->assertSame(0, $mock->queryNum);
$this->assertSame(0, $mock->preparedQueryNum);

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

0 comments on commit a52ef44

Please sign in to comment.