php - Why phpspec does not see shouldBeLike for object from static constructor? -


i'm trying spec value object static constructor in phpspec , problem says shouldbelike undefined method. object returned times method new money, don't know wrong...

moneyspec:

<?php  namespace spec;  use money; use phpspec\objectbehavior;  class moneyspec extends objectbehavior {     function it_is_initializable()     {         $this->shouldhavetype(money::class);     }      function it_multiplies()     {         $five = money::dollar(5);         $five->times(2)->shouldbelike(money::dollar(5));         $five->times(3)->shouldbelike(money::dollar(6));     } } 

money:

<?php  class money {     private $amount;      private function __construct($amount)     {         $this->amount = $amount;     }      public static function dollar($amount)     {         return new money($amount);     }      public function times($multiplier)     {         return new money($this->amount * $multiplier);     }      public function getamount()     {         return $this->amount;     } } 

for named static constructors need use beconstructedthrough (or 1 of shorter syntax described). example, case:

function it_multiplies() {     $this->beconstructedthrough('dollar', [5]);     $this->times(2)->shouldbelike(money::dollar(5));     $this->times(3)->shouldbelike(money::dollar(6)); } 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -