Skip to content

Instantly share code, notes, and snippets.

@adamelso
Last active August 29, 2015 14:02
Show Gist options
  • Save adamelso/94082070925eddbb5c32 to your computer and use it in GitHub Desktop.
Save adamelso/94082070925eddbb5c32 to your computer and use it in GitHub Desktop.
Creating a fake Translator with Spec Behaviour Driven Development using PhpSpec
<?php
namespace spec\FakeTranslator;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class GreekTranslatorSpec extends ObjectBehavior
{
function it_is_a_translator()
{
$this->shouldImplement('FakeTranslator\Translator');
}
function it_translates_the_word_Welcome_to_Greek()
{
$this->translate('Welcome')->shouldReturn('Μαλάκα');
}
function it_translates_the_word_Anything_to_Greek()
{
$this->translate('Anything')->shouldReturn('Μαλάκα');
}
function it_translates_the_word_Yourself_to_Greek()
{
$this->translate('Yourself')->shouldReturn('Μαλάκα');
}
function it_translates_the_word_Okay_to_Greek()
{
$this->translate('Okay')->shouldReturn('Μαλάκα');
}
}
<?php
namespace spec\FakeTranslator;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class PolishTranslatorSpec extends ObjectBehavior
{
function it_is_a_translator()
{
$this->shouldImplement('FakeTranslator\Translator');
}
function it_translates_the_word_Hello_to_Polish()
{
$this->translate('Hello')->shouldReturn('Kurwa');
}
function it_translates_the_word_Something_to_Polish()
{
$this->translate('Something')->shouldReturn('Kurwa');
}
function it_translates_the_word_Mother_to_Polish()
{
$this->translate('Mother')->shouldReturn('Kurwa');
}
function it_translates_the_word_Okay_to_Polish()
{
$this->translate('Okay')->shouldReturn('Kurwa');
}
}
<?php
namespace FakeTranslator;
interface Translator
{
/**
* @param string $phrase
*
* @return string
*/
public function translate($phrase);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment