PHP Classes

File: Tests/UpdateTest.php

Recommend this page to a friend!
  Classes of Joseluis Laso   Simple PHP Memory Database   Tests/UpdateTest.php   Download  
File: Tests/UpdateTest.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: 6 years ago
Size: 1,486 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
UpdateTest extends AbstractTestCase
{
    public function
testUpdate()
    {
       
// prepare some records to write in the json file
       
$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);

       
// create the DB from the json file and start testing
       
$customerTbl = new CustomerTable($this->tmpFile);

       
$customers = $customerTbl->findAll();
       
$this->assertEquals(2, count($customers));
       
$this->assertArrayHasKey(1, $customers);
       
$this->assertArrayHasKey(2, $customers);
       
$this->assertEquals($customers[1]['name'], 'Customer 1');

       
// demostration of update
       
$customer = new Customer(1, 'No customer 1 anymore', 1);
       
$customerTbl->update($customer);

       
$customers = $customerTbl->findAll();
       
$this->assertEquals(2, count($customers));
       
$this->assertArrayHasKey(1, $customers);
       
$this->assertArrayHasKey(2, $customers);
       
$this->assertNotEquals($customers[1]['name'], 'Customer 1');
       
$this->assertEquals($customers[1]['name'], 'No customer 1 anymore');
    }
}