Skip to content

Commit

Permalink
Add regression test for phpspec#27
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean85 committed Oct 7, 2020
1 parent 08db3fb commit 487377c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
24 changes: 24 additions & 0 deletions fixtures/MockCallMatchFailure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Prophecy\PhpUnit\Tests\Fixtures;

use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;

class MockCallMatchFailure extends TestCase
{
use ProphecyTrait;

public function testMethod()
{
$prophecy = $this->prophesize('DateTime');

$prophecy->format('Y-m-d')->shouldBeCalledOnce();

$double = $prophecy->reveal();

$double->format('wrong-parameter');

throw new \RuntimeException('ERROR - mock should have already make this test fail earlier');
}
}
14 changes: 14 additions & 0 deletions tests/ProphecyTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PHPUnit\Framework\TestCase;
use PHPUnit\Runner\BaseTestRunner;
use Prophecy\PhpUnit\Tests\Fixtures\Error;
use Prophecy\PhpUnit\Tests\Fixtures\MockCallMatchFailure;
use Prophecy\PhpUnit\Tests\Fixtures\MockFailure;
use Prophecy\PhpUnit\Tests\Fixtures\SpyFailure;
use Prophecy\PhpUnit\Tests\Fixtures\Success;
Expand Down Expand Up @@ -61,6 +62,19 @@ public function testMockPredictionFailure(): void
$this->assertSame(BaseTestRunner::STATUS_FAILURE, $test->getStatus());
}

public function testMockCallDoesntMatchExpectation(): void
{
$test = new MockCallMatchFailure('testMethod');

$result = $test->run();

$this->assertSame(0, $result->errorCount());
$this->assertSame(1, $result->failureCount());
$this->assertCount(1, $result);
$this->assertSame(1, $test->getNumAssertions());
$this->assertSame(BaseTestRunner::STATUS_FAILURE, $test->getStatus());
}

public function testDoublingError(): void
{
$test = new Error('testMethod');
Expand Down

0 comments on commit 487377c

Please sign in to comment.