2016-02-13 16:28:28 +00:00
|
|
|
<?php namespace phpunit;
|
2016-02-12 21:07:46 +00:00
|
|
|
|
2016-02-13 16:28:28 +00:00
|
|
|
class Database_construct extends \PHPUnit_Framework_TestCase{
|
2016-02-12 21:07:46 +00:00
|
|
|
|
|
|
|
/* [1] Verification du chargement de la config
|
|
|
|
=========================================================*/
|
|
|
|
public function testGetInstanceWithNoSERVER(){
|
2016-11-05 13:57:35 +00:00
|
|
|
$instance = \database\core\DatabaseDriver::get();
|
2016-02-12 21:07:46 +00:00
|
|
|
|
|
|
|
$this->assertEquals( 'localhost', $instance->getConfig()['host'] );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetInstanceWithSERVERLocal(){
|
|
|
|
// Pour regenerer une instance, on definit une erreur
|
2016-11-05 13:57:35 +00:00
|
|
|
\database\core\DatabaseDriver::$error = \error\core\Error::PDOConnection;
|
2016-02-12 21:07:46 +00:00
|
|
|
|
|
|
|
|
2016-11-05 13:57:35 +00:00
|
|
|
$instance = \database\core\DatabaseDriver::get();
|
2016-02-12 21:07:46 +00:00
|
|
|
|
|
|
|
$this->assertEquals( 'localhost', $instance->getConfig()['host'] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] Verification du singleton (getInstance)
|
|
|
|
=========================================================*/
|
|
|
|
public function testInstancePersistence(){
|
2016-11-05 13:57:35 +00:00
|
|
|
\database\core\DatabaseDriver::$error = \error\core\Error::PDOConnection;
|
2016-02-12 21:07:46 +00:00
|
|
|
|
2016-11-05 13:57:35 +00:00
|
|
|
$instance_construct = \database\core\DatabaseDriver::get();
|
|
|
|
$instance_nextuse = \database\core\DatabaseDriver::get();
|
2016-02-12 21:07:46 +00:00
|
|
|
|
|
|
|
$this->assertSame( $instance_construct, $instance_nextuse );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInstancePersistenceRefutation(){
|
2016-11-05 13:57:35 +00:00
|
|
|
\database\core\DatabaseDriver::$error = \error\core\Error::PDOConnection;
|
|
|
|
$instance_construct = \database\core\DatabaseDriver::get();
|
2016-02-12 21:07:46 +00:00
|
|
|
|
2016-11-05 13:57:35 +00:00
|
|
|
\database\core\DatabaseDriver::$error = \error\core\Error::PDOConnection;
|
|
|
|
$instance_nextuse = \database\core\DatabaseDriver::get();
|
2016-02-12 21:07:46 +00:00
|
|
|
|
|
|
|
$this->assertNotSame( $instance_construct, $instance_nextuse );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] Verification de l'objet PDO
|
|
|
|
=========================================================*/
|
|
|
|
public function testPDO(){
|
2016-11-05 13:57:35 +00:00
|
|
|
$pdo = \database\core\DatabaseDriver::getPDO();
|
2016-02-12 21:07:46 +00:00
|
|
|
|
|
|
|
$this->assertGreaterThan( 10, count($pdo->query('SELECT * FROM user')->fetchAll()), '[!] Moins de 10 utilisateurs trouves.');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|