SMMP/phpunit/tests/Database_construct.php

63 lines
1.8 KiB
PHP
Raw Normal View History

<?php namespace phpunit;
class Database_construct extends \PHPUnit_Framework_TestCase{
/* [1] Verification du chargement de la config
=========================================================*/
public function testGetInstanceWithNoSERVER(){
2016-10-18 14:03:03 +00:00
$instance = \database\core\Database::getInstance();
$this->assertEquals( 'localhost', $instance->getConfig()['host'] );
}
public function testGetInstanceWithSERVERLocal(){
// Pour regenerer une instance, on definit une erreur
2016-10-18 17:09:47 +00:00
\database\core\Database::$error = \error\core\Error::PDOConnection;
2016-10-18 14:03:03 +00:00
$instance = \database\core\Database::getInstance();
$this->assertEquals( 'localhost', $instance->getConfig()['host'] );
}
/* [2] Verification du singleton (getInstance)
=========================================================*/
public function testInstancePersistence(){
2016-10-18 17:09:47 +00:00
\database\core\Database::$error = \error\core\Error::PDOConnection;
2016-10-18 14:03:03 +00:00
$instance_construct = \database\core\Database::getInstance();
$instance_nextuse = \database\core\Database::getInstance();
$this->assertSame( $instance_construct, $instance_nextuse );
}
public function testInstancePersistenceRefutation(){
2016-10-18 17:09:47 +00:00
\database\core\Database::$error = \error\core\Error::PDOConnection;
2016-10-18 14:03:03 +00:00
$instance_construct = \database\core\Database::getInstance();
2016-10-18 17:09:47 +00:00
\database\core\Database::$error = \error\core\Error::PDOConnection;
2016-10-18 14:03:03 +00:00
$instance_nextuse = \database\core\Database::getInstance();
$this->assertNotSame( $instance_construct, $instance_nextuse );
}
/* [3] Verification de l'objet PDO
=========================================================*/
public function testPDO(){
2016-10-18 14:03:03 +00:00
$pdo = \database\core\Database::getPDO();
$this->assertGreaterThan( 10, count($pdo->query('SELECT * FROM user')->fetchAll()), '[!] Moins de 10 utilisateurs trouves.');
}
}
?>