-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(KzNUCYHy): ConnectionException tests for Mysqli & Pdo_Mysql drivers
- Loading branch information
1 parent
2293f79
commit 509ccd7
Showing
4 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
test/functional/DataStore/DataStore/ConnectionExceptionTest/BaseTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
|
||
namespace rollun\test\functional\DataStore\DataStore\ConnectionExceptionTest; | ||
|
||
use rollun\datastore\DataStore\ConnectionException; | ||
use rollun\datastore\DataStore\Interfaces\DataStoreInterface; | ||
use rollun\test\functional\FunctionalTestCase; | ||
use Xiag\Rql\Parser\Node\Query\ScalarOperator\EqNode; | ||
use Xiag\Rql\Parser\Query; | ||
|
||
abstract class BaseTest extends FunctionalTestCase | ||
{ | ||
/** | ||
* Should return dataStore that have problems with connection | ||
*/ | ||
abstract protected function getDbTableDataStore(): DataStoreInterface; | ||
|
||
public function testCreate(): void | ||
{ | ||
$this->expectException(ConnectionException::class); | ||
|
||
$this->getDbTableDataStore()->create(['id' => 1, 'value' => 'foo']); | ||
} | ||
|
||
public function testMultiCreate(): void | ||
{ | ||
$this->expectException(ConnectionException::class); | ||
|
||
$this->getDbTableDataStore()->multiCreate([ | ||
['id' => 1, 'value' => 'foo'], | ||
['id' => 2, 'value' => 'bar'], | ||
]); | ||
} | ||
|
||
public function testUpdate(): void | ||
{ | ||
$this->expectException(ConnectionException::class); | ||
|
||
$this->getDbTableDataStore()->update(['id' => 1, 'value' => 'foo']); | ||
} | ||
|
||
public function testMultiUpdate(): void | ||
{ | ||
$updatedRecords = $this->getDbTableDataStore()->multiUpdate([ | ||
['id' => 1, 'value' => 'foo'], | ||
['id' => 2, 'value' => 'bar'], | ||
]); | ||
|
||
// Any exceptions that are thrown while updating records are simply ignored in this method. | ||
// Therefore, the best we can do is to check that nothing has been updated. | ||
self::assertEmpty($updatedRecords); | ||
} | ||
|
||
public function testQueriedUpdate(): void | ||
{ | ||
$this->expectException(ConnectionException::class); | ||
|
||
$this->getDbTableDataStore()->queriedUpdate(['id' => 1, 'value' => 'foo'], $this->getQuery()); | ||
} | ||
|
||
public function testRewrite(): void | ||
{ | ||
$this->expectException(ConnectionException::class); | ||
|
||
$this->getDbTableDataStore()->rewrite(['id' => 1, 'value' => 'foo']); | ||
} | ||
|
||
public function testDelete(): void | ||
{ | ||
$this->expectException(ConnectionException::class); | ||
|
||
$this->getDbTableDataStore()->delete(1); | ||
} | ||
|
||
public function testQueriedDelete(): void | ||
{ | ||
$this->expectException(ConnectionException::class); | ||
|
||
$this->getDbTableDataStore()->queriedDelete($this->getQuery()); | ||
} | ||
|
||
public function testRead(): void | ||
{ | ||
$this->expectException(ConnectionException::class); | ||
|
||
$this->getDbTableDataStore()->read(1); | ||
} | ||
|
||
public function testHas(): void | ||
{ | ||
$this->expectException(ConnectionException::class); | ||
|
||
$this->getDbTableDataStore()->has(1); | ||
} | ||
|
||
public function testQuery(): void | ||
{ | ||
$this->expectException(ConnectionException::class); | ||
|
||
$this->getDbTableDataStore()->query($this->getQuery()); | ||
} | ||
|
||
private function getQuery(): Query | ||
{ | ||
$query = new Query(); | ||
$query->setQuery(new EqNode('value', 'foo')); | ||
return $query; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...nctional/DataStore/DataStore/ConnectionExceptionTest/DbTableMysqliDriverDataStoreTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace rollun\test\functional\DataStore\DataStore\ConnectionExceptionTest; | ||
|
||
use Laminas\Db\TableGateway\TableGateway; | ||
use rollun\datastore\DataStore\DbTable; | ||
|
||
class DbTableMysqliDriverDataStoreTest extends BaseTest | ||
{ | ||
protected function getDbTableDataStore(): DbTable | ||
{ | ||
return new DbTable( | ||
new TableGateway( | ||
table: 'pdo-connection-test', | ||
adapter: $this->getContainer()->get('db.mysqli.wrong-connection') | ||
) | ||
); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
.../functional/DataStore/DataStore/ConnectionExceptionTest/DbTablePdoDriverDataStoreTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace rollun\test\functional\DataStore\DataStore\ConnectionExceptionTest; | ||
|
||
use Laminas\Db\TableGateway\TableGateway; | ||
use rollun\datastore\DataStore\DbTable; | ||
|
||
class DbTablePdoDriverDataStoreTest extends BaseTest | ||
{ | ||
protected function getDbTableDataStore(): DbTable | ||
{ | ||
return new DbTable( | ||
new TableGateway( | ||
table: 'pdo-connection-test', | ||
adapter: $this->getContainer()->get('db.pdo.wrong-connection') | ||
) | ||
); | ||
} | ||
} |
509ccd7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.