Skip to content

Commit b7f5c50

Browse files
authored
Merge pull request #119 from louvelmathieu/master
fix verifyNeverInvoked with array params
2 parents 7a13a26 + ffb563a commit b7f5c50

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

src/AspectMock/Proxy/Verifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function verifyNeverInvoked($name, $params = null)
155155
if (empty($calls)) {
156156
return;
157157
}
158-
$params = ArgumentsFormatter::toString($params);
158+
159159
foreach ($calls as $args) {
160160
if ($this->onlyExpectedArguments($params, $args) === $params) {
161161
throw new fail(sprintf($this->neverInvoked, $this->className));

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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,43 @@ 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+
// if verifyInvoked is ok, verifyNeverInvoked have to fail
89+
try {
90+
$user->verifyNeverInvoked('setName', "Bob Jones");
91+
// If i dont fail, my test fail
92+
throw new fail('verifyNeverInvoked');
93+
} catch (\Exception $e) {}
94+
95+
$user->verifyNeverInvoked('setName', ["Boby Jones"]);
96+
97+
// call function with multiple params
98+
$user->setNameAndInfo("Bob Jones", "Infos");
99+
100+
// verify
101+
$user->verifyInvoked('setNameAndInfo', ["Bob Jones", "Infos"]);
102+
103+
// if verifyInvoked is ok, verifyNeverInvoked have to fail
104+
try {
105+
$user->verifyNeverInvoked('setNameAndInfo', ["Bob Jones", "Infos"]);
106+
// If i dont fail, my test fail
107+
throw new fail('verifyNeverInvoked');
108+
} catch (\Exception $e) {
109+
110+
}
111+
});
112+
}
74113
}

0 commit comments

Comments
 (0)