public function testFullNamesort() { $Nest = new Nest($this->data); $data = $this->data["one"]; asort($data); $this->assertEquals($data, $Nest->sort("one", "asort")->get("one")); }
public function testTo() { $Nest = new Nest(); // Valid $Nest->data($this->data); $this->assertEquals($this->data, $Nest->data()); }
/** * @depends testCreate */ public function testSetNested() { $Nest = new Nest([]); // Setting empty array $key = ["one", "two"]; $this->assertEquals([], $Nest->set($key)->get($key)); // Valid $this->assertEquals("three", $Nest->set($key, "three")->get($key)); }
public function testSerialize() { $Nest = new Nest(); // Valid $Nest->data($this->data); // First level $tmp = unserialize(serialize($Nest))->data(); // Nested $this->assertEquals($this->data, $tmp); }
/** * @depends testCreate */ public function testSetNested($data) { // Valid $this->assertEquals("four", Nest::_set($data, ["one", "two"], "four")->one["two"]); // Valid, with default $this->assertEquals("newtwo", Nest::_set($data, ["one", "two2"], "newtwo")->one["two2"]); }
public function testIsset() { $Nest = new Nest(); // Valid $Nest->data($this->data); // First level $this->assertEquals(true, isset($Nest->foo)); // Nested $this->assertEquals(true, isset($Nest->one__two)); // Invalid, first level $this->assertEquals(false, isset($Nest->BAD)); // Invalid, nested $this->assertEquals(false, isset($Nest->one__BAD)); // Invalid, nested $this->assertEquals(false, isset($Nest->BAD__TWO)); }
/** * __CONSTRUCT * * @param string $file Path to the json save file * @param bool $autosave Whether to auto-save on set or not */ public function __construct($file, $autosave = false, $magicSeparator = "__") { $this->file = $file; $this->autosave = $autosave; parent::__construct([], $magicSeparator); $this->loadJSON(@file_get_contents($this->file)); register_shutdown_function([$this, "save"]); }
public function testUnset() { $Nest = new Nest(); $Nest->data($this->data); // First level unset($Nest->foo); $this->assertEquals(false, $Nest->exists("foo")); // Nested unset($Nest->one__two); $this->assertEquals(false, $Nest->exists(["one", "two"])); // Make sure it only deleted the final level $this->assertEquals(true, $Nest->exists("one")); $Nest = new Nest(); $Nest->data($this->data); // Invalid, nested unset($Nest->BAD__two); $this->assertEquals(false, $Nest->exists(["BAD", "two"])); // Invalid, nested unset($Nest->one__BAD); $this->assertEquals(false, $Nest->exists(["one", "BAD"])); // Make sure it only deleted the final level $this->assertEquals(true, $Nest->exists("one")); // Invalid, first level unset($Nest->BAD); $this->assertEquals(false, $Nest->exists("BAD")); }