PHP Classes

File: tests/Phabstractic/Patterns/Registry.php

Recommend this page to a friend!
  Classes of Asher Wolfstein   PHP Registry with Singleton Trait   tests/Phabstractic/Patterns/Registry.php   Download  
File: tests/Phabstractic/Patterns/Registry.php
Role: Unit test script
Content type: text/plain
Description: unit testing
Class: PHP Registry with Singleton Trait
Set and get registry values using singleton trait
Author: By
Last change:
Date: 8 years ago
Size: 2,664 bytes
 

Contents

Class file image Download
<?php

require_once('src/Phabstractic/Patterns/Registry.php');

use
PHPUnit\Framework\TestCase;
use
Phabstractic\Patterns;

class
RegistryTest extends TestCase
{
    public function
testInstantiation() {
       
$registry = Patterns\Registry::instantiate(array('testkey'=>'testdata'));
       
       
$this->assertInstanceOf(Patterns\Registry::class, $registry);
       
        return
$registry;
    }
   
   
/**
     * @depends testInstantiation
     * @expectedException \Phabstractic\Patterns\Exception\RuntimeException
     *
     */
   
public function testDoubleInstantiation() {
       
$registry = Patterns\Registry::instantiate(array('errorkey'=>'errorvalue'));
    }
   
   
/**
     * @depends testInstantiation
     *
     */
   
public function testRetrieval($registry) {
       
$test = $registry->get('testkey');
       
       
$this->assertEquals($test, 'testdata');
       
       
$testref =& $registry->getReference('testkey');
       
       
$this->assertEquals($test, 'testdata');
       
       
$testref = 'referenceddata';
       
       
$this->assertEquals($registry->get('testkey'), 'referenceddata');
       
       
$testref = 'testdata';
       
    }
   
   
/**
     * @depends testInstantiation
     *
     */
   
public function testSetting($registry) {
       
$registry->set('newkey', 'newvalue');
       
       
$this->assertEquals($registry->get('newkey'), 'newvalue');
       
       
$testref = 'referenceddata';
       
       
$registry->setReference('testref', $testref);
       
       
$testref = 'toucheddata';
       
       
$this->assertEquals($registry->get('testref'), 'toucheddata');
       
    }
   
   
/**
     * @depends testInstantiation
     *
     */
   
public function testArrayFunctionality($registry) {
       
$this->assertEquals($registry['testkey'], 'testdata');
       
       
$registry['testkey'] = 'modifieddata';
       
       
$this->assertEquals($registry['testkey'], 'modifieddata');
    }
   
   
/**
     * @depends testInstantiation
     * @expectedException \Phabstractic\Patterns\Exception\RangeException
     *
     */
   
public function testArrayRange($registry) {
       
$val = $registry['unknownkey'];
    }
   
   
/**
     * @expectedException Error
     *
     */
   
public function testClone()
    {
       
$registry = Patterns\Registry::instantiate();
       
$registryclone = clone $registry;
    }
   
   
    public static function
tearDownAfterClass()
    {
       
$registry = Patterns\Registry::instantiate();
        unset(
$registry['testkey']);
        unset(
$registry['newkey']);
        unset(
$registry['testref']);
    }
}