Skip to content

Commit b50ed4d

Browse files
Test that a shrinking attempt that ends before it is prepared does not falsify a property in another way
1 parent d080872 commit b50ed4d

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture\PropertyBasedTesting;
11+
12+
use PHPUnit\Framework\Attributes\Property;
13+
use PHPUnit\Framework\TestCase;
14+
use RuntimeException;
15+
16+
final class ShrinkingAttemptThatEndsBeforeItIsPreparedTest extends TestCase
17+
{
18+
private static int $numberOfExamples = 0;
19+
20+
/**
21+
* The example that falsifies the property and its four replays are
22+
* prepared, the first shrinking attempt is not.
23+
*/
24+
protected function setUp(): void
25+
{
26+
self::$numberOfExamples++;
27+
28+
if (self::$numberOfExamples === 6) {
29+
throw new RuntimeException('The first shrinking attempt is not prepared');
30+
}
31+
}
32+
33+
/**
34+
* @param int<0, 100> $value
35+
*/
36+
#[Property]
37+
public function testIsFalsifiedByEveryExample(int $value): void
38+
{
39+
$this->assertGreaterThan(100, $value);
40+
}
41+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
A shrinking attempt that ends before it is prepared does not falsify the property in another way
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--no-configuration';
6+
$_SERVER['argv'][] = '--do-not-record-test-run-history';
7+
$_SERVER['argv'][] = '--random-seed';
8+
$_SERVER['argv'][] = '1234';
9+
$_SERVER['argv'][] = __DIR__ . '/_files/ShrinkingAttemptThatEndsBeforeItIsPreparedTest.php';
10+
11+
require __DIR__ . '/../../bootstrap.php';
12+
13+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
14+
--EXPECTF--
15+
PHPUnit %s by Sebastian Bergmann and contributors.
16+
17+
Runtime: %s
18+
Random Seed: 1234
19+
20+
F 1 / 1 (100%)
21+
22+
Time: %s, Memory: %s
23+
24+
There was 1 failure:
25+
26+
1) PHPUnit\TestFixture\PropertyBasedTesting\ShrinkingAttemptThatEndsBeforeItIsPreparedTest::testIsFalsifiedByEveryExample
27+
Failed asserting that 0 is greater than 100.
28+
29+
Property falsified after 1 example with this counterexample:
30+
31+
$value = 0;
32+
33+
%sShrinkingAttemptThatEndsBeforeItIsPreparedTest.php:%d
34+
35+
FAILURES!
36+
Tests: 1, Assertions: 1, Failures: 1.

0 commit comments

Comments
 (0)