Dummy Test Double Using Prophecy

Dummy is the simplest test double.

It doesn't contain any logic and you use it when you need to satisfy a dependency which is not needed for functionality being tested.

Below is the class which has a constructor dependency:

<?php

namespace App;

class Questioner
{
    private $output;

    public function __construct(OutputInterface $output)
    {
        $this->output = $output;
    }

    public function getQuestionsCount()
    {
        return 0;
    }
}

The dependency can be satisfied by providing a dummy object:

<?php

namespace tests;

use App\Output;
use App\Questioner;

class QuestionerTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @test
     */
    function new_questioner_has_no_questions()
    {
        $outputDummy = $this->prophesize(Output::class);
        $questioner  = new Questioner($outputDummy->reveal());

        $this->assertSame(0, $questioner->getQuestionsCount());
    }
}

This article is from the Test doubles using Prophecy series which is made from following articles:

  • Dummy Test Double Using Prophecy
  • Stub Test Double Using Prophecy
  • Spy Test Double Using Prophecy
  • Mock Test Double Using Prophecy
  • Fake Test Double Using Prophecy
  • Posted in: PHP, Prophecy, TDD, Technical

    Comments