File tree Expand file tree Collapse file tree 2 files changed +36
-3
lines changed
Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -33,10 +33,12 @@ class Mutator implements HydratorInterface
3333 public function hydrate ($ object , array $ data ) : void
3434 {
3535 foreach ($ data as $ property => $ value ) {
36- $ mutator = $ this ->determineMutator ($ property );
36+ if ($ value !== null && $ value !== '' ) {
37+ $ mutator = $ this ->determineMutator ($ property );
3738
38- if (method_exists ($ object , $ mutator )) {
39- $ object ->$ mutator ($ value ); // @phpstan-ignore-line, PhpStan does not like variadic calls
39+ if (method_exists ($ object , $ mutator )) {
40+ $ object ->$ mutator ($ value ); // @phpstan-ignore-line, PhpStan does not like variadic calls
41+ }
4042 }
4143 }
4244 }
Original file line number Diff line number Diff line change @@ -61,10 +61,41 @@ public function testHydrateCallsMutatorsOnObject()
6161 $ hydrator = new \PHPExif \Hydrator \Mutator ;
6262 $ hydrator ->hydrate ($ mock , $ input );
6363 }
64+
65+ /**
66+ * @group hydrator
67+ * @covers \PHPExif\Hydrator\Mutator::hydrate
68+ */
69+ public function testHydrateCallsEmptyValues ()
70+ {
71+ // input data
72+ $ input = array (
73+ 'foo ' => null ,
74+ 'bar ' => '' ,
75+ );
76+
77+ // create mock
78+ $ mock = $ this ->getMockBuilder ('TestClass ' )
79+ ->setMethods (array ('setFoo ' , 'setBar ' ))
80+ ->getMock ();
81+
82+ $ mock ->expects ($ this ->exactly (0 ))
83+ ->method ('setFoo ' );
84+ $ mock ->expects ($ this ->exactly (0 ))
85+ ->method ('setBar ' );
86+
87+ // do the test
88+ $ hydrator = new \PHPExif \Hydrator \Mutator ;
89+ $ hydrator ->hydrate ($ mock , $ input );
90+ }
6491}
6592
6693class TestClass
6794{
95+ public function setFoo ()
96+ {
97+ }
98+
6899 public function setBar ()
69100 {
70101 }
You can’t perform that action at this time.
0 commit comments