Last active
March 9, 2016 23:53
-
-
Save kirkbushell/badce06f0daa2a844318 to your computer and use it in GitHub Desktop.
Weirdness in PHPSpec?
This file contains hidden or 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 | |
namespace IronSteel\Construction; | |
use IronSteel\Library\Uuid; | |
class BuildingId extends Uuid | |
{ | |
} |
This file contains hidden or 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 | |
namespace spec\IronSteel\Construction; | |
use IronSteel\Construction\BuildingId; | |
use PhpSpec\ObjectBehavior; | |
use Prophecy\Argument; | |
class BuildingIdSpec extends ObjectBehavior | |
{ | |
function it_is_initializable() | |
{ | |
$this->beConstructedWith('abcdef'); | |
$this->shouldHaveType(BuildingId::class); | |
} | |
function it_should_generate_itself() | |
{ | |
$this->beConstructedThrough('generate'); | |
$this->shouldHaveType(BuildingId::class); | |
$this->toString()->shouldBeString(); // This is the problem call/assertion | |
} | |
} |
This file contains hidden or 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
IronSteel/Construction/BuildingId | |
16 - it should generate itself | |
method [array:2] not found. | |
75% 25% 4 | |
2 specs | |
4 examples (3 passed, 1 broken) | |
10ms | |
Do you want me to create `Ramsey\Uuid\Uuid::isString()` for you? [Y/n] |
This file contains hidden or 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 | |
namespace IronSteel\Library; | |
use Ramsey\Uuid\Uuid as Ruuid; | |
/** | |
* Base class for all UUIDs on the system. | |
*/ | |
abstract class Uuid | |
{ | |
/** | |
* Stores the ID. | |
* | |
* @var string | |
*/ | |
private $id; | |
/** | |
* Constructs a new UUID object. | |
* | |
* @param string $id | |
*/ | |
public function __construct($id) | |
{ | |
$this->id = $id; | |
} | |
/** | |
* Generates a new version 4 UUID object. | |
* | |
* @return static | |
*/ | |
public static function generate() | |
{ | |
return new static(Ruuid::uuid4()); | |
} | |
/** | |
* Syntactical sugar for string conversion. | |
* | |
* @return string | |
*/ | |
public function toString() | |
{ | |
return $this->id; | |
} | |
/** | |
* Returns the UUID as a string. | |
* | |
* @return string | |
*/ | |
public function __toString() | |
{ | |
return $this->toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment