You can also use reflection techniques for building a new Post class with custom dates. Consider Mimic, a simple functional library for object prototyping, data hydration, and data exposition:
namespace Domain;
use mimic as m;
class ComputerScientist {
private $name;
private $surname;
public function __construct($name, $surname)
{
$this->name = $name;
$this->surname = $surname;
}
public function rocks()
{
return $this->name . ' ' . $this->surname . ' rocks!';
}
}
assert(mprototype('DomainComputerScientist')
instanceof DomainComputerScientist);
mhydrate('DomainComputerScientist', [
'name' =>'John' ,
'surname'=>'McCarthy'
])->rocks(); //John McCarthy rocks!
assert(mexpose(
new DomainComputerScientist('Grace', 'Hopper')) ==
[
'name' => 'Grace' ,
'surname' => 'Hopper'
]
)
Share and Discuss
Discuss with your workmates how to properly unit test your Entities with fixed DateTimes and come up with additional alternatives.
Discuss with your workmates how to properly unit test your Entities with fixed DateTimes and come up with additional alternatives.
If you want to know more about testing patterns and approaches, take a look at the book xUnit Test Patterns: Refactoring Test Code by Gerard Meszaros.