Skip to content

Commit b13edef

Browse files
Mathieu LOUVELMathieu LOUVEL
authored andcommitted
fix verifyNeverInvoked with aray params
1 parent c3971bb commit b13edef

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

src/AspectMock/Proxy/Verifier.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ public function verifyNeverInvoked($name, $params = null)
151151

152152
if (is_array($params)) {
153153
if (empty($calls)) return;
154-
$params = ArgumentsFormatter::toString($params);
155154
foreach ($calls as $args) {
156155
if ($this->onlyExpectedArguments($params, $args) == $params) throw new fail(sprintf($this->neverInvoked, $this->className));
157156
}

tests/_data/demo/UserModel.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,24 @@ public function getName()
4343
return $this->name;
4444
}
4545

46+
/**
47+
* @param mixed $name
48+
*/
49+
public function setNameAndInfo($name, $info)
50+
{
51+
$this->name = $name;
52+
$this->info = $info;
53+
return $this;
54+
}
55+
56+
/**
57+
* @return mixed
58+
*/
59+
public function getNameAndInfo()
60+
{
61+
return array($this->name, $this->info);
62+
}
63+
4664
/**
4765
* @param array $info
4866
*/

tests/unit/VerifierTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,34 @@ public function testVerifyMagicMethods()
7171
$user->verifyInvoked('renameUser');
7272
});
7373
}
74+
75+
public function testverifyWithMutliplesParams()
76+
{
77+
$this->specify('works for instance proxy', function() {
78+
// Set up user object.
79+
$user = new UserModel(['name' => "John Smith"]);
80+
double::registerObject($user);
81+
$user = new InstanceProxy($user);
82+
83+
// Rename the user
84+
$user->setName("Bob Jones");
85+
86+
// Assert rename was counted.
87+
$user->verifyInvoked('setName', "Bob Jones");
88+
$user->verifyNeverInvoked('setName', ["Boby Jones"]);
89+
90+
// call function with multiple params
91+
$user->setNameAndInfo("Bob Jones", "Infos");
92+
93+
// verify
94+
$user->verifyInvoked('setNameAndInfo',["Bob Jones", "Infos"]);
95+
96+
// if verifyInvoked is ok, verifyNeverInvoked have to fail
97+
try {
98+
$user->verifyNeverInvoked('setNameAndInfo', ["Bob Jones", "Infos"]);
99+
// If i dont fail, my test fail
100+
throw new fail('verifyNeverInvoked');
101+
} catch (\Exception $e) {}
102+
});
103+
}
74104
}

0 commit comments

Comments
 (0)