Skip to content

Commit 0488389

Browse files
committed
[PropertyAccess] Refactored PropertyAccessorTest
1 parent 3cd1c9c commit 0488389

File tree

8 files changed

+336
-408
lines changed

8 files changed

+336
-408
lines changed

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function setValue(&$objectOrArray, $propertyPath, $value)
116116
*
117117
* @throws UnexpectedTypeException If a value within the path is neither object nor array.
118118
*/
119-
private function &readPropertiesUntil(&$objectOrArray, PropertyPathInterface $propertyPath, $lastIndex, $throwExceptionOnNonexistantIndex = false)
119+
private function &readPropertiesUntil(&$objectOrArray, PropertyPathInterface $propertyPath, $lastIndex, $throwExceptionOnInvalidIndex = false)
120120
{
121121
$propertyValues = array();
122122

@@ -131,9 +131,10 @@ private function &readPropertiesUntil(&$objectOrArray, PropertyPathInterface $pr
131131

132132
// Create missing nested arrays on demand
133133
if ($isIndex && $isArrayAccess && !isset($objectOrArray[$property])) {
134-
if ($throwExceptionOnNonexistantIndex) {
134+
if ($throwExceptionOnInvalidIndex) {
135135
throw new NoSuchIndexException(sprintf('Cannot read property "%s". Available properties are "%s"', $property, print_r(array_keys($objectOrArray), true)));
136136
}
137+
137138
$objectOrArray[$property] = $i + 1 < $propertyPath->getLength() ? array() : null;
138139
}
139140

@@ -412,8 +413,8 @@ private function findAdderAndRemover(\ReflectionClass $reflClass, array $singula
412413
$addMethod = 'add'.$singular;
413414
$removeMethod = 'remove'.$singular;
414415

415-
$addMethodFound = $this->isAccessible($reflClass, $addMethod, 1);
416-
$removeMethodFound = $this->isAccessible($reflClass, $removeMethod, 1);
416+
$addMethodFound = $this->isMethodAccessible($reflClass, $addMethod, 1);
417+
$removeMethodFound = $this->isMethodAccessible($reflClass, $removeMethod, 1);
417418

418419
if ($addMethodFound && $removeMethodFound) {
419420
return array($addMethod, $removeMethod);
@@ -442,7 +443,7 @@ private function findAdderAndRemover(\ReflectionClass $reflClass, array $singula
442443
* @return Boolean Whether the method is public and has $parameters
443444
* required parameters
444445
*/
445-
private function isAccessible(\ReflectionClass $class, $methodName, $parameters)
446+
private function isMethodAccessible(\ReflectionClass $class, $methodName, $parameters)
446447
{
447448
if ($class->hasMethod($methodName)) {
448449
$method = $class->getMethod($methodName);

src/Symfony/Component/PropertyAccess/Tests/Fixtures/Author.php

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/Symfony/Component/PropertyAccess/Tests/Fixtures/Magician.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/Symfony/Component/PropertyAccess/Tests/Fixtures/MagicianCall.php

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\PropertyAccess\Tests\Fixtures;
13+
14+
class TestClass
15+
{
16+
public $publicProperty;
17+
protected $protectedProperty;
18+
private $privateProperty;
19+
20+
private $publicAccessor;
21+
private $publicIsAccessor;
22+
private $publicHasAccessor;
23+
24+
public function __construct($value)
25+
{
26+
$this->publicProperty = $value;
27+
$this->publicAccessor = $value;
28+
$this->publicIsAccessor = $value;
29+
$this->publicHasAccessor = $value;
30+
}
31+
32+
public function setPublicAccessor($value)
33+
{
34+
$this->publicAccessor = $value;
35+
}
36+
37+
public function getPublicAccessor()
38+
{
39+
return $this->publicAccessor;
40+
}
41+
42+
public function setPublicIsAccessor($value)
43+
{
44+
$this->publicIsAccessor = $value;
45+
}
46+
47+
public function isPublicIsAccessor()
48+
{
49+
return $this->publicIsAccessor;
50+
}
51+
52+
public function setPublicHasAccessor($value)
53+
{
54+
$this->publicHasAccessor = $value;
55+
}
56+
57+
public function hasPublicHasAccessor()
58+
{
59+
return $this->publicHasAccessor;
60+
}
61+
62+
protected function setProtectedAccessor($value)
63+
{
64+
}
65+
66+
protected function getProtectedAccessor()
67+
{
68+
return 'foobar';
69+
}
70+
71+
protected function setProtectedIsAccessor($value)
72+
{
73+
}
74+
75+
protected function isProtectedIsAccessor()
76+
{
77+
return 'foobar';
78+
}
79+
80+
protected function setProtectedHasAccessor($value)
81+
{
82+
}
83+
84+
protected function hasProtectedHasAccessor()
85+
{
86+
return 'foobar';
87+
}
88+
89+
private function setPrivateAccessor($value)
90+
{
91+
}
92+
93+
private function getPrivateAccessor()
94+
{
95+
return 'foobar';
96+
}
97+
98+
private function setPrivateIsAccessor($value)
99+
{
100+
}
101+
102+
private function isPrivateIsAccessor()
103+
{
104+
return 'foobar';
105+
}
106+
107+
private function setPrivateHasAccessor($value)
108+
{
109+
}
110+
111+
private function hasPrivateHasAccessor()
112+
{
113+
return 'foobar';
114+
}
115+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\PropertyAccess\Tests\Fixtures;
13+
14+
class TestClassMagicCall
15+
{
16+
private $magicCallProperty;
17+
18+
public function __construct($value)
19+
{
20+
$this->magicCallProperty = $value;
21+
}
22+
23+
public function __call($method, array $args)
24+
{
25+
if ('getMagicCallProperty' === $method) {
26+
return $this->magicCallProperty;
27+
}
28+
29+
if ('getConstantMagicCallProperty' === $method) {
30+
return 'constant value';
31+
}
32+
33+
if ('setMagicCallProperty' === $method) {
34+
$this->magicCallProperty = reset($args);
35+
}
36+
37+
return null;
38+
}
39+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\PropertyAccess\Tests\Fixtures;
13+
14+
class TestClassMagicGet
15+
{
16+
private $magicProperty;
17+
18+
public function __construct($value)
19+
{
20+
$this->magicProperty = $value;
21+
}
22+
23+
public function __set($property, $value)
24+
{
25+
if ('magicProperty' === $property) {
26+
$this->magicProperty = $value;
27+
}
28+
}
29+
30+
public function __get($property)
31+
{
32+
if ('magicProperty' === $property) {
33+
return $this->magicProperty;
34+
}
35+
36+
if ('constantMagicProperty' === $property) {
37+
return 'constant value';
38+
}
39+
40+
return null;
41+
}
42+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy