Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes from 1.0.1 - https://github.com/awesomite/var-dumper/blob/v1.0.…
- Loading branch information
1 parent
7c12072
commit 22c0def
Showing
5 changed files
with
219 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the awesomite/var-dumper package. | ||
* | ||
* (c) Bartłomiej Krukowski <bartlomiej@krukowski.me> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Awesomite\VarDumper\MagicMethods; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
class GetterObject extends RemovedProperty | ||
{ | ||
private $c = 'c'; | ||
|
||
public function __get($name) | ||
{ | ||
return $this->$name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the awesomite/var-dumper package. | ||
* | ||
* (c) Bartłomiej Krukowski <bartlomiej@krukowski.me> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Awesomite\VarDumper\MagicMethods; | ||
|
||
use Awesomite\VarDumper\BaseTestCase; | ||
use Awesomite\VarDumper\LightVarDumper; | ||
use Awesomite\VarDumper\Properties\Properties; | ||
use Awesomite\VarDumper\Properties\PropertyInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
class MagicMethodsTest extends BaseTestCase | ||
{ | ||
public function testDump() | ||
{ | ||
$dumper = new LightVarDumper(); | ||
$object = new RemovedProperty(); | ||
|
||
$expected | ||
= <<<'EXPECTED' | ||
(2) { | ||
private $a => “a” | ||
private $b => “b” | ||
} | ||
EXPECTED; | ||
$this->assertContains($expected, $dumper->dumpAsString($object)); | ||
|
||
$parts = array( | ||
'private $b =>', | ||
); | ||
if (!\defined('HHVM_VERSION') && \version_compare(PHP_VERSION, '7.0') >= 0) { | ||
$parts[] = '(1) {'; | ||
} else { | ||
$parts[] = '(2) {'; | ||
$parts[] = 'private $a => NULL'; | ||
} | ||
$object->without('a'); | ||
foreach ($parts as $part) { | ||
$this->assertContains($part, $dumper->dumpAsString($object)); | ||
} | ||
|
||
$object->c = 'c'; | ||
$parts = array( | ||
'private $b =>', | ||
'$c =>', | ||
); | ||
if (!\defined('HHVM_VERSION') && \version_compare(PHP_VERSION, '7.0') >= 0) { | ||
$parts[] = '(2) {'; | ||
} else { | ||
$parts[] = '(3) {'; | ||
$parts[] = 'private $a => NULL'; | ||
} | ||
foreach ($parts as $part) { | ||
$this->assertContains($part, $dumper->dumpAsString($object)); | ||
} | ||
|
||
$getter = new GetterObject(); | ||
$this->assertContains('(0) {}', $dumper->dumpAsString($getter)); | ||
} | ||
|
||
/** | ||
* @dataProvider providerAbstractProperties | ||
* | ||
* @param $object | ||
* @param array $expectedProperties | ||
* @param array $diff | ||
*/ | ||
public function testAbstractProperties($object, array $expectedProperties, $diff) | ||
{ | ||
$reader = new Properties($object); | ||
|
||
if (!\defined('HHVM_VERSION') && \version_compare(PHP_VERSION, '7.0') >= 0) { | ||
$this->assertSame(\count($expectedProperties), \count($reader->getProperties())); | ||
} else { | ||
$this->assertSame(\count($expectedProperties) + \count($diff), \count($reader->getProperties())); | ||
} | ||
|
||
foreach ($expectedProperties as $expectedProperty) { | ||
$contains = false; | ||
foreach ($reader->getProperties() as $property) { | ||
/** @var PropertyInterface $property */ | ||
if ($contains = $property->getName() === $expectedProperty) { | ||
$contains = true; | ||
break; | ||
} | ||
} | ||
$this->assertTrue($contains); | ||
} | ||
} | ||
|
||
public function providerAbstractProperties() | ||
{ | ||
return array( | ||
array(new RemovedProperty(), array('a', 'b'), array()), | ||
array(new GetterObject(), array(), array()), | ||
array(RemovedProperty::createWithout(array('a')), array('b'), array('a')), | ||
array(RemovedProperty::createWithout(array('a'))->with('c'), array('b', 'c'), array('a')), | ||
array(RemovedProperty::createWithout(array('a', 'b')), array(), array('a', 'b')), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the awesomite/var-dumper package. | ||
* | ||
* (c) Bartłomiej Krukowski <bartlomiej@krukowski.me> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Awesomite\VarDumper\MagicMethods; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
class RemovedProperty | ||
{ | ||
private $a = 'a'; | ||
|
||
private $b = 'b'; | ||
|
||
public function without($name) | ||
{ | ||
unset($this->$name); | ||
|
||
return $this; | ||
} | ||
|
||
public function with($name, $value = null) | ||
{ | ||
$this->$name = $value; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param string[] $props | ||
* | ||
* @return static | ||
*/ | ||
public static function createWithout(array $props) | ||
{ | ||
$result = new static(); | ||
foreach ($props as $prop) { | ||
$result->without($prop); | ||
} | ||
|
||
return $result; | ||
} | ||
} |