phpspec / prophecy

Highly opinionated mocking framework for PHP 5.3+
MIT License
8.53k stars 240 forks source link

Prophecy cannot prophesize itself #233

Closed jubianchi closed 8 years ago

jubianchi commented 8 years ago

I'm trying to integrate prophecy in an @atoum extension and I'm having problem when writing my unit tests. At some point in need to prophesize prophecy and it does not seem to work :

<?php

require_once __DIR__ . '/vendor/autoload.php';

$className = uniqid();

$prophet = new \Prophecy\Prophet();
$prophetProphecy = $prophet->prophesize('Prophecy\Prophet');
$objectProphecy = $prophet->prophesize('Prophecy\Prophecy\ObjectProphecy');

$prophetProphecy->prophesize($className)->willReturn($objectProphecy->reveal());
var_dump($prophetProphecy->reveal()->prophesize($className)); // NULL

$prophetProphecy->prophesize($className)->willReturn('foo');
var_dump($prophetProphecy->reveal()->prophesize($className)); // string(3) "foo"
stof commented 8 years ago

Well, there might indeed be some issues with such inceptions in a few cases. Most Prophecy classes can be doubled though (Prophecy is tested with PhpSpec, which uses Prophecy internally)

malkusch commented 8 years ago

This goes in line with the PhpSpec way: making it hard to work with badly designed APIs

SCNR

everzet commented 8 years ago

@jubianchi @malkusch mocking core of the mocking framework with the mocking framework itself is a very specific case of design where the negative feedback isn't always illustrative of design issues.

jubianchi commented 8 years ago

@everzet I'm not judging the design of prophecy which I know is very good.

My need was just to build an atoum ext. and as always, we try to test tools with themselves. I will use another strategy here.