PHP Classes

File: Tests/DbTest.php

Recommend this page to a friend!
  Classes of Joseluis Laso   Simple PHP Memory Database   Tests/DbTest.php   Download  
File: Tests/DbTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Simple PHP Memory Database
Manipulate databases stored in JSON format files
Author: By
Last change: fixing CS & MD
Date: 7 years ago
Size: 1,363 bytes
 

Contents

Class file image Download
<?php

namespace JLaso\SimpleMemoryDb;

use
JLaso\SimpleMemoryDb\Example\CustomerTable;
use
JLaso\SimpleMemoryDb\Tests\AbstractTestCase;

class
DbTest extends AbstractTestCase
{
    protected
$folder = __DIR__.'/../src/Example/';

    public function
testEmptyDB()
    {
       
$customerTbl = new CustomerTable();

       
$this->assertTrue($customerTbl->count() === 0);
    }

    public function
testRecords()
    {
       
$customerTbl = new CustomerTable($this->folder.'customers.json');

       
$this->assertEquals($customerTbl->count(), 2);
       
$customer = $customerTbl->find(1);
       
$this->assertEquals($customer['name'], 'John Doe');
       
$customer = $customerTbl->find(2);
       
$this->assertEquals($customer['name'], 'Jane Doe');
       
$customer = $customerTbl->find(3);
       
$this->assertNull($customer);
    }

    public function
testSave()
    {
       
$customerTbl = new CustomerTable();
       
$customerTbl->saveToJsonFile($this->tmpFile);
       
$this->assertEquals(file_get_contents($this->tmpFile), '[]');

       
$customerTbl->insert(['id' => 1, 'name' => 'Test name', 'tax_type_id' => null]);
       
$customerTbl->saveToJsonFile($this->tmpFile);

       
$customerTbl = new CustomerTable($this->tmpFile);
       
$customer = $customerTbl->find(1);
       
$this->assertEquals($customer['name'], 'Test name');
    }
}