I had little dispute with my coworkers about unit testing simple class. I have to test simple class like that.
class Person { /** @var string */ protected $name public function __construct(string $name) { $this->name = $name; } public function __toString(): string { return (string) $this->name; } } We both agree on testing toString method. But in my opinion, first we have to test creating this object as such:
public function testObjectCreation() { $testSubject = new Person('name'); $this->assertInstanceOf(Person::class, $testSubject); } My question is: Is there any sense in testing this case?
__constructworks, or that PHP can set properties, but if there's logic of any kind, then it certainly might be worth testing. It depends. This one specifically, no.__toStringyou'll be testing the constructor anyway