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