PHP Classes

File: tests/dataTest.php

Recommend this page to a friend!
  Classes of Rick Hambrook   Nest   tests/dataTest.php   Download  
File: tests/dataTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test: data
Class: Nest
Easily set and get values of nested arrays
Author: By
Last change: feat(meta): update namespaces and add composer file for composer/packagist support
Date: 9 years ago
Size: 1,095 bytes
 

Contents

Class file image Download
<?php

require_once(implode(DIRECTORY_SEPARATOR, [__DIR__, "..", "src", "Nest.php"]));

use \
Hambrook\Nest\Nest as Nest;

/**
 * Tests for PHPUnit
 *
 * @author Rick Hambrook <rick@rickhambrook.com>
 * @copyright 2015 Rick Hambrook
 * @license https://www.gnu.org/licenses/gpl.txt GNU General Public License v3
 */
class dataTest extends PHPUnit_Framework_TestCase {

    private
$data = [
       
"foo" => "bar",
       
"one" => [
           
"two" => "three"
       
]
    ];

    public function
testSet() {
       
$Nest = new Nest();
       
// Valid
       
$Nest->data($this->data);
       
// First level
       
$this->assertEquals("bar", $Nest->foo);
       
// Nested
       
$this->assertEquals("three", $Nest->one__two);

       
$Nest = new Nest();
       
// Valid
       
$Nest->data(["bar" => "baz"]);
       
// First level
       
$this->assertEquals("baz", $Nest->bar);
       
// Invalid, first level
       
$this->assertEquals(null, $Nest->foo);
       
// Invalid, nested
       
$this->assertEquals(null, $Nest->one__two);
    }

    public function
testTo() {
       
$Nest = new Nest();
       
// Valid
       
$Nest->data($this->data);
       
$this->assertEquals($this->data, $Nest->data());
    }

}