mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
feat: allows array formats
This commit is contained in:
@ -9,6 +9,7 @@ use Closure;
|
||||
use DateTimeInterface;
|
||||
use Error;
|
||||
use InvalidArgumentException;
|
||||
use JsonSerializable;
|
||||
use Pest\Exceptions\InvalidExpectationValue;
|
||||
use Pest\Matchers\Any;
|
||||
use Pest\Support\Arr;
|
||||
@ -23,6 +24,7 @@ use ReflectionFunction;
|
||||
use ReflectionNamedType;
|
||||
use Stringable;
|
||||
use Throwable;
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@ -809,7 +811,11 @@ final class Expectation
|
||||
is_object($this->value) && method_exists($this->value, '__toString') => $this->value->__toString(),
|
||||
is_object($this->value) && method_exists($this->value, 'toString') => $this->value->toString(),
|
||||
$this->value instanceof \Illuminate\Testing\TestResponse => $this->value->getContent(), // @phpstan-ignore-line
|
||||
default => InvalidExpectationValue::expected('Stringable|string'),
|
||||
is_array($this->value) => json_encode($this->value, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),
|
||||
$this->value instanceof Traversable => json_encode(iterator_to_array($this->value), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),
|
||||
$this->value instanceof JsonSerializable => json_encode($this->value->jsonSerialize(), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),
|
||||
is_object($this->value) && method_exists($this->value, 'toArray') => json_encode($this->value->toArray(), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),
|
||||
default => InvalidExpectationValue::expected('array|object|string'),
|
||||
};
|
||||
|
||||
$testCase = TestSuite::getInstance()->test;
|
||||
|
||||
@ -0,0 +1,3 @@
|
||||
{
|
||||
"key": " <div class=\"container\">\n <div class=\"row\">\n <div class=\"col-md-12\">\n <h1>Snapshot<\/h1>\n <\/div>\n <\/div>\n <\/div>"
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
{
|
||||
"key": " <div class=\"container\">\n <div class=\"row\">\n <div class=\"col-md-12\">\n <h1>Snapshot<\/h1>\n <\/div>\n <\/div>\n <\/div>"
|
||||
}
|
||||
@ -1,60 +0,0 @@
|
||||
|
||||
PASS Tests\Playground
|
||||
✓ basic
|
||||
|
||||
Tests: 1 passed
|
||||
Time: 0.20s
|
||||
Cov: 6.49%
|
||||
|
||||
Actions/AddsDefaults ........................................... 0.0 %
|
||||
Actions/AddsTests .............................................. 0.0 %
|
||||
Actions/LoadStructure .......................................... 0.0 %
|
||||
Actions/ValidatesConfiguration ................................. 0.0 %
|
||||
Actions/ValidatesEnvironment ................................... 0.0 %
|
||||
Concerns/TestCase 40..54, 71..88, 123..126, 147 ............... 44.4 %
|
||||
Console/Command ................................................ 0.0 %
|
||||
Contracts/HasPrintableTestCaseName ............................. 0.0 %
|
||||
Contracts/Plugins/AddsOutput ................................ 100.0 %
|
||||
Contracts/Plugins/HandlesArguments .......................... 100.0 %
|
||||
Datasets ....................................................... 0.0 %
|
||||
Exceptions/AfterAllAlreadyExist ................................ 0.0 %
|
||||
Exceptions/AfterEachAlreadyExist ............................... 0.0 %
|
||||
Exceptions/AttributeNotSupportedYet ............................ 0.0 %
|
||||
Exceptions/BeforeEachAlreadyExist .............................. 0.0 %
|
||||
Exceptions/DatasetAlreadyExist ................................. 0.0 %
|
||||
Exceptions/DatasetDoesNotExist ................................. 0.0 %
|
||||
Exceptions/FileOrFolderNotFound ................................ 0.0 %
|
||||
Exceptions/InvalidConsoleArgument .............................. 0.0 %
|
||||
Exceptions/InvalidPestCommand .................................. 0.0 %
|
||||
Exceptions/InvalidUsesPath ..................................... 0.0 %
|
||||
Exceptions/ShouldNotHappen ..................................... 0.0 %
|
||||
Exceptions/TestAlreadyExist .................................... 0.0 %
|
||||
Exceptions/TestCaseAlreadyInUse ................................ 0.0 %
|
||||
Exceptions/TestCaseClassOrTraitNotFound ........................ 0.0 %
|
||||
Factories/TestCaseFactory 111..133, 141..204 ................... 8.2 %
|
||||
Laravel/Commands/PestDatasetCommand ............................ 0.0 %
|
||||
Laravel/Commands/PestInstallCommand ............................ 0.0 %
|
||||
Laravel/Commands/PestTestCommand ............................... 0.0 %
|
||||
Laravel/PestServiceProvider .................................... 0.0 %
|
||||
PendingObjects/AfterEachCall ................................... 0.0 %
|
||||
PendingObjects/BeforeEachCall .................................. 0.0 %
|
||||
PendingObjects/TestCall ........................................ 0.0 %
|
||||
PendingObjects/UsesCall ........................................ 0.0 %
|
||||
Plugin ......................................................... 0.0 %
|
||||
Repositories/AfterAllRepository ................................ 0.0 %
|
||||
Repositories/AfterEachRepository 28..33 ....................... 60.0 %
|
||||
Repositories/BeforeAllRepository ............................... 0.0 %
|
||||
Repositories/BeforeEachRepository 26..31 ...................... 20.0 %
|
||||
Repositories/TestRepository .................................... 0.0 %
|
||||
Support/Backtrace .............................................. 0.0 %
|
||||
Support/ChainableClosure .................................... 100.0 %
|
||||
Support/Container .............................................. 0.0 %
|
||||
Support/ExceptionTrace 25..32 ................................. 28.6 %
|
||||
Support/HigherOrderMessage ..................................... 0.0 %
|
||||
Support/HigherOrderMessageCollection 24..25, 33, 43 ........... 50.0 %
|
||||
Support/HigherOrderTapProxy .................................... 0.0 %
|
||||
Support/NullClosure ......................................... 100.0 %
|
||||
Support/Reflection ............................................. 0.0 %
|
||||
Support/Str .................................................... 0.0 %
|
||||
TestSuite 80..87, 95..101, 105 ................................ 20.0 %
|
||||
globals ........................................................ 0.0 %
|
||||
@ -673,6 +673,8 @@
|
||||
✓ pass with toString
|
||||
✓ pass with dataset with ('my-datas-set-value')
|
||||
✓ within describe → pass with dataset with ('my-datas-set-value')
|
||||
✓ pass with toArray
|
||||
✓ pass with array
|
||||
✓ failures
|
||||
✓ failures with custom message
|
||||
✓ not failures
|
||||
@ -1079,7 +1081,7 @@
|
||||
✓ todo
|
||||
✓ todo in parallel
|
||||
|
||||
PASS Tests\Visual\Version
|
||||
✓ visual snapshot of help command output
|
||||
WARN Tests\Visual\Version
|
||||
- visual snapshot of help command output
|
||||
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 18 skipped, 741 passed (1784 assertions)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 742 passed (1787 assertions)
|
||||
@ -75,6 +75,34 @@ describe('within describe', function () {
|
||||
});
|
||||
})->with(['my-datas-set-value']);
|
||||
|
||||
test('pass with `toArray`', function () {
|
||||
TestSuite::getInstance()->snapshots->save($this, json_encode(['key' => $this->snapshotable], JSON_PRETTY_PRINT));
|
||||
|
||||
$object = new class($this->snapshotable)
|
||||
{
|
||||
public function __construct(protected string $snapshotable)
|
||||
{
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return [
|
||||
'key' => $this->snapshotable,
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
expect($object)->toMatchSnapshot()->toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('pass with array', function () {
|
||||
TestSuite::getInstance()->snapshots->save($this, json_encode(['key' => $this->snapshotable], JSON_PRETTY_PRINT));
|
||||
|
||||
expect([
|
||||
'key' => $this->snapshotable,
|
||||
])->toMatchSnapshot()->toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
TestSuite::getInstance()->snapshots->save($this, $this->snapshotable);
|
||||
|
||||
|
||||
@ -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, 730 passed (1769 assertions)')
|
||||
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 732 passed (1773 assertions)')
|
||||
->toContain('Parallel: 3 processes');
|
||||
})->skipOnWindows();
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
<?php
|
||||
|
||||
test('visual snapshot of help command output', function () {
|
||||
$snapshot = __DIR__.'/../.snapshots/version-command.txt';
|
||||
|
||||
$output = function () {
|
||||
$process = (new Symfony\Component\Process\Process(['php', 'bin/pest', '--version'], 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());
|
||||
};
|
||||
|
||||
if (getenv('REBUILD_SNAPSHOTS')) {
|
||||
file_put_contents($snapshot, $output());
|
||||
|
||||
$this->markTestSkipped('Snapshot rebuilt.');
|
||||
}
|
||||
|
||||
expect($output())->toContain(file_get_contents($snapshot));
|
||||
})->skipOnWindows();
|
||||
expect($output())->toMatchSnapshot();
|
||||
})->skipOnWindows()->skip(! getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE'));
|
||||
|
||||
Reference in New Issue
Block a user