Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove
src\TestSupport
from yiisoft\db
.
- Loading branch information
1 parent
2ae89ee
commit 30411a8
Showing
13 changed files
with
334 additions
and
401 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
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
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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Sqlite\Tests\Builder; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Yiisoft\Db\Exception\Exception; | ||
use Yiisoft\Db\Exception\InvalidArgumentException; | ||
use Yiisoft\Db\Exception\InvalidConfigException; | ||
use Yiisoft\Db\Exception\NotSupportedException; | ||
use Yiisoft\Db\Query\Query; | ||
use Yiisoft\Db\QueryBuilder\Condition\InCondition; | ||
use Yiisoft\Db\Sqlite\Builder\InConditionBuilder; | ||
use Yiisoft\Db\Sqlite\Tests\Support\TestTrait; | ||
|
||
/** | ||
* @group sqlite | ||
*/ | ||
final class InconditionBuilderTest extends TestCase | ||
{ | ||
use TestTrait; | ||
|
||
/** | ||
* @throws Exception | ||
* @throws InvalidArgumentException | ||
* @throws InvalidConfigException | ||
*/ | ||
public function testBuildSubqueryInCondition(): void | ||
{ | ||
$db = $this->getConnection(); | ||
$inCondition = new InCondition( | ||
['id'], | ||
'in', | ||
(new Query($db))->select('id')->from('users')->where(['active' => 1]), | ||
); | ||
|
||
$this->expectException(NotSupportedException::class); | ||
$this->expectExceptionMessage( | ||
'Yiisoft\Db\Sqlite\Builder\InConditionBuilder::buildSubqueryInCondition is not supported by SQLite.' | ||
); | ||
|
||
(new InConditionBuilder($db->getQueryBuilder()))->build($inCondition); | ||
} | ||
} |
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
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
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,113 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Sqlite\Tests; | ||
|
||
use Throwable; | ||
use Yiisoft\Db\Exception\Exception; | ||
use Yiisoft\Db\Exception\InvalidCallException; | ||
use Yiisoft\Db\Exception\InvalidConfigException; | ||
use Yiisoft\Db\Exception\NotSupportedException; | ||
use Yiisoft\Db\Sqlite\Tests\Support\TestTrait; | ||
use Yiisoft\Db\Tests\Common\CommonConnectionPDOTest; | ||
use Yiisoft\Db\Transaction\TransactionInterface; | ||
|
||
/** | ||
* @group pgsql | ||
* | ||
* @psalm-suppress PropertyNotSetInConstructor | ||
*/ | ||
final class ConnectionPDOTest extends CommonConnectionPDOTest | ||
{ | ||
use TestTrait; | ||
|
||
/** | ||
* Ensure database connection is reset on when a connection is cloned. | ||
* | ||
* Make sure each connection element has its own PDO instance i.e. own connection to the DB. | ||
* Also, transaction elements should not be shared between two connections. | ||
* | ||
* @throws Exception | ||
* @throws Throwable | ||
*/ | ||
public function testClone(): void | ||
{ | ||
$this->setDsn('sqlite:' . __DIR__ . '/Support/Runtime/yiitest.sq3'); | ||
|
||
$db = $this->getConnection(); | ||
|
||
$this->assertNull($db->getTransaction()); | ||
$this->assertNull($db->getPDO()); | ||
|
||
$db->open(); | ||
|
||
$this->assertNull($db->getTransaction()); | ||
$this->assertNotNull($db->getPDO()); | ||
|
||
$conn2 = clone $db; | ||
|
||
$this->assertNull($db->getTransaction()); | ||
$this->assertNotNull($db->getPDO()); | ||
|
||
$this->assertNull($conn2->getTransaction()); | ||
$this->assertNull($conn2->getPDO()); | ||
|
||
$db->beginTransaction(); | ||
|
||
$this->assertNotNull($db->getTransaction()); | ||
$this->assertNotNull($db->getPDO()); | ||
|
||
$this->assertNull($conn2->getTransaction()); | ||
$this->assertNull($conn2->getPDO()); | ||
|
||
$conn3 = clone $db; | ||
|
||
$this->assertNotNull($db->getTransaction()); | ||
$this->assertNotNull($db->getPDO()); | ||
$this->assertNull($conn3->getTransaction()); | ||
$this->assertNull($conn3->getPDO()); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
* @throws InvalidConfigException | ||
* @throws InvalidCallException | ||
* @throws Throwable | ||
*/ | ||
public function testGetLastInsertID(): void | ||
{ | ||
$db = $this->getConnection(true); | ||
|
||
$command = $db->createCommand(); | ||
$command->insert( | ||
'customer', | ||
[ | ||
'name' => 'Some {{weird}} name', | ||
'email' => 'test@example.com', | ||
'address' => 'Some {{%weird}} address', | ||
] | ||
)->execute(); | ||
|
||
$this->assertSame('4', $db->getLastInsertID()); | ||
|
||
$db->close(); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
* @throws InvalidConfigException | ||
* @throws Throwable | ||
*/ | ||
public function testTransactionIsolationException(): void | ||
{ | ||
$db = $this->getConnection(); | ||
|
||
$this->expectException(NotSupportedException::class); | ||
$this->expectExceptionMessage( | ||
'Yiisoft\Db\Sqlite\TransactionPDO only supports transaction isolation levels READ UNCOMMITTED and SERIALIZABLE.' | ||
); | ||
|
||
$db->beginTransaction(TransactionInterface::READ_COMMITTED); | ||
} | ||
} |
Oops, something went wrong.