Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fixtures/Error.php → fixtures/WrongCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;

class Error extends TestCase
class WrongCall extends TestCase
{
use ProphecyTrait;

Expand Down
29 changes: 16 additions & 13 deletions phpunit.xml.dist
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/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResult="false"
colors="true"
>
<testsuites>
<testsuite name="Prophecy PhpUnit Test Suite">
<directory suffix=".phpt">./tests/</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory>./src</directory>
</include>
</coverage>
</phpunit>
30 changes: 30 additions & 0 deletions tests/MockFailure.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
A test with a mock fails due to a missing expected call
--FILE--
<?php

require_once __DIR__ . '/run_test.php';

\Prophecy\PhpUnit\Tests\runTest('MockFailure');
--EXPECTF--
PHPUnit %s

F %s 1 / 1 (100%)

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
%s/tests/run_test.php:%d

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
16 changes: 16 additions & 0 deletions tests/NoProphecy.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
A test without Prophecy is executed with no additional assertions counted
--FILE--
<?php

require_once __DIR__ . '/run_test.php';

\Prophecy\PhpUnit\Tests\runTest('NoProphecy');
--EXPECTF--
PHPUnit %s

. %s 1 / 1 (100%)

Time: %s

OK (1 test, 1 assertion)
90 changes: 0 additions & 90 deletions tests/ProphecyTraitTest.php

This file was deleted.

26 changes: 26 additions & 0 deletions tests/SpyFailure.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
A test with a spy fails due to expected call not made
--FILE--
<?php

require_once __DIR__ . '/run_test.php';

\Prophecy\PhpUnit\Tests\runTest('SpyFailure');
--EXPECTF--
PHPUnit %s

F %s 1 / 1 (100%)

Time: %a

There was 1 failure:

1) Prophecy\PhpUnit\Tests\Fixtures\SpyFailure::testMethod
No calls have been made that match:
Double\DateTime\P1->format(exact("Y-m-d"))
but expected at least one.

%s/tests/run_test.php:%d

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
16 changes: 16 additions & 0 deletions tests/Success.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
A test with a mock is executed successfully
--FILE--
<?php

require_once __DIR__ . '/run_test.php';

\Prophecy\PhpUnit\Tests\runTest('Success');
--EXPECTF--
PHPUnit %s

. %s 1 / 1 (100%)

Time: %s

OK (1 test, 1 assertion)
25 changes: 25 additions & 0 deletions tests/WrongCall.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
A test fails due to calling an unexisting method on a mock
--FILE--
<?php

require_once __DIR__ . '/run_test.php';

\Prophecy\PhpUnit\Tests\runTest('WrongCall');
--EXPECTF--
PHPUnit %s

E %s 1 / 1 (100%)

Time: %a

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
%s/tests/run_test.php:%d

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
18 changes: 18 additions & 0 deletions tests/run_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Prophecy\PhpUnit\Tests;

use PHPUnit\TextUI\Command;

require_once __DIR__ . '/xdebug_filter.php';
require_once dirname(__DIR__) . '/vendor/autoload.php';

function runTest(string $fixtureName): void
{
$filename = dirname(__DIR__) . '/fixtures/' . $fixtureName . '.php';
if (!file_exists($filename)) {
throw new \InvalidArgumentException('Unable to find test fixture at path ' . $filename);
}

(new Command())->run(['phpunit', $filename], false);
}
13 changes: 13 additions & 0 deletions tests/xdebug_filter.php
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,
[ dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR ]
);
xdebug_set_filter(
XDEBUG_FILTER_CODE_COVERAGE,
XDEBUG_PATH_EXCLUDE,
[ dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR ]
);
}