The problem is : What is the proper way to test discussion's method equals with PhpSpec.
Last active
December 2, 2015 20:05
-
-
Save SelrahcD/f479dd6d3edd385988fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Discussion | |
{ | |
private $id; | |
private function __construct(DiscussionId $discussionId) | |
{ | |
$this->id = $discussionId; | |
} | |
public function equals(Discussion $discussion) | |
{ | |
return $this->id->equals($discussion->id); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DiscussionId | |
{ | |
private $id; | |
public function __construct($d) | |
{ | |
$this->id = $id; | |
} | |
public function equals(DiscussionId $discussionId) | |
{ | |
return $this->id === $discussionId->id; | |
} | |
} |
I didn't think of a value object as a value instead of a collaborator but yes it makes sens. (Didn't see the big V before object, duh...)
I'm curious, what are the two examples ?
I guess clarifying that a VO is a value as native value would be is one of them but I can't figure what the second would be.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You ended up with 2 very good examples in my book 👍
I generally am not interested in communication between two values, I am interested in communication between two roles. In your case, you don't have a role - you have a very specific value representation -
DiscussionId
.DiscussionId
is not a collaborator, it is a value (an object incorporating a singular value with a set of behaviour surrounding it). I wouldn't stub or mockDiscussionId
as I wouldn't stub or mock array or collection - there's no collaboration with ValueObject's, you just use them as you would use integers or strings in your tests.