tests: adds more tests regarding snapshots multiple

This commit is contained in:
Nuno Maduro
2023-08-02 23:02:00 +01:00
parent 43107c1743
commit 00109e9976
29 changed files with 79 additions and 26 deletions

View File

@ -62,6 +62,11 @@ trait Testable
*/
private static ?Closure $__afterAll = null;
/**
* The list of snapshot changes, if any.
*/
private array $__snapshotChanges = [];
/**
* Resets the test case static properties.
*/
@ -331,6 +336,24 @@ trait Testable
return ExceptionTrace::ensure(fn (): mixed => call_user_func_array(Closure::bind($closure, $this, $this::class), $arguments));
}
/** @postCondition */
protected function __MarkTestIncompleteIfSnapshotHaveChanged(): void
{
if (count($this->__snapshotChanges) === 0) {
return;
}
if (count($this->__snapshotChanges) === 1) {
$this->markTestIncomplete($this->__snapshotChanges[0]);
return;
}
$messages = implode(PHP_EOL, array_map(static fn (string $message): string => '- $message', $this->__snapshotChanges));
$this->markTestIncomplete($messages);
}
/**
* The printable test case name.
*/

View File

@ -189,29 +189,7 @@ final class TestCaseFactory
private static \$__filename = '$filename';
private array \$__snapshotChanges = [];
$methodsCode
/** @postCondition */
protected function __MarkTestIncompleteIfSnapshotHaveChanged(): void
{
if (empty(\$this->__snapshotChanges)) {
return;
}
if (count(\$this->__snapshotChanges) === 1) {
\$this->markTestIncomplete(\$this->__snapshotChanges[0]);
return;
}
\$formattedMessages = implode(PHP_EOL, array_map(function (string \$message) {
return "- \$message";
}, \$this->__snapshotChanges));
\$this->markTestIncomplete(\$formattedMessages);
}
}
PHP;

View File

@ -1,5 +1,5 @@
Pest Testing Framework 2.11.0.
Pest Testing Framework 2.12.0.
USAGE: pest <file> [options]

View File

@ -1,3 +1,3 @@
Pest Testing Framework 2.11.0.
Pest Testing Framework 2.12.0.

View File

@ -698,6 +698,22 @@
✓ failures
✓ failures with custom message
✓ not failures
✓ multiple snapshot expectations
✓ multiple snapshot expectations with datasets with (1)
✓ multiple snapshot expectations with datasets with ('foo')
✓ multiple snapshot expectations with datasets with ('bar')
✓ multiple snapshot expectations with datasets with ('baz')
✓ describable → multiple snapshot expectations with describe
✓ multiple snapshot expectations with repeat @ repetition 1 of 10
✓ multiple snapshot expectations with repeat @ repetition 2 of 10
✓ multiple snapshot expectations with repeat @ repetition 3 of 10
✓ multiple snapshot expectations with repeat @ repetition 4 of 10
✓ multiple snapshot expectations with repeat @ repetition 5 of 10
✓ multiple snapshot expectations with repeat @ repetition 6 of 10
✓ multiple snapshot expectations with repeat @ repetition 7 of 10
✓ multiple snapshot expectations with repeat @ repetition 8 of 10
✓ multiple snapshot expectations with repeat @ repetition 9 of 10
✓ multiple snapshot expectations with repeat @ repetition 10 of 10
PASS Tests\Features\Expect\toStartWith
✓ pass
@ -1194,4 +1210,4 @@
WARN Tests\Visual\Version
- visual snapshot of help command output
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 844 passed (1947 assertions)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 860 passed (1979 assertions)

View File

@ -132,3 +132,17 @@ test('multiple snapshot expectations with datasets', function () {
expect('foo bar 2')->toMatchSnapshot();
})->with([1, 'foo', 'bar', 'baz']);
describe('describable', function () {
test('multiple snapshot expectations with describe', function () {
expect('foo bar 1')->toMatchSnapshot();
expect('foo bar 2')->toMatchSnapshot();
});
});
test('multiple snapshot expectations with repeat', function () {
expect('foo bar 1')->toMatchSnapshot();
expect('foo bar 2')->toMatchSnapshot();
})->repeat(10);

View File

@ -16,7 +16,7 @@ $run = function () {
test('parallel', function () use ($run) {
expect($run('--exclude-group=integration'))
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 833 passed (1932 assertions)')
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 849 passed (1964 assertions)')
->toContain('Parallel: 3 processes');
})->skipOnWindows();