PHP Classes

File: test/BaseTest.php

Recommend this page to a friend!
  Classes of Victor Bolshov   Zephir HandlerSocket Client   test/BaseTest.php   Download  
File: test/BaseTest.php
Role: Unit test script
Content type: text/plain
Description: Test
Class: Zephir HandlerSocket Client
Access MySQL tables as NoSQL with HandlerSocket
Author: By
Last change: Different approach to logging. Use single Logger instance.
Date: 7 years ago
Size: 1,362 bytes
 

Contents

Class file image Download
<?php
namespace Zhandlersocket;
/**
 * Created by PhpStorm.
 * User: vbolshov <bolshov@tradetracker.com>
 * Date: 5-10-15
 * Time: 22:27
 */
class BaseTest extends \PHPUnit_Framework_TestCase
{
   
/**
     * @var \PDO
     */
   
static $pdo;
    protected function
createClient() {
       
$ret = new Client(ZHS_HOST, ZHS_PORT_READ, ZHS_PORT_WRITE);
       
$ret->setLogger(Logger::create(true));
        return
$ret;
    }
    protected function
createIndex(Client $client) {
        return
$client->getIndex(ZHS_DBNAME, ZHS_TABLE_MOVIE, "PRIMARY", ["id", "genre", "title", "view_count"], ["genre"]);
    }
    public function
setUp() {
       
self::pdo()->exec("DELETE FROM " . ZHS_TABLE_MOVIE);
    }
    static public function
setupTable() {
       
self::pdo()->exec("DROP TABLE IF EXISTS " . ZHS_TABLE_MOVIE);
       
self::pdo()->exec("CREATE TABLE " . ZHS_TABLE_MOVIE . "
            (
                id int not null auto_increment PRIMARY KEY,
                genre VARCHAR(20) NOT NULL,
                title varchar(100) NOT NULL,
                view_count INT NOT NULL DEFAULT 0,
                KEY(genre)
            ) ENGINE InnoDB"
);
    }
    static public function
pdo() {
        if (
self::$pdo) {
            return
self::$pdo;
        } else {
            return
self::$pdo = new \PDO(ZHS_DSN, ZHS_USER, ZHS_PASSWORD);
        }
    }
}