Skip to content

Instantly share code, notes, and snippets.

@kirkbushell
Last active March 9, 2016 23:53
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 kirkbushell/badce06f0daa2a844318 to your computer and use it in GitHub Desktop.
Save kirkbushell/badce06f0daa2a844318 to your computer and use it in GitHub Desktop.
Weirdness in PHPSpec?
<?php
namespace IronSteel\Construction;
use IronSteel\Library\Uuid;
class BuildingId extends Uuid
{
}
<?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
}
}
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]
<?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