Login   Register  
PHP Classes
elePHPant
Icontem

File: tests/SQLToolsTest.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  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:
Date: 8 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::HOSTself::USERself::PWD));
        
SQLTools::execute(new DropDataBase(self::DB));
        
SQLTools::execute(new CreateDataBase(self::DB));
    }

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

        );
    }

    public function 
testCreateTable()
    {
        
SQLTools::configure(new SQLConfig(self::HOSTself::USERself::PWDself::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::HOSTself::USERself::PWDself::DB));
        
SQLTools::execute(new AddForeignKey("news""categoryId""category""id"));
    }

}