Skip to content

Commit

Permalink
Initial work on Prophecy support
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Nov 5, 2014
1 parent 24d985b commit 6c21c66
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
13 changes: 13 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,19 @@
<exclude name="**/Autoload.*" />
</fileset>
</copy>

<copy todir="${basedir}/build/phar/phpdocumentor-reflection-docblock">
<fileset dir="${basedir}/vendor/phpdocumentor/reflection-docblock/src">
<include name="**/*.php" />
</fileset>
</copy>

<copy file="${basedir}/vendor/phpspec/prophecy/LICENSE" tofile="${basedir}/build/phar/phpspec-prophecy/LICENSE"/>
<copy todir="${basedir}/build/phar/phpspec-prophecy">
<fileset dir="${basedir}/vendor/phpspec/prophecy/src">
<include name="**/*.php" />
</fileset>
</copy>
</target>

<target name="phar-build">
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"phpunit/php-code-coverage": "3.0.*@dev",
"phpunit/php-timer": "~1.0.2",
"phpunit/phpunit-mock-objects": "2.4.*@dev",
"phpspec/prophecy": "~1.2",
"symfony/yaml": "~2.0",
"sebastian/comparator": "1.1.*@dev",
"sebastian/diff": "~1.1",
Expand Down
46 changes: 46 additions & 0 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
use SebastianBergmann\GlobalState\Blacklist;
use SebastianBergmann\Exporter\Context;
use SebastianBergmann\Exporter\Exporter;
use Prophecy\Exception\Prediction\PredictionException;
use Prophecy\Prophet;

/**
* A TestCase defines the fixture to run multiple tests.
Expand Down Expand Up @@ -293,6 +295,11 @@ abstract class PHPUnit_Framework_TestCase extends PHPUnit_Framework_Assert imple
*/
private $snapshot;

/**
* @var Prophecy\Prophet
*/
private $prophet;

/**
* Constructs a test case with the given name.
*
Expand Down Expand Up @@ -966,6 +973,21 @@ protected function verifyMockObjects()

$mockObject->__phpunit_verify();
}

if ($this->prophet !== null) {
foreach ($this->prophet->getProphecies() as $objectProphecy) {
foreach ($objectProphecy->getMethodProphecies() as $methodProphecies) {
foreach ($methodProphecies as $methodProphecy) {
if ($methodProphecy->getPrediction() !== null) {
$this->numAssertions++;
}
}
}
}

$this->prophet->checkPredictions();
$this->prophet = null;
}
}

/**
Expand Down Expand Up @@ -1439,6 +1461,17 @@ protected function getObjectForTrait($traitName, array $arguments = array(), $tr
);
}

/**
* @param string|null $classOrInterface
* @return \Prophecy\Prophecy\ObjectProphecy
* @throws \LogicException
* @since Method available since Release 4.5.0
*/
protected function prophesize($classOrInterface = null)
{
return $this->getProphet()->prophesize($classOrInterface);
}

/**
* Adds a value to the assertion counter.
*
Expand Down Expand Up @@ -2001,4 +2034,17 @@ private function restoreGlobalState()

$this->snapshot = null;
}

/**
* @return Prophecy\Prophet
* @since Method available since Release 4.5.0
*/
private function getProphet()
{
if ($this->prophet === null) {
$this->prophet = new Prophet;
}

return $this->prophet;
}
}

4 comments on commit 6c21c66

@stof
Copy link
Contributor

@stof stof commented on 6c21c66 Nov 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing the conversion of PredictionException into PHPUnit failures, as done in prophecy-phpunit

@sebastianbergmann
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, hence the "Initial work" in the commit message ;-)

@everzet
Copy link

@everzet everzet commented on 6c21c66 Nov 9, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebastianbergmann @stof I finally delivered my last conference talk this year, I should have some time now to add things you're missing. Tell me what you need, guys :)

@sebastianbergmann
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@everzet I described what I need in phpspec/prophecy#132

Please sign in to comment.