mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
chore: uses snapshot testing in some visual testing
This commit is contained in:
@ -76,7 +76,7 @@
|
|||||||
"test:inline": "php bin/pest --colors=always --configuration=phpunit.inline.xml",
|
"test:inline": "php bin/pest --colors=always --configuration=phpunit.inline.xml",
|
||||||
"test:parallel": "php bin/pest --colors=always --exclude-group=integration --parallel --processes=10",
|
"test:parallel": "php bin/pest --colors=always --exclude-group=integration --parallel --processes=10",
|
||||||
"test:integration": "php bin/pest --colors=always --group=integration",
|
"test:integration": "php bin/pest --colors=always --group=integration",
|
||||||
"update:snapshots": "REBUILD_SNAPSHOTS=true php bin/pest --colors=always",
|
"update:snapshots": "REBUILD_SNAPSHOTS=true php bin/pest --colors=always --update-snapshots",
|
||||||
"test": [
|
"test": [
|
||||||
"@test:refacto",
|
"@test:refacto",
|
||||||
"@test:lint",
|
"@test:lint",
|
||||||
|
|||||||
@ -107,6 +107,10 @@ final class Help implements HandlesArguments
|
|||||||
'arg' => '--parallel',
|
'arg' => '--parallel',
|
||||||
'desc' => 'Run tests in parallel',
|
'desc' => 'Run tests in parallel',
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'arg' => '--update-snapshots',
|
||||||
|
'desc' => 'Update snapshots for tests using the "toMatchSnapshot" expectation',
|
||||||
|
],
|
||||||
], ...$content['Execution']];
|
], ...$content['Execution']];
|
||||||
|
|
||||||
$content['Selection'] = [[
|
$content['Selection'] = [[
|
||||||
|
|||||||
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
EXECUTION OPTIONS:
|
EXECUTION OPTIONS:
|
||||||
--parallel ........................................... Run tests in parallel
|
--parallel ........................................... Run tests in parallel
|
||||||
|
--update-snapshots Update snapshots for tests using the "toMatchSnapshot" expectation
|
||||||
--process-isolation ................ Run each test in a separate PHP process
|
--process-isolation ................ Run each test in a separate PHP process
|
||||||
--globals-backup ................. Backup and restore $GLOBALS for each test
|
--globals-backup ................. Backup and restore $GLOBALS for each test
|
||||||
--static-backup ......... Backup and restore static properties for each test
|
--static-backup ......... Backup and restore static properties for each test
|
||||||
@ -1,12 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
test('collision', function (array $arguments) {
|
test('collision', function (array $arguments) {
|
||||||
$snapshot = __DIR__.'/../.snapshots/collision.txt';
|
|
||||||
|
|
||||||
if (in_array('--parallel', $arguments)) {
|
|
||||||
$snapshot = __DIR__.'/../.snapshots/collision-parallel.txt';
|
|
||||||
}
|
|
||||||
|
|
||||||
$output = function () use ($arguments) {
|
$output = function () use ($arguments) {
|
||||||
$process = (new Symfony\Component\Process\Process(
|
$process = (new Symfony\Component\Process\Process(
|
||||||
array_merge(['php', 'bin/pest', 'tests/Fixtures/CollisionTest.php'], $arguments),
|
array_merge(['php', 'bin/pest', 'tests/Fixtures/CollisionTest.php'], $arguments),
|
||||||
@ -19,23 +13,17 @@ test('collision', function (array $arguments) {
|
|||||||
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||||
};
|
};
|
||||||
|
|
||||||
if (getenv('REBUILD_SNAPSHOTS')) {
|
$outputContent = explode("\n", $output());
|
||||||
$outputContent = explode("\n", $output());
|
array_pop($outputContent);
|
||||||
|
array_pop($outputContent);
|
||||||
|
array_pop($outputContent);
|
||||||
|
|
||||||
|
if (in_array('--parallel', $arguments)) {
|
||||||
array_pop($outputContent);
|
array_pop($outputContent);
|
||||||
array_pop($outputContent);
|
array_pop($outputContent);
|
||||||
array_pop($outputContent);
|
|
||||||
|
|
||||||
if (in_array('--parallel', $arguments)) {
|
|
||||||
array_pop($outputContent);
|
|
||||||
array_pop($outputContent);
|
|
||||||
}
|
|
||||||
|
|
||||||
file_put_contents($snapshot, implode("\n", $outputContent));
|
|
||||||
|
|
||||||
$this->markTestSkipped('Snapshot rebuilt.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
expect($output())->toContain(file_get_contents($snapshot));
|
expect(implode("\n", $outputContent))->toMatchSnapshot();
|
||||||
})->with([
|
})->with([
|
||||||
[['']],
|
[['']],
|
||||||
[['--parallel']],
|
[['--parallel']],
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
test('visual snapshot of help command output', function () {
|
test('visual snapshot of help command output', function () {
|
||||||
$snapshot = __DIR__.'/../.snapshots/help-command.txt';
|
|
||||||
|
|
||||||
$output = function () {
|
$output = function () {
|
||||||
$process = (new Symfony\Component\Process\Process(['php', 'bin/pest', '--help'], null, ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true']));
|
$process = (new Symfony\Component\Process\Process(['php', 'bin/pest', '--help'], null, ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true']));
|
||||||
|
|
||||||
@ -11,11 +9,5 @@ test('visual snapshot of help command output', function () {
|
|||||||
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||||
};
|
};
|
||||||
|
|
||||||
if (getenv('REBUILD_SNAPSHOTS')) {
|
expect($output())->toMatchSnapshot();
|
||||||
file_put_contents($snapshot, $output());
|
|
||||||
|
|
||||||
$this->markTestSkipped('Snapshot rebuilt.');
|
|
||||||
}
|
|
||||||
|
|
||||||
expect($output())->toContain(file_get_contents($snapshot));
|
|
||||||
})->skipOnWindows();
|
})->skipOnWindows();
|
||||||
|
|||||||
@ -11,8 +11,6 @@ $run = function () {
|
|||||||
|
|
||||||
$process->run();
|
$process->run();
|
||||||
|
|
||||||
// expect($process->getExitCode())->toBe(0);
|
|
||||||
|
|
||||||
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user