PHP Classes
elePHPant
Icontem

File: tests/unit/Storage/BaseStorageTest.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Daniel Martinez  >  Forker PHP  >  tests/unit/Storage/BaseStorageTest.php  >  Download  
File: tests/unit/Storage/BaseStorageTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: Forker PHP
Split tasks into multiple forked processes
Author: By
Last change:
Date: 1 year ago
Size: 2,012 bytes
 

Contents

Class file image Download
<?php

use Forker\Storage\ArrayStorage;

Abstract class
BaseStorageTest extends PHPUnit_Framework_TestCase
{
    protected
$storageSystem;
    protected
$tasks = array(1, 2, 3, 4, 5, 6);

    public function
setUp()
    {
       
$this->storageSystem = $this->getSystemStorage();
    }

    public function
tearDown()
    {
       
$this->storageSystem->cleanUp();
    }

   
// to override
   
abstract protected function getSystemStorage();

    public function
testWeCanGetASimpleStoredValue()
    {
       
$expectedValue = 'value';
       
$nonExistingKey = 'uhh';

       
$this->storageSystem->store('foo', $expectedValue);
       
$this->assertEquals($expectedValue, $this->storageSystem->get('foo'));

       
$this->assertFalse($this->storageSystem->get($nonExistingKey));
    }

   
/**
     * Let's return a boolean value
     * To make it easier
     */
   
public function testWeCanSToreValues()
    {
       
$this->assertTrue(
           
$this->storageSystem->store('foo', 'some-value')
        );
    }

   
/**
     * It should be a way to retrieve all our stored tasks
     */
   
public function testIcanGetAllMyStoredTasks()
    {
       
$this->storeAllTasks();
       
$reducedTasks = $this->storageSystem->getStoredTasks();
       
$expected = $this->tasks;
       
       
$this->assertNotEmpty($reducedTasks);
       
$this->assertTrue(is_array($reducedTasks));
       
$this->assertEquals($expected, $reducedTasks);
    }

    public function
testWeCanCleanUpAllPreviousTasks()
    {
       
$this->storeAllTasks();
       
$reducedTasks = $this->storageSystem->getStoredTasks();
       
       
$this->assertNotEmpty($reducedTasks);
       
$this->assertTrue($this->storageSystem->cleanUp());
       
$this->assertEmpty($this->storageSystem->getStoredTasks());
    }

    protected function
storeAllTasks()
    {
        foreach (
$this->tasks as $keyTask => $task) {
           
$this->storageSystem->store($keyTask, $task);
        }
    }
}