File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed
src/Symfony/Component/PropertyAccess/Tests Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change
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
+
15
+ class TestAdderVersusSetter
16
+ {
17
+ /** @var array */
18
+ private $ emails = array ();
19
+
20
+ /**
21
+ * @param array $emails
22
+ */
23
+ public function setEmails ($ emails )
24
+ {
25
+ throw new \RuntimeException ('Setter must NOT be called while adder exists ' );
26
+ }
27
+
28
+ /**
29
+ * @return array
30
+ */
31
+ public function getEmails ()
32
+ {
33
+ return $ this ->emails ;
34
+ }
35
+
36
+ /**
37
+ * @param string $email
38
+ */
39
+ public function addEmail ($ email )
40
+ {
41
+ $ this ->emails [] = $ email ;
42
+ }
43
+
44
+ /**
45
+ * @param string $email
46
+ */
47
+ public function removeEmail ($ email )
48
+ {
49
+ $ this ->emails = array_diff ($ this ->emails , array ($ email ));
50
+ }
51
+ }
Original file line number Diff line number Diff line change 16
16
use Symfony \Component \PropertyAccess \Exception \NoSuchIndexException ;
17
17
use Symfony \Component \PropertyAccess \PropertyAccessor ;
18
18
use Symfony \Component \PropertyAccess \Tests \Fixtures \ReturnTyped ;
19
+ use Symfony \Component \PropertyAccess \Tests \Fixtures \TestAdderVersusSetter ;
19
20
use Symfony \Component \PropertyAccess \Tests \Fixtures \TestClass ;
20
21
use Symfony \Component \PropertyAccess \Tests \Fixtures \TestClassIsWritable ;
21
22
use Symfony \Component \PropertyAccess \Tests \Fixtures \TestClassMagicCall ;
@@ -722,4 +723,14 @@ public function testWriteToPluralPropertyWhileSingularOneExists()
722
723
self ::assertEquals (array ('test@email.com ' ), $ object ->getEmails ());
723
724
self ::assertNull ($ object ->getEmail ());
724
725
}
726
+
727
+ public function testAdderHasHigherPriorityThanPluralSetter ()
728
+ {
729
+ $ object = new TestAdderVersusSetter ();
730
+
731
+ $ this ->propertyAccessor ->isWritable ($ object , 'emails ' ); //cache access info
732
+ $ this ->propertyAccessor ->setValue ($ object , 'emails ' , array ('test@email.com ' ));
733
+
734
+ self ::assertEquals (array ('test@email.com ' ), $ object ->getEmails ());
735
+ }
725
736
}
You can’t perform that action at this time.
0 commit comments