63 lines
1.9 KiB
PHP
63 lines
1.9 KiB
PHP
<?php namespace phpunit;
|
|
|
|
class Database_construct extends \PHPUnit_Framework_TestCase{
|
|
|
|
/* [1] Verification du chargement de la config
|
|
=========================================================*/
|
|
public function testGetInstanceWithNoSERVER(){
|
|
$instance = \database\core\DatabaseDriver::getInstance();
|
|
|
|
$this->assertEquals( 'localhost', $instance->getConfig()['host'] );
|
|
}
|
|
|
|
public function testGetInstanceWithSERVERLocal(){
|
|
// Pour regenerer une instance, on definit une erreur
|
|
\database\core\DatabaseDriver::$error = \manager\ManagerError::PDOConnection;
|
|
|
|
|
|
$instance = \database\core\DatabaseDriver::getInstance();
|
|
|
|
$this->assertEquals( 'localhost', $instance->getConfig()['host'] );
|
|
}
|
|
|
|
|
|
|
|
/* [2] Verification du singleton (getInstance)
|
|
=========================================================*/
|
|
public function testInstancePersistence(){
|
|
\database\core\DatabaseDriver::$error = \manager\ManagerError::PDOConnection;
|
|
|
|
$instance_construct = \database\core\DatabaseDriver::getInstance();
|
|
$instance_nextuse = \database\core\DatabaseDriver::getInstance();
|
|
|
|
$this->assertSame( $instance_construct, $instance_nextuse );
|
|
}
|
|
|
|
public function testInstancePersistenceRefutation(){
|
|
\database\core\DatabaseDriver::$error = \manager\ManagerError::PDOConnection;
|
|
$instance_construct = \database\core\DatabaseDriver::getInstance();
|
|
|
|
\database\core\DatabaseDriver::$error = \manager\ManagerError::PDOConnection;
|
|
$instance_nextuse = \database\core\DatabaseDriver::getInstance();
|
|
|
|
$this->assertNotSame( $instance_construct, $instance_nextuse );
|
|
}
|
|
|
|
|
|
|
|
/* [3] Verification de l'objet PDO
|
|
=========================================================*/
|
|
public function testPDO(){
|
|
$pdo = \database\core\DatabaseDriver::getPDO();
|
|
|
|
$this->assertGreaterThan( 0, count($pdo->query('SELECT * FROM users')->fetchAll()), '[!] Aucun utilisateur trouve.');
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
?>
|