Add basic tests for PDOConnection and PDOStatement
[MAILPOET-3296]
This commit is contained in:
committed by
Veljko V
parent
0ee843723e
commit
dd3538b78d
@@ -111,7 +111,7 @@ class ContainerConfigurator implements IContainerConfigurator {
|
|||||||
// Doctrine
|
// Doctrine
|
||||||
$container->autowire(\MailPoet\Doctrine\Annotations\AnnotationReaderProvider::class);
|
$container->autowire(\MailPoet\Doctrine\Annotations\AnnotationReaderProvider::class);
|
||||||
$container->autowire(\MailPoet\Doctrine\ConfigurationFactory::class);
|
$container->autowire(\MailPoet\Doctrine\ConfigurationFactory::class);
|
||||||
$container->autowire(\MailPoet\Doctrine\ConnectionFactory::class);
|
$container->autowire(\MailPoet\Doctrine\ConnectionFactory::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\Doctrine\EntityManagerFactory::class);
|
$container->autowire(\MailPoet\Doctrine\EntityManagerFactory::class);
|
||||||
$container->autowire(\MailPoetVendor\Doctrine\ORM\Configuration::class)
|
$container->autowire(\MailPoetVendor\Doctrine\ORM\Configuration::class)
|
||||||
->setFactory([new Reference(\MailPoet\Doctrine\ConfigurationFactory::class), 'createConfiguration']);
|
->setFactory([new Reference(\MailPoet\Doctrine\ConfigurationFactory::class), 'createConfiguration']);
|
||||||
|
21
tests/integration/Doctrine/Driver/DummyUser.php
Normal file
21
tests/integration/Doctrine/Driver/DummyUser.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MailPoet\Doctrine\Driver;
|
||||||
|
|
||||||
|
class DummyUser {
|
||||||
|
private $name;
|
||||||
|
private $age;
|
||||||
|
|
||||||
|
public function __construct($name, $age) {
|
||||||
|
$this->name = $name;
|
||||||
|
$this->age = $age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName() {
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAge() {
|
||||||
|
return $this->age;
|
||||||
|
}
|
||||||
|
}
|
28
tests/integration/Doctrine/Driver/PDOConnectionTest.php
Normal file
28
tests/integration/Doctrine/Driver/PDOConnectionTest.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MailPoet\Doctrine\Driver;
|
||||||
|
|
||||||
|
use MailPoet\Doctrine\ConnectionFactory;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/DummyUser.php';
|
||||||
|
|
||||||
|
class PDOConnectionTest extends \MailPoetTest {
|
||||||
|
|
||||||
|
/** @var PDOConnection */
|
||||||
|
private $testConnection;
|
||||||
|
|
||||||
|
public function _before() {
|
||||||
|
$this->testConnection = $this->diContainer->get(ConnectionFactory::class)->createConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItCanQuery() {
|
||||||
|
$statement = $this->testConnection->query("SELECT 'lojza' as name, 30 as age;");
|
||||||
|
expect($statement)->isInstanceOf(PDOStatement::class);
|
||||||
|
|
||||||
|
$statement = $this->testConnection->query("SELECT 'lojza' as name, 30 as age;", \PDO::FETCH_COLUMN, 2);
|
||||||
|
expect($statement)->isInstanceOf(PDOStatement::class);
|
||||||
|
|
||||||
|
$statement = $this->testConnection->query("SELECT 'lojza' as name, 30 as age;", \PDO::FETCH_CLASS, DummyUser::class, ['name', 'age']);
|
||||||
|
expect($statement)->isInstanceOf(PDOStatement::class);
|
||||||
|
}
|
||||||
|
}
|
34
tests/integration/Doctrine/Driver/PDOStatementTest.php
Normal file
34
tests/integration/Doctrine/Driver/PDOStatementTest.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MailPoet\Doctrine\Driver;
|
||||||
|
|
||||||
|
use MailPoet\Doctrine\ConnectionFactory;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/DummyUser.php';
|
||||||
|
|
||||||
|
class PDOStatementTest extends \MailPoetTest {
|
||||||
|
|
||||||
|
/** @var PDOConnection */
|
||||||
|
private $testConnection;
|
||||||
|
|
||||||
|
public function _before() {
|
||||||
|
$this->testConnection = $this->diContainer->get(ConnectionFactory::class)->createConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItCanFetchAll() {
|
||||||
|
$statement = $this->testConnection->query("SELECT 'lojza' as name, 30 as age;");
|
||||||
|
$result = $statement->fetchAll();
|
||||||
|
expect($result)->count(1);
|
||||||
|
expect($result[0]['name'])->equals('lojza');
|
||||||
|
|
||||||
|
$statement = $this->testConnection->query("SELECT 'lojza' as name, 30 as age;");
|
||||||
|
$result = $statement->fetchAll(\PDO::FETCH_COLUMN);
|
||||||
|
expect($result)->count(1);
|
||||||
|
expect($result[0])->equals('lojza');
|
||||||
|
|
||||||
|
$statement = $this->testConnection->query("SELECT 'lojza' as name, 30 as age;");
|
||||||
|
$result = $statement->fetchAll(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, DummyUser::class, ['name', 'age']);
|
||||||
|
expect($result)->count(1);
|
||||||
|
expect($result[0]->getName())->equals('lojza');
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user