Skip to content

Instantly share code, notes, and snippets.

@SelrahcD
Last active December 2, 2015 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SelrahcD/f479dd6d3edd385988fd to your computer and use it in GitHub Desktop.
Save SelrahcD/f479dd6d3edd385988fd to your computer and use it in GitHub Desktop.
<?php
class Discussion
{
private $id;
private function __construct(DiscussionId $discussionId)
{
$this->id = $discussionId;
}
public function equals(Discussion $discussion)
{
return $this->id->equals($discussion->id);
}
}
<?php
class DiscussionId
{
private $id;
public function __construct($d)
{
$this->id = $id;
}
public function equals(DiscussionId $discussionId)
{
return $this->id === $discussionId->id;
}
}

The problem is : What is the proper way to test discussion's method equals with PhpSpec.

@everzet
Copy link

everzet commented Dec 2, 2015

You ended up with 2 very good examples in my book 👍

The thing which was bothering us was that we weren't testing that the logic was delegated to DiscussionId's equals method.

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 mock DiscussionId 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.

@SelrahcD
Copy link
Author

SelrahcD commented Dec 2, 2015

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