Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install semantic-result-formats dev-master for MW 1.42 #85

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"php-parallel-lint/php-console-highlighter": "1.0.0",
"php-parallel-lint/php-parallel-lint": "1.4.0",
"phpstan/phpstan": "^1.7",
"vimeo/psalm": "^4.23"
"vimeo/psalm": "^5.26"
},
"scripts": {
"test": [
Expand Down
13 changes: 7 additions & 6 deletions includes/TemporaryTableManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

namespace SD;

use DatabaseBase;
use Wikimedia\Rdbms\Database;
use Wikimedia\Rdbms\IDatabase;

/**
* Provides helper method to execute SQL queries in auto-commit mode
*/

class TemporaryTableManager {
/** @var \Wikimedia\Rdbms\IDatabase|DatabaseBase */
/** @var \Wikimedia\Rdbms\IDatabase|Database */
private $databaseConnection;

/**
* TemporaryTableManager constructor.
* @param \Wikimedia\Rdbms\IDatabase|DatabaseBase $databaseConnection the DB connection to execute queries against
* @param \Wikimedia\Rdbms\IDatabase|Database $databaseConnection the DB connection to execute queries against
*/
public function __construct( $databaseConnection ) {
$this->databaseConnection = $databaseConnection;
Expand All @@ -28,8 +29,8 @@ public function __construct( $databaseConnection ) {
* @param string $method method name to log for query, defaults to this method
*/
public function queryWithAutoCommit( $sqlQuery, $method = __METHOD__ ) {
$wasAutoTrx = $this->databaseConnection->getFlag( DBO_TRX );
$this->databaseConnection->clearFlag( DBO_TRX );
$wasAutoTrx = $this->databaseConnection->getFlag( IDatabase::DBO_TRX );
$this->databaseConnection->clearFlag( IDatabase::DBO_TRX );

// If a transaction was automatically started on first query, make sure we commit it
if ( $wasAutoTrx && $this->databaseConnection->trxLevel() ) {
Expand All @@ -43,7 +44,7 @@ public function queryWithAutoCommit( $sqlQuery, $method = __METHOD__ ) {
}

if ( $wasAutoTrx ) {
$this->databaseConnection->setFlag( DBO_TRX );
$this->databaseConnection->setFlag( IDatabase::DBO_TRX );
}
}
}
14 changes: 8 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
cacheTokens="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
Expand All @@ -10,15 +11,16 @@
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stderr="true"
verbose="true">
<testsuites>
<testsuite name="semantic-drilldown">
<directory>tests/phpunit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">includes</directory>
</whitelist>
</filter>
</include>
</coverage>
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @group SD
* @group Database
* @group SMWExtension
* @group Database
*/
class JsonTestCaseScriptRunnerTest extends JSONScriptTestCaseRunnerTest {

Expand Down
23 changes: 10 additions & 13 deletions tests/phpunit/Unit/TemporaryTableManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

namespace SD\Tests\Unit;

use DatabaseBase;
use PHPUnit;
use SD\TemporaryTableManager;
use Wikimedia;
use const DBO_TRX;
use Wikimedia\Rdbms\Database;
use Wikimedia\Rdbms\IDatabase;

/**
* @covers \SD\TemporaryTableManager
*/
class TemporaryTableManagerTest extends PHPUnit\Framework\TestCase {
/** @var DatabaseBase|\Wikimedia\Rdbms\IDatabase */
class TemporaryTableManagerTest extends \PHPUnit\Framework\TestCase {
/** @var Database|IDatabase */
private $databaseConnectionMock;

/** @var TemporaryTableManager */
Expand All @@ -22,8 +20,7 @@ protected function setUp(): void {
parent::setUp();

// Database::commit is final, cannot be mocked - we must use interface :/
$dbClassName = class_exists( DatabaseType::class ) ? DatabaseType::class : Wikimedia\Rdbms\IDatabase::class;
$this->databaseConnectionMock = $this->getMockBuilder( $dbClassName )
$this->databaseConnectionMock = $this->getMockBuilder( IDatabase::class )
->disableOriginalConstructor()
->getMock();

Expand All @@ -37,7 +34,7 @@ protected function setUp(): void {
public function testTransactionStateAndFlagsAreNotManipulatedWhenDboTrxIsNotSet( $sqlQuery ) {
$this->databaseConnectionMock->expects( $this->any() )
->method( 'getFlag' )
->with( DBO_TRX )
->with( IDatabase::DBO_TRX )
->willReturn( false );

$this->databaseConnectionMock->expects( $this->once() )
Expand All @@ -61,7 +58,7 @@ public function testDboTrxFlagIsPreservedButCommitIsNotCalledIfDboTrxIsSetWithNo
) {
$this->databaseConnectionMock->expects( $this->any() )
->method( 'getFlag' )
->with( DBO_TRX )
->with( IDatabase::DBO_TRX )
->willReturn( true );
$this->databaseConnectionMock->expects( $this->any() )
->method( 'trxLevel' )
Expand All @@ -75,7 +72,7 @@ public function testDboTrxFlagIsPreservedButCommitIsNotCalledIfDboTrxIsSetWithNo
->method( 'startAtomic' );
$this->databaseConnectionMock->expects( $this->once() )
->method( 'setFlag' )
->with( DBO_TRX );
->with( IDatabase::DBO_TRX );

$this->temporaryTableManager->queryWithAutoCommit( $sqlQuery );
}
Expand All @@ -89,7 +86,7 @@ public function testDboTrxFlagIsPreservedAndCommitIsCalledIfDboTrxIsSetWithOpenT
) {
$this->databaseConnectionMock->expects( $this->any() )
->method( 'getFlag' )
->with( DBO_TRX )
->with( IDatabase::DBO_TRX )
->willReturn( true );
$this->databaseConnectionMock->expects( $this->any() )
->method( 'trxLevel' )
Expand All @@ -103,7 +100,7 @@ public function testDboTrxFlagIsPreservedAndCommitIsCalledIfDboTrxIsSetWithOpenT
->method( 'startAtomic' );
$this->databaseConnectionMock->expects( $this->once() )
->method( 'setFlag' )
->with( DBO_TRX );
->with( IDatabase::DBO_TRX );

$this->temporaryTableManager->queryWithAutoCommit( $sqlQuery );
}
Expand Down
Loading