-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Phpunit 10 support #41
Changes from all commits
68a9cea
58759fc
4b84620
ae5783a
04ef895
03f5fa5
bbdeb45
f76d29e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Prophecy\PhpUnit\Tests\Fixtures; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
|
||
class NoProphecy extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
public function testMethod() | ||
{ | ||
$this->assertTrue(true); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit colors="true" bootstrap="vendor/autoload.php"> | ||
<testsuites> | ||
<testsuite name="Prophecy PhpUnit Test Suite"> | ||
<directory suffix="Test.php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>./src</directory> | ||
</whitelist> | ||
</filter> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
cacheResult="false" | ||
colors="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Prophecy End2End PHPT Test Suite"> | ||
<directory suffix=".phpt">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage> | ||
<include> | ||
<directory>./src</directory> | ||
</include> | ||
</coverage> | ||
</phpunit> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,11 +38,6 @@ trait ProphecyTrait | |
*/ | ||
protected function prophesize(?string $classOrInterface = null): ObjectProphecy | ||
{ | ||
if (\is_string($classOrInterface)) { | ||
\assert($this instanceof TestCase); | ||
$this->recordDoubledType($classOrInterface); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems unrelated to the commit message There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The commit adding it says anyway, I suggest that increasing test coverage to 100% should be done in a separate PR so that we already get 100% test coverage with the code using PHPUnit 9.x There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Probably my mistake while committing
Done in #42 |
||
} | ||
|
||
return $this->getProphet()->prophesize($classOrInterface); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--TEST-- | ||
A test with a mock fails due to a missing expected call | ||
--FILE-- | ||
<?php | ||
|
||
require_once dirname(__DIR__) . '/xdebug_filter.php'; | ||
require dirname(__DIR__) . '/vendor/autoload.php'; | ||
|
||
(new PHPUnit\TextUI\Application())->run(['phpunit', 'fixtures/MockFailure.php', '--no-progress'], false); | ||
--EXPECTF-- | ||
PHPUnit 10.%s | ||
|
||
Runtime: PHP 8.%s | ||
Configuration: %s | ||
|
||
Time: %s | ||
|
||
There was 1 failure: | ||
|
||
1) Prophecy\PhpUnit\Tests\Fixtures\MockFailure::testMethod | ||
Some predictions failed: | ||
Double\DateTime\P1: | ||
Expected exactly 2 calls that match: | ||
Double\DateTime\P1->format(exact("Y-m-d")) | ||
but 1 were made: | ||
- format("Y-m-d") @ fixtures/MockFailure.php:%d | ||
|
||
%s/src/ProphecyTrait.php:%d | ||
|
||
FAILURES! | ||
Tests: 1, Assertions: 1, Failures: 1. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--TEST-- | ||
A test without Prophecy is executed with no additional assertions counted | ||
--FILE-- | ||
<?php | ||
|
||
require_once dirname(__DIR__) . '/xdebug_filter.php'; | ||
require dirname(__DIR__) . '/vendor/autoload.php'; | ||
|
||
(new PHPUnit\TextUI\Application())->run(['phpunit', 'fixtures/NoProphecy.php', '--no-progress'], false); | ||
--EXPECTF-- | ||
PHPUnit 10.%s | ||
|
||
Runtime: PHP 8.%s | ||
Configuration: %s | ||
|
||
Time: %s | ||
|
||
OK (1 test, 1 assertion) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--TEST-- | ||
A test with a spy fails due to expected call not made | ||
--FILE-- | ||
<?php | ||
|
||
require_once dirname(__DIR__) . '/xdebug_filter.php'; | ||
require dirname(__DIR__) . '/vendor/autoload.php'; | ||
|
||
(new PHPUnit\TextUI\Application())->run(['phpunit', 'fixtures/SpyFailure.php', '--no-progress'], false); | ||
--EXPECTF-- | ||
PHPUnit 10.%s | ||
|
||
Runtime: PHP 8.%s | ||
Configuration: %s | ||
|
||
Time: %s | ||
|
||
There was 1 error: | ||
|
||
1) Prophecy\PhpUnit\Tests\Fixtures\SpyFailure::testMethod | ||
Prophecy\Exception\Prediction\NoCallsException: No calls have been made that match: | ||
Double\DateTime\P1->format(exact("Y-m-d")) | ||
but expected at least one. | ||
|
||
%a%s/fixtures/SpyFailure.php:%d | ||
|
||
ERRORS! | ||
Tests: 1, Assertions: 1, Errors: 1. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--TEST-- | ||
A test with a mock is executed successfully | ||
--FILE-- | ||
<?php | ||
|
||
require_once dirname(__DIR__) . '/xdebug_filter.php'; | ||
require dirname(__DIR__) . '/vendor/autoload.php'; | ||
|
||
(new PHPUnit\TextUI\Application())->run(['phpunit', 'fixtures/Success.php', '--no-progress'], false); | ||
--EXPECTF-- | ||
PHPUnit 10.%s | ||
|
||
Runtime: PHP 8.%s | ||
Configuration: %s | ||
|
||
Time: %s | ||
|
||
OK (1 test, 1 assertion) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--TEST-- | ||
A test fails due to calling an unexisting method on a mock | ||
--FILE-- | ||
<?php | ||
|
||
require_once dirname(__DIR__) . '/xdebug_filter.php'; | ||
require dirname(__DIR__) . '/vendor/autoload.php'; | ||
|
||
(new PHPUnit\TextUI\Application())->run(['phpunit', 'fixtures/WrongCall.php', '--no-progress'], false); | ||
--EXPECTF-- | ||
PHPUnit 10.%s | ||
|
||
Runtime: PHP 8.%s | ||
Configuration: %s | ||
|
||
Time: %s | ||
|
||
There was 1 error: | ||
|
||
1) Prophecy\PhpUnit\Tests\Fixtures\WrongCall::testMethod | ||
Prophecy\Exception\Doubler\MethodNotFoundException: Method `Double\stdClass\P1::talk()` is not defined. | ||
|
||
%a%s/fixtures/WrongCall.php:%d | ||
|
||
ERRORS! | ||
Tests: 1, Assertions: 0, Errors: 1. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
if (function_exists('xdebug_set_filter')) { | ||
xdebug_set_filter( | ||
XDEBUG_FILTER_CODE_COVERAGE, | ||
XDEBUG_PATH_INCLUDE, | ||
[ __DIR__ . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR ] | ||
); | ||
xdebug_set_filter( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this managed by PHPUnit already based on the configuration in phpunit.xml ? Or is it not supported for the phpt runner ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know exactly, maybe is due to PHPT; locally, as said in the commit message, with this I observed a reduction of execution time from 26 seconds to only 3. |
||
XDEBUG_FILTER_CODE_COVERAGE, | ||
XDEBUG_PATH_EXCLUDE, | ||
[ __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR ] | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which possible naming collisions ? The namespace
Prophecy\PhpUnit\Tests\Fixtures
is fully ours.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was getting a "Cannot find class
Error
" with that, and the simple renaming made it go away.