Skip to content

Commit

Permalink
Merge pull request #119 from louvelmathieu/master
Browse files Browse the repository at this point in the history
fix verifyNeverInvoked with array params
  • Loading branch information
sergeyklay authored Jan 31, 2017
2 parents 7a13a26 + ffb563a commit b7f5c50
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/AspectMock/Proxy/Verifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function verifyNeverInvoked($name, $params = null)
if (empty($calls)) {
return;
}
$params = ArgumentsFormatter::toString($params);

foreach ($calls as $args) {
if ($this->onlyExpectedArguments($params, $args) === $params) {
throw new fail(sprintf($this->neverInvoked, $this->className));
Expand Down
18 changes: 18 additions & 0 deletions tests/_data/demo/UserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ public function getName()
return $this->name;
}

/**
* @param mixed $name
*/
public function setNameAndInfo($name, $info)
{
$this->name = $name;
$this->info = $info;
return $this;
}

/**
* @return mixed
*/
public function getNameAndInfo()
{
return array($this->name, $this->info);
}

/**
* @param array $info
*/
Expand Down
39 changes: 39 additions & 0 deletions tests/unit/VerifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,43 @@ public function testVerifyMagicMethods()
$user->verifyInvoked('renameUser');
});
}

public function testverifyWithMutliplesParams()
{
$this->specify('works for instance proxy', function () {
// Set up user object.
$user = new UserModel(['name' => "John Smith"]);
double::registerObject($user);
$user = new InstanceProxy($user);

// Rename the user
$user->setName("Bob Jones");

// Assert rename was counted.
$user->verifyInvoked('setName', "Bob Jones");
// if verifyInvoked is ok, verifyNeverInvoked have to fail
try {
$user->verifyNeverInvoked('setName', "Bob Jones");
// If i dont fail, my test fail
throw new fail('verifyNeverInvoked');
} catch (\Exception $e) {}

$user->verifyNeverInvoked('setName', ["Boby Jones"]);

// call function with multiple params
$user->setNameAndInfo("Bob Jones", "Infos");

// verify
$user->verifyInvoked('setNameAndInfo', ["Bob Jones", "Infos"]);

// if verifyInvoked is ok, verifyNeverInvoked have to fail
try {
$user->verifyNeverInvoked('setNameAndInfo', ["Bob Jones", "Infos"]);
// If i dont fail, my test fail
throw new fail('verifyNeverInvoked');
} catch (\Exception $e) {

}
});
}
}

0 comments on commit b7f5c50

Please sign in to comment.