Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
"jbzoo/utils" : "^1.4.2"
},
"require-dev" : {
"jbzoo/phpunit" : "^1.2",
"symfony/yaml" : "^2.8|^3.0"
"jbzoo/phpunit" : "^1.10",
"jbzoo/profiler" : "^1.0",
"symfony/yaml" : "^2.8|^3.0"
},
"suggest" : {
"symfony/yaml" : "^2.8|^3.0"
Expand Down
45 changes: 2 additions & 43 deletions src/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class Data extends \ArrayObject
*/
public function __construct($data = array())
{
$this->setFlags(\ArrayObject::ARRAY_AS_PROPS);

if ($data && is_string($data) && file_exists($data)) {
$data = $this->_readFile($data);
}
Expand Down Expand Up @@ -115,49 +117,6 @@ public function remove($name)
return $this;
}

/**
* Magic method to allow for correct isset() calls
* @param string $name The key to search for
* @return boolean
*/
public function __isset($name)
{
return $this->offsetExists($name);
}

/**
* Magic method to get values as object properties
* @param string $name The key of the data to fetch
* @return mixed
*/
public function __get($name)
{
if (!$this->has($name)) {
return null;
}

return $this->offsetGet($name);
}

/**
* Magic method to set values through object properties
* @param string $name The key of the data to set
* @param mixed $value The value to set
*/
public function __set($name, $value)
{
$this->offsetSet($name, $value);
}

/**
* Magic method to unset values using unset()
* @param string $name The key of the data to set
*/
public function __unset($name)
{
$this->offsetUnset($name);
}

/**
* Magic method to convert the data to a string
* Returns a serialized version of the data contained in
Expand Down
17 changes: 9 additions & 8 deletions tests/BenchmarkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace JBZoo\PHPUnit;

use JBZoo\Data\Data;
use JBZoo\Profiler\Benchmark;

/**
* Class BenchmarkTest
Expand Down Expand Up @@ -67,7 +68,7 @@ public function testCreate()
{
$array = $this->_data;

runBench(array(
Benchmark::compare(array(
'Array' => function () use ($array) {
$var = $array; // for clean experiment
return $var;
Expand All @@ -94,7 +95,7 @@ public function testGet()
$arrobj = new \ArrayObject($this->_data);
$arrobjExt = new \ArrayObjectExt($this->_data);

runBench(array(
Benchmark::compare(array(
// Simple array
'Array::clean' => function () use ($array) {
return $array['prop'];
Expand Down Expand Up @@ -151,7 +152,7 @@ public function testGetInner()
$arrobj = new \ArrayObject($this->_data);
$arrobjExt = new \ArrayObjectExt($this->_data);

runBench(array(
Benchmark::compare(array(
// Simple array
'Array::clean' => function () use ($array) {
return $array['inner']['inner']['prop'];
Expand Down Expand Up @@ -205,7 +206,7 @@ public function testGetUndefined()
$arrobj = new \ArrayObject($this->_data);
$arrobjExt = new \ArrayObjectExt($this->_data);

runBench(array(
Benchmark::compare(array(
// Simple array
'array::@' => function () use ($array) {
return @$array['undefined'];
Expand Down Expand Up @@ -288,7 +289,7 @@ public function testForReadme()
$data = new Data($this->_data);
$arrobj = new \ArrayObject($this->_data);

runBench(array(
Benchmark::compare(array(
'Array' => function () use ($array) {
$var = $array; // for clean experiment
return $var;
Expand All @@ -304,7 +305,7 @@ public function testForReadme()
), array('name' => 'For Readme: Create', 'count' => $times));


runBench(array(
Benchmark::compare(array(
'Array' => function () use ($array) {
return array_key_exists('prop', $array) ? $array['prop'] : null;
},
Expand All @@ -317,7 +318,7 @@ public function testForReadme()
), array('name' => 'For Readme: Get by key', 'count' => $times));


runBench(array(
Benchmark::compare(array(
'Array' => function () use ($array) {
if (
array_key_exists('inner', $array) &&
Expand Down Expand Up @@ -345,7 +346,7 @@ public function testForReadme()
},
), array('name' => 'For Readme: Find nested defined var', 'count' => $times));

runBench(array(
Benchmark::compare(array(
'Array' => function () use ($array) {
if (
array_key_exists('inner', $array) &&
Expand Down
6 changes: 6 additions & 0 deletions tests/dataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,10 @@ public function testNumeric()
isSame(0, $data['0']);
isSame(1, $data[2][0]);
}

public function testPropsVisible()
{
$data = new Data($this->_test);
isTrue(count(get_object_vars($data)) > 0);
}
}
6 changes: 6 additions & 0 deletions tests/iniDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ public function testString()

is($dataValid, (string)$data);
}

public function testPropsVisible()
{
$data = new Ini($this->openFile($this->testFile));
isTrue(count(get_object_vars($data)) > 0);
}
}
6 changes: 6 additions & 0 deletions tests/jsonDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,10 @@ public function testJson()

is($dataValid, (string)$data);
}

public function testPropsVisible()
{
$data = new JSON($this->test);
isTrue(count(get_object_vars($data)) > 0);
}
}
6 changes: 6 additions & 0 deletions tests/phpArrayDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ public function testFile()

is($dataValid, (string)$data);
}

public function testPropsVisible()
{
$data = new PHPArray($this->testFile);
isTrue(count(get_object_vars($data)) > 0);
}
}
6 changes: 6 additions & 0 deletions tests/ymlDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ public function testString()

is($dataValid, (string)$data);
}

public function testPropsVisible()
{
$data = new Yml($this->openFile($this->testFile));
isTrue(count(get_object_vars($data)) > 0);
}
}