Skip to content

Instantly share code, notes, and snippets.

@teklakct
Last active January 16, 2016 15:16
Show Gist options
  • Save teklakct/ae1cfd8d03ceee4a9063 to your computer and use it in GitHub Desktop.
Save teklakct/ae1cfd8d03ceee4a9063 to your computer and use it in GitHub Desktop.
Przykładowa specyfikacja do opisania zachowania Named Constructors wykorzystując PHPSpec
<?php
class Person
{
private $name;
private $surname;
private function __construct($name, $surname)
{
$this->name = $name;
$this->surname = $surname;
}
public static function born($name, $surname)
{
$person = new Person($name, $surname);
// TODO: write other logic here
return $person;
}
public static function bornAsCloneOf(Person $original)
{
$name = $original->getName();
$surname = $original->getSurname();
$person = new Person($name, $surname);
// TODO: write other logic here
return $person;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @return mixed
*/
public function getSurname()
{
return $this->surname;
}
public function changeName($newName)
{
$this->name = $newName;
}
}
<?php
namespace spec;
use Person;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
/**
* Class PersonSpec
* @package spec
* @mixin Person
*/
class PersonSpec extends ObjectBehavior
{
function let()
{
$name = 'asia';
$surname = 'asiowa';
$this->beConstructedThroughBorn($name, $surname);
}
function its_person()
{
$this->shouldHaveType(Person::class);
}
function it_create_person_clone(Person $original)
{
$original->getName()->willReturn('Jola');
$original->getSurname()->willReturn('Jolanta');
$this->beConstructedThroughBornAsCloneOf($original);
$this->getName()->shouldBe('Jola');
$this->getSurname()->shouldBe('Jolanta');
}
function it_allow_to_change_person_name()
{
$this->changeName('miriam');
$this->getName()->shouldBe('miriam');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment