PHP Classes

File: Tests/FilterTest.php

Recommend this page to a friend!
  Classes of Joseluis Laso   Simple PHP Memory Database   Tests/FilterTest.php   Download  
File: Tests/FilterTest.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,065 bytes
 

Contents

Class file image Download
<?php

namespace JLaso\SimpleMemoryDb;

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

class
FilterTest extends AbstractTestCase
{
    public function
testFilter()
    {
       
$customerTbl = new CustomerTable();

       
$customer = new Customer(1, 'Customer 1', 1);
       
$customerTbl->insert($customer);
       
$customer = new Customer(2, 'Customer 2', 2);
       
$customerTbl->insert($customer);

       
$customerTbl->saveToJsonFile($this->tmpFile);

       
$customerTbl = new CustomerTable($this->tmpFile);

       
$customers = $customerTbl->findAll();
       
$this->assertEquals(2, count($customers));

       
$customers = $customerTbl->findAll(null, null, function ($r) {
            return
$r['tax_type_id'] == 2;
        });
       
$this->assertEquals(1, count($customers));

       
$this->assertArrayHasKey(2, $customers);
       
$this->assertEquals($customers[2]['name'], 'Customer 2');
       
$this->assertArrayNotHasKey(1, $customers);
    }
}