Exemple #1
0
 public function testVerifyInstanceMethods()
 {
     $user = new UserModel();
     double::registerObject($user);
     $user = new InstanceProxy($user);
     $user->setName('davert');
     $this->specify('setName() was invoked', function () use($user) {
         $user->verifyInvoked('setName');
         $user->verifyInvoked('setName', ['davert']);
         $user->verifyInvokedMultipleTimes('setName', 1);
         $user->verifyInvokedMultipleTimes('setName', 1, ['davert']);
         $user->verifyNeverInvoked('setName', ['bugoga']);
     });
     $this->specify('save() was not invoked', function () use($user) {
         $user->verifyNeverInvoked('save');
         $user->verifyNeverInvoked('save', ['params']);
     });
 }
 public function testVerifyInvocationClosures()
 {
     $info = array('address' => 'foo', 'email' => '*****@*****.**');
     $user = new UserModel();
     double::registerObject($user);
     $user = new InstanceProxy($user);
     $user->setInfo($info);
     $user->setInfo([]);
     $matcher = function ($params) use($info) {
         $args = $params[0][0];
         // first call, first arg
         $empty = $params[1][0];
         // second call, first arg
         verify($info)->equals($args);
         verify($empty)->isEmpty();
     };
     $this->specify('closure was called', function () use($user, $info, $matcher) {
         $user->verifyInvokedMultipleTimes('setInfo', 2, $matcher);
         $user->verifyInvoked('setInfo', $matcher);
     });
 }
 public function testVerifyMagicMethods()
 {
     $this->specify('works for class proxy', function () {
         // Set up user object.
         double::registerClass("demo\\UserModel", ['renameUser' => "Bob Jones", 'save' => null]);
         $userProxy = new ClassProxy("demo\\UserModel");
         $user = new UserModel(['name' => "John Smith"]);
         // Rename the user via magic method.
         UserService::renameStatic($user, "Bob Jones");
         // Assert rename was counted.
         $userProxy->verifyInvoked('renameUser');
     });
     $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 via magic method.
         $user->renameUser("Bob Jones");
         // Assert rename was counted.
         $user->verifyInvoked('renameUser');
     });
 }