0

I am fresher working in PHP and I want to unit test a method which does not returns anything but just sets value to an object. My code is like this

class User
{
    private $name;

    private $email;

    public function getName(): ?string
    {
        return $this->name;
    }

   public function setName(?string $name): void
   {
       $this->name = $name;
   }

   public function getEmail(): ?string
   {
      return $this->email;
   }

   public function setEmail(?string $email): void
   {
       $this->email = $email;
   }
}

The class I want to test is like this

class UserMapper
{
    public function map(User $user): void
    {
          $user->setName("abc");
          $user->setemail("abc@example.com")
    }
}

How can I test this map function with PHPUnit mock?

gogaz
  • 2,323
  • 2
  • 23
  • 31
  • test $user after the method call if has the values – Edwin Aug 08 '18 at 14:29
  • 1
    Why don't you get the values afterwards and perform a normal comparison vi `==` or `===`? (Whichever is appropiate). – Tobias F. Aug 08 '18 at 14:29
  • 1
    The duplicate raises some interesting points about this sort of testing, but the last answer also shows you how you can do it. – Nigel Ren Aug 08 '18 at 14:30

0 Answers0