-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
2,397 additions
and
0 deletions.
There are no files selected for viewing
143 changes: 143 additions & 0 deletions
143
tests/integration/DM/Pdo/Connection/CommitInTransactionRollBackCest.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,143 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Phalcon Framework. | ||
* | ||
* For the full copyright and license information, please view the LICENSE.md | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phalcon\Test\Integration\DM\Pdo\Connection; | ||
|
||
use IntegrationTester; | ||
use Phalcon\DM\Pdo\Connection; | ||
use Phalcon\Test\Fixtures\Migrations\Invoices; | ||
|
||
use function date; | ||
use function str_replace; | ||
use function uniqid; | ||
|
||
class CommitInTransactionRollBackCest | ||
{ | ||
/** | ||
* Integration Tests Phalcon\DM\Pdo\Connection :: commit()/inTransaction() | ||
* | ||
* @since 2020-01-25 | ||
*/ | ||
public function dMPdoConnectionCommitInTransaction(IntegrationTester $I) | ||
{ | ||
$I->wantToTest('DM\Pdo\Connection - commit()/inTransaction()'); | ||
|
||
/** @var Connection $connection */ | ||
$connection = $I->getConnection(); | ||
(new Invoices($connection)); | ||
$connection->beginTransaction(); | ||
|
||
$I->assertTrue($connection->inTransaction()); | ||
|
||
$template = 'insert into co_invoices (inv_id, inv_cst_id, inv_status_flag, ' | ||
. 'inv_title, inv_total, inv_created_at) values (' | ||
. '%id%, 1, 1, "%title%", %total%, "%now%")'; | ||
|
||
$sql = str_replace( | ||
[ | ||
'%id%', | ||
'%title%', | ||
'%total%', | ||
'%now%', | ||
], | ||
[ | ||
2, | ||
uniqid(), | ||
102, | ||
date('Y-m-d H:i:s'), | ||
], | ||
$template | ||
); | ||
|
||
$result = $connection->exec($sql); | ||
$I->assertEquals(1, $result); | ||
|
||
$connection->commit(); | ||
|
||
/** | ||
* Committed record | ||
*/ | ||
$all = $connection | ||
->fetchOne( | ||
'select * from co_invoices WHERE inv_id = ?', | ||
[ | ||
0 => 2, | ||
] | ||
); | ||
|
||
$I->assertIsArray($all); | ||
$I->assertEquals(2, $all['inv_id']); | ||
} | ||
|
||
/** | ||
* Integration Tests Phalcon\DM\Pdo\Connection :: rollBack() | ||
* | ||
* @since 2020-01-25 | ||
*/ | ||
public function dMPdoConnectionRollBack(IntegrationTester $I) | ||
{ | ||
$I->wantToTest('DM\Pdo\Connection - rollBack()'); | ||
|
||
/** @var Connection $connection */ | ||
$connection = $I->getConnection(); | ||
(new Invoices($connection)); | ||
$connection->beginTransaction(); | ||
|
||
$I->assertTrue($connection->inTransaction()); | ||
|
||
$template = 'insert into co_invoices (inv_id, inv_cst_id, inv_status_flag, ' | ||
. 'inv_title, inv_total, inv_created_at) values (' | ||
. '%id%, 1, 1, "%title%", %total%, "%now%")'; | ||
|
||
$sql = str_replace( | ||
[ | ||
'%id%', | ||
'%title%', | ||
'%total%', | ||
'%now%', | ||
], | ||
[ | ||
2, | ||
uniqid(), | ||
102, | ||
date('Y-m-d H:i:s'), | ||
], | ||
$template | ||
); | ||
|
||
$result = $connection->exec($sql); | ||
$I->assertEquals(1, $result); | ||
|
||
/** | ||
* Committed record | ||
*/ | ||
$all = $connection | ||
->fetchOne( | ||
'select * from co_invoices WHERE inv_id = ?', | ||
[ | ||
0 => 2, | ||
] | ||
); | ||
|
||
$connection->rollBack(); | ||
|
||
$all = $connection | ||
->fetchOne( | ||
'select * from co_invoices WHERE inv_id = ?', | ||
[ | ||
0 => 2, | ||
] | ||
); | ||
|
||
$I->assertIsArray($all); | ||
$I->assertEmpty($all); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
tests/integration/DM/Pdo/Connection/ConnectDisconnectIsConnectedCest.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,74 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Phalcon Framework. | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phalcon\Test\Integration\DM\Pdo\Connection; | ||
|
||
use IntegrationTester; | ||
use Phalcon\DM\Pdo\Connection; | ||
|
||
class ConnectDisconnectIsConnectedCest | ||
{ | ||
/** | ||
* Integration Tests Phalcon\DM\Pdo\Connection :: | ||
* connect()/disconnect()/isConnected() | ||
* | ||
* @since 2020-01-25 | ||
*/ | ||
public function dMPdoConnectionConnectDisconnectIsConnected(IntegrationTester $I) | ||
{ | ||
$I->wantToTest('DM\Pdo\Connection - connect()/disconnect()/isConnected()'); | ||
|
||
/** @var Connection $connection */ | ||
$connection = $I->getConnection(); | ||
|
||
$I->assertFalse($connection->isConnected()); | ||
$connection->connect(); | ||
$I->assertTrue($connection->isConnected()); | ||
$connection->disconnect(); | ||
$I->assertFalse($connection->isConnected()); | ||
} | ||
|
||
/** | ||
* Integration Tests Phalcon\DM\Pdo\Connection :: connect() - queries | ||
* | ||
* @since 2020-01-25 | ||
*/ | ||
public function dMPdoConnectionConnectQueries(IntegrationTester $I) | ||
{ | ||
$I->wantToTest('DM\Pdo\Connection - connect() - queries'); | ||
|
||
if ('mysql' === $I->getAdapter()) { | ||
/** @var Connection $connection */ | ||
$connection = new Connection( | ||
$I->getDatabaseDsn(), | ||
$I->getDatabaseUsername(), | ||
$I->getDatabasePassword(), | ||
[], | ||
[ | ||
'set names big5', | ||
] | ||
); | ||
|
||
$I->assertFalse($connection->isConnected()); | ||
$result = $connection->fetchOne( | ||
'show variables like "character_set_client"' | ||
); | ||
|
||
$I->assertTrue($connection->isConnected()); | ||
$expeced = [ | ||
'Variable_name' => 'character_set_client', | ||
'Value' => 'big5', | ||
]; | ||
|
||
$I->assertEquals($expeced, $result); | ||
} | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Phalcon Framework. | ||
* | ||
* For the full copyright and license information, please view the LICENSE.md | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phalcon\Test\Integration\DM\Pdo\Connection; | ||
|
||
use IntegrationTester; | ||
use InvalidArgumentException; | ||
use Phalcon\DM\Pdo\Connection; | ||
|
||
class ConstructCest | ||
{ | ||
/** | ||
* Integration Tests Phalcon\DM\Pdo\Connection :: __construct() | ||
* | ||
* @since 2020-01-25 | ||
*/ | ||
public function dMPdoConnectionConstruct(IntegrationTester $I) | ||
{ | ||
$I->wantToTest('DM\Pdo\Connection - __construct()'); | ||
|
||
/** @var Connection $connection */ | ||
$connection = $I->getConnection(); | ||
|
||
$I->assertInstanceOf(Connection::class, $connection); | ||
} | ||
|
||
/** | ||
* Integration Tests Phalcon\DM\Pdo\Connection :: __construct() - exception | ||
* | ||
* @since 2020-01-20 | ||
*/ | ||
public function dMPdoConnectionConstructException(IntegrationTester $I) | ||
{ | ||
$I->wantToTest('DM\Pdo\Connection - __construct() - exception'); | ||
|
||
$I->expectThrowable( | ||
new InvalidArgumentException( | ||
"Driver not supported [random]" | ||
), | ||
function () { | ||
(new Connection('random:some data')); | ||
} | ||
); | ||
} | ||
} |
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 | ||
|
||
/** | ||
* This file is part of the Phalcon Framework. | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phalcon\Test\Integration\DM\Pdo\Connection; | ||
|
||
use IntegrationTester; | ||
use PDO; | ||
use Phalcon\DM\Pdo\Connection; | ||
|
||
class DebugInfoCest | ||
{ | ||
/** | ||
* Integration Tests Phalcon\DM\Pdo\Connection :: __debugInfo() | ||
* | ||
* @since 2020-01-25 | ||
*/ | ||
public function dMPdoConnectionDebugInfo(IntegrationTester $I) | ||
{ | ||
$I->wantToTest('DM\Pdo\Connection - __debugInfo()'); | ||
|
||
/** @var Connection $connection */ | ||
$connection = $I->getConnection(); | ||
|
||
$expected = [ | ||
'arguments' => [ | ||
$I->getDatabaseDsn(), | ||
'****', | ||
'****', | ||
[ | ||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, | ||
], | ||
[], | ||
], | ||
]; | ||
$I->assertEquals($expected, $connection->__debugInfo()); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
tests/integration/DM/Pdo/Connection/Decorated/ConstructCest.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,43 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Phalcon Framework. | ||
* | ||
* For the full copyright and license information, please view the LICENSE.md | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phalcon\Test\Integration\DM\Pdo\Connection\Decorated; | ||
|
||
use IntegrationTester; | ||
use PDO; | ||
use Phalcon\DM\Pdo\Connection\Decorated; | ||
use Phalcon\DM\Pdo\Profiler\Profiler; | ||
|
||
class ConstructCest | ||
{ | ||
/** | ||
* Integration Tests Phalcon\DM\Pdo\Connection\Decorated :: __construct() | ||
* | ||
* @since 2020-01-25 | ||
*/ | ||
public function dMPdoConnectionDecoratedConstruct(IntegrationTester $I) | ||
{ | ||
$I->wantToTest('DM\Pdo\Connection\Decorated - __construct()'); | ||
|
||
$connection = new PDO( | ||
$I->getDatabaseDsn(), | ||
$I->getDatabaseUsername(), | ||
$I->getDatabasePassword() | ||
); | ||
|
||
$decorated = new Decorated($connection); | ||
$decorated->connect(); | ||
|
||
$I->assertTrue($decorated->isConnected()); | ||
$I->assertInstanceOf(Profiler::class, $decorated->getProfiler()); | ||
$I->assertSame($connection, $decorated->getAdapter()); | ||
} | ||
} |
Oops, something went wrong.