PHP Classes

File: tests/SQLToolsTest.php

Recommend this page to a friend!
  Classes of Rafael Lúcio   SQLTools   tests/SQLToolsTest.php   Download  
File: tests/SQLToolsTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: SQLTools
Create and alter databases, tables and indexes
Author: By
Last change: Update of tests/SQLToolsTest.php
Date: 9 months ago
Size: 1,519 bytes
 

Contents

Class file image Download
<?php
use SQLTools\Command\AddForeignKey;
use
SQLTools\Command\CreateDataBase;
use
SQLTools\Command\CreateTable;
use
SQLTools\Command\DropDataBase;
use
SQLTools\Entity\Field;
use
SQLTools\SQLConfig;
use
SQLTools\SQLTools;

require_once
__DIR__ . '/../vendor/autoload.php';

class
SQLToolsTest extends PHPUnit_Framework_TestCase {

    const
HOST = "localhost";
    const
USER = "root";
    const
PWD = "";
    const
DB = "sqltools_test";

    public function
testCreateDataBase()
    {
       
SQLTools::configure(new SQLConfig(self::HOST, self::USER, self::PWD));
       
SQLTools::execute(new DropDataBase(self::DB));
       
SQLTools::execute(new CreateDataBase(self::DB));
    }

    private function
generateFields()
    {
        return array(
            new
Field("id", "int", null, false, null, true, false, "AUTO_INCREMENT"),
            new
Field("name", "varchar", 100)

        );
    }

    public function
testCreateTable()
    {
       
SQLTools::configure(new SQLConfig(self::HOST, self::USER, self::PWD, self::DB));
       
SQLTools::execute(new CreateTable("category", $this->generateFields()));

       
$fields = $this->generateFields();
       
$fields[] = new Field("categoryId", "int");
       
SQLTools::execute(new CreateTable("news", $fields));
    }

    public function
testCreateForeignIndex()
    {
       
SQLTools::configure(new SQLConfig(self::HOST, self::USER, self::PWD, self::DB));
       
SQLTools::execute(new AddForeignKey("news", "categoryId", "category", "id"));
    }

}