PHP Classes

File: tests/jsonTest.php

Recommend this page to a friend!
  Classes of Rick Hambrook   Nest   tests/jsonTest.php   Download  
File: tests/jsonTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test: json
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,029 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 jsonTest extends PHPUnit_Framework_TestCase {

    public function
testCreate() {
       
$Nest = new Nest([]);
       
$this->assertInstanceOf("\Hambrook\Nest\Nest", $Nest);
        return
$Nest;
    }
   
/**
     * @depends testCreate
     */
   
public function testLoad($Nest) {
       
// Valid
       
$json = '{"foo":"bar","one":{"two":"three"}}';
       
$Nest->loadJSON($json);
       
// Valid
       
$this->assertEquals("bar", $Nest->foo);
       
// Valid, with default
       
$this->assertEquals("three", $Nest->one__two);
    }

   
/**
     * @depends testCreate
     */
   
public function testTo($Nest) {
       
$Nest->foo = "newfoo";
       
$Nest->one__two = "four";
       
$json = $Nest->toJSON(false);
       
$this->assertEquals('{"foo":"newfoo","one":{"two":"four"}}', $json);
    }

}