feat(expect): updates test suite to use expectation api

This commit is contained in:
Nuno Maduro
2020-07-14 23:15:14 +02:00
parent e03d015120
commit 832882160f
37 changed files with 151 additions and 257 deletions

View File

@ -10,7 +10,7 @@ $run = function (string $target, $decorated = false) {
return $decorated ? $process->getOutput() : preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
};
$snapshot = function ($name) {
$snapshot = function ($name) {
$testsPath = dirname(__DIR__);
return file_get_contents(implode(DIRECTORY_SEPARATOR, [
@ -21,23 +21,15 @@ $snapshot = function ($name) {
};
test('allows to run a single test', function () use ($run, $snapshot) {
assertStringContainsString(
$snapshot('allows-to-run-a-single-test'),
$run('tests/Fixtures/DirectoryWithTests/ExampleTest.php'));
expect($run('tests/Fixtures/DirectoryWithTests/ExampleTest.php'))->toContain($snapshot('allows-to-run-a-single-test'));
})->skip(PHP_OS_FAMILY === 'Windows');
test('allows to run a directory', function () use ($run, $snapshot) {
assertStringContainsString(
$snapshot('allows-to-run-a-directory'),
$run('tests/Fixtures')
);
expect($run('tests/Fixtures'))->toContain($snapshot('allows-to-run-a-directory'));
})->skip(PHP_OS_FAMILY === 'Windows');
it('has ascii chars', function () use ($run, $snapshot) {
assertStringContainsString(
$snapshot('has-ascii-chars'),
$run('tests/Fixtures/DirectoryWithTests/ExampleTest.php', true)
);
expect($run('tests/Fixtures/DirectoryWithTests/ExampleTest.php', true))->toContain($snapshot('has-ascii-chars'));
})->skip(PHP_OS_FAMILY === 'Windows');
it('disable decorating printer when colors is set to never', function () use ($snapshot) {
@ -49,9 +41,5 @@ it('disable decorating printer when colors is set to never', function () use ($s
], dirname(__DIR__, 2));
$process->run();
$output = $process->getOutput();
assertStringContainsString(
$snapshot('disable-decorating-printer'),
$output
);
expect($output)->toContain($snapshot('disable-decorating-printer'));
})->skip(PHP_OS_FAMILY === 'Windows');

View File

@ -22,7 +22,7 @@ test('visual snapshot of test suite on success', function () {
$output = explode("\n", $output());
array_pop($output);
array_pop($output);
assertStringContainsString(implode("\n", $output), file_get_contents($snapshot));
expect(file_get_contents($snapshot))->toContain(implode("\n", $output));
}
})->skip(!getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE'))
->skip(PHP_OS_FAMILY === 'Windows');