PHP Classes

File: tests/arrayHelpersTest.php

Recommend this page to a friend!
  Classes of Rick Hambrook   Nest   tests/arrayHelpersTest.php   Download  
File: tests/arrayHelpersTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test: array helpers
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: 8 years ago
Size: 1,790 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 arrayHelpersTest extends PHPUnit_Framework_TestCase {

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

    public function
testCreateAppend() {
       
$Nest = new Nest($this->data);
        return
$Nest;
    }

    public function
testCreateCount() {
       
$Nest = new Nest($this->data);
        return
$Nest;
    }

    public function
testCreateMerge() {
       
$Nest = new Nest($this->data);
        return
$Nest;
    }

   
/**
     * @depends testCreateAppend
     */
   
public function testAppend($Nest) {
       
$Nest->append("one", "four");
       
$Nest->append("one", "five");
       
// Default
       
$this->assertEquals("four", $Nest->one__0);
       
$this->assertEquals("five", $Nest->one__1);
    }

   
/**
     * @depends testCreateCount
     */
   
public function testCount($Nest) {
       
// No default
       
$this->assertEquals(2, $Nest->count());
       
// Default
       
$this->assertEquals(2, $Nest->count(false, 5));
       
// Nested
       
$this->assertEquals(1, $Nest->count("one"));
       
// Updated nested count
       
$Nest->one__four = "five";
       
$this->assertEquals(2, $Nest->count("one"));
    }

   
/**
     * @depends testCreateMerge
     */
   
public function testMerge($Nest) {
       
$Nest->merge("one", [
           
"four" => "five"
       
]);

       
// Existing value
       
$this->assertEquals("three", $Nest->one__two);
       
// New value
       
$this->assertEquals("five", $Nest->one__four);
       
// Count
       
$this->assertEquals(2, $Nest->count("one"));
       
// Old top level value
       
$this->assertEquals("bar", $Nest->foo);
    }

}