/** * Test du chargement des tables */ public function testLoadTable() { require_once __DIR__ . '/../Test/Table/NewsTable.php'; Config::add(__DIR__ . '/../Test/test.php', 'app'); Connections::add('dev', new Connection('sqlite::memory:')); $controller = new Controller(); $this->assertCount(0, $controller->tables); $this->assertInstanceOf(NewsTable::class, $controller->news); $this->assertCount(1, $controller->tables); }
/** * Initialisation des fichiers de configuration */ public function initConfig() { $path = realpath(__DIR__ . '/../../bin/configs/'); $rdi = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS); $rit = new RecursiveIteratorIterator($rdi); foreach ($rit as $file) { if ($file->getExtension() === 'php') { Config::add($file->getBasename('.php')); } } $configApp = Config::get('app'); if ($configApp && !empty($configApp->name)) { $this->name = $configApp->name; } }
/** * Test de la facade */ public function testFacadeConfig() { $configManager = ConfigManager::getInstance(); $this->assertCount(0, $configManager->configs); Config::add(__DIR__ . '/../Test/test.php'); $this->assertCount(1, $configManager->configs); Config::add(__DIR__ . '/../Test/test2.php'); $this->assertCount(2, $configManager->configs); Config::add(__DIR__ . '/../Test/test.php'); $this->assertCount(2, $configManager->configs); Config::add(__DIR__ . '/../Test/test2.php'); $this->assertCount(2, $configManager->configs); $this->assertTrue(Config::exist('test')); $this->assertTrue(Config::exist('test2')); $this->assertFalse(Config::exist('test3')); $this->assertEquals('Test\\Table', Config::get('test')->namespace['table']); $this->assertNull(Config::get('test3')); $this->assertNull(Config::get('test')->unknown); }
public function testRender() { Config::add(__DIR__ . '/../Test/test.php', 'app'); $string = Response::string('view'); $this->assertEquals('view', $string->view->render()); $json = Response::json(['id' => 1]); $this->assertEquals('{"id":1}', $json->view->render()); $text = Response::html('test', 'a', ['id' => 1], ['b.js']); $this->assertEquals('<h1>a</h1><p>1</p><script src="b.js"></script>', $text->view->render()); $html = Response::text('salut'); $catched = false; try { $html->view->render(); } catch (InvalidArgumentException $e) { $this->assertEquals('View [salut] not found.', $e->getMessage()); $catched = true; } $this->assertTrue($catched); }
/** * Test de récupération des données */ public function testFirstAndAll() { Config::add(__DIR__ . '/../Test/namespace.php'); $connection = new Connection('sqlite::memory:'); $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $connection->query('CREATE TABLE IF NOT EXISTS news ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, `title` VARCHAR(50) NOT NULL, `content` LONGTEXT NOT NULL, `created_at` DATETIME NOT NULL )'); $allNews = [[':title' => 'Titre 1', ':content' => 'Contenu 1', ':createdAt' => '2016-07-18 09:20:35'], [':title' => 'Titre 2', ':content' => 'Contenu 2', ':createdAt' => '2016-07-18 10:20:35'], [':title' => 'Titre 3', ':content' => 'Contenu 3', ':createdAt' => '2016-07-18 11:20:35'], [':title' => 'Titre 4', ':content' => 'Contenu 4', ':createdAt' => '2016-07-18 12:20:35']]; require_once __DIR__ . '/../Test/Table/NewsTable.php'; require_once __DIR__ . '/../Test/Entities/Database/News.php'; $newsTable = new NewsTable($connection, '', News::class); foreach ($allNews as $news) { $newsTable->add($news); } $this->assertEquals(0, $newsTable->badCount()); $this->assertEquals(count($allNews), $newsTable->count()); $first = $newsTable->getById(1); $this->assertEquals($allNews[0][':content'], $first->content); $impossible = $newsTable->getById(5); $this->assertFalse($impossible); $all = $newsTable->getAll(); $this->assertEquals(count($allNews), $newsTable->count()); foreach ($all as $index => $value) { $this->assertInstanceOf(News::class, $value); $this->assertSame($allNews[$index][':content'], $value->content); } }