-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't silently ignore exceptions in mock destructor
- Loading branch information
1 parent
4918913
commit c61d971
Showing
4 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <sebastian@phpunit.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PHPUnit\TestFixture; | ||
|
||
use Exception; | ||
|
||
class ExceptionInMockDestructor | ||
{ | ||
public function __destruct() | ||
{ | ||
throw new Exception('Some exception.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <sebastian@phpunit.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PHPUnit\TestFixture; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class ExceptionInMockDestructorTest extends TestCase | ||
{ | ||
public function testOne(): void | ||
{ | ||
$mock = $this->createMock(ExceptionInMockDestructor::class); | ||
|
||
$this->assertInstanceOf(ExceptionInMockDestructor::class, $mock); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/end-to-end/generic/exception-in-mock-destructor.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--TEST-- | ||
phpunit ../../_files/ExceptionInMockDestructorTest.php | ||
--FILE-- | ||
<?php declare(strict_types=1); | ||
$_SERVER['argv'][] = '--do-not-cache-result'; | ||
$_SERVER['argv'][] = '--no-configuration'; | ||
$_SERVER['argv'][] = __DIR__ . '/../../_files/ExceptionInMockDestructorTest.php'; | ||
|
||
require_once __DIR__ . '/../../bootstrap.php'; | ||
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']); | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
Runtime: %s | ||
|
||
E 1 / 1 (100%) | ||
|
||
Time: %s, Memory: %s | ||
|
||
There was 1 error: | ||
|
||
1) PHPUnit\TestFixture\ExceptionInMockDestructorTest::testOne | ||
Exception: Some exception. | ||
|
||
%sExceptionInMockDestructor.php:%d | ||
|
||
ERRORS! | ||
Tests: 1, Assertions: 1, Errors: 1. |