Merge branch '2.x' into 3.x

This commit is contained in:
Nuno Maduro
2024-02-01 11:53:10 +00:00
73 changed files with 1169 additions and 788 deletions

View File

@ -361,3 +361,23 @@ it('can correctly resolve a bound dataset that returns an array but wants to be
]);
todo('forbids to define tests in Datasets dirs and Datasets.php files');
dataset('greeting-string', [
'formal' => 'Evening',
'informal' => 'yo',
]);
it('may be used with high order')
->with('greeting-string')
->expect(fn (string $greeting) => $greeting)
->throwsNoExceptions();
dataset('greeting-bound', [
'formal' => fn () => 'Evening',
'informal' => fn () => 'yo',
]);
it('may be used with high order even when bound')
->with('greeting-bound')
->expect(fn (string $greeting) => $greeting)
->throws(InvalidArgumentException::class);

View File

@ -16,6 +16,11 @@ test('passes with DateTime and DateTimeImmutable', function () {
expect($past)->not->toBeGreaterThan($now);
});
test('passes with strings', function () {
expect('b')->toBeGreaterThan('a');
expect('a')->not->toBeGreaterThan('a');
});
test('failures', function () {
expect(4)->toBeGreaterThan(4);
})->throws(ExpectationFailedException::class);

View File

@ -18,6 +18,11 @@ test('passes with DateTime and DateTimeImmutable', function () {
expect($past)->not->toBeGreaterThanOrEqual($now);
});
test('passes with strings', function () {
expect('b')->toBeGreaterThanOrEqual('a');
expect('a')->toBeGreaterThanOrEqual('a');
});
test('failures', function () {
expect(4)->toBeGreaterThanOrEqual(4.1);
})->throws(ExpectationFailedException::class);

View File

@ -0,0 +1,9 @@
<?php
test('enum is backed by int')
->expect('Tests\Fixtures\Arch\ToBeIntBackedEnum\HasIntBacking')
->toBeIntBackedEnum();
test('enum is not backed by int')
->expect('Tests\Fixtures\Arch\ToBeIntBackedEnum\HasStringBacking')
->not->toBeIntBackedEnum();

View File

@ -16,6 +16,11 @@ test('passes with DateTime and DateTimeImmutable', function () {
expect($now)->not->toBeLessThan($now);
});
test('passes with strings', function () {
expect('a')->toBeLessThan('b');
expect('a')->not->toBeLessThan('a');
});
test('failures', function () {
expect(4)->toBeLessThan(4);
})->throws(ExpectationFailedException::class);

View File

@ -18,6 +18,11 @@ test('passes with DateTime and DateTimeImmutable', function () {
expect($now)->not->toBeLessThanOrEqual($past);
});
test('passes with strings', function () {
expect('a')->toBeLessThanOrEqual('b');
expect('a')->toBeLessThanOrEqual('a');
});
test('failures', function () {
expect(4)->toBeLessThanOrEqual(3.9);
})->throws(ExpectationFailedException::class);

View File

@ -0,0 +1,9 @@
<?php
test('enum is backed by string')
->expect('Tests\Fixtures\Arch\ToBeStringBackedEnum\HasStringBacking')
->toBeStringBackedEnum();
test('enum is not backed by string')
->expect('Tests\Fixtures\Arch\ToBeStringBackedEnum\HasIntBacking')
->not->toBeStringBackedEnum();

View File

@ -0,0 +1,35 @@
<?php
use PHPUnit\Framework\ExpectationFailedException;
test('passes arrays', function () {
expect([1, 2, 42])->toContainEqual('42');
});
test('passes arrays with multiple needles', function () {
expect([1, 2, 42])->toContainEqual('42', '2');
});
test('failures', function () {
expect([1, 2, 42])->toContainEqual('3');
})->throws(ExpectationFailedException::class);
test('failures with multiple needles (all failing)', function () {
expect([1, 2, 42])->toContainEqual('3', '4');
})->throws(ExpectationFailedException::class);
test('failures with multiple needles (some failing)', function () {
expect([1, 2, 42])->toContainEqual('1', '3', '4');
})->throws(ExpectationFailedException::class);
test('not failures', function () {
expect([1, 2, 42])->not->toContainEqual('42');
})->throws(ExpectationFailedException::class);
test('not failures with multiple needles (all failing)', function () {
expect([1, 2, 42])->not->toContainEqual('42', '2');
})->throws(ExpectationFailedException::class);
test('not failures with multiple needles (some failing)', function () {
expect([1, 2, 42])->not->toContainEqual('42', '1');
})->throws(ExpectationFailedException::class);

View File

@ -21,6 +21,23 @@ test('pass', function () {
expect($this->snapshotable)->toMatchSnapshot();
});
expect()->pipe('toMatchSnapshot', function (Closure $next) {
if (is_string($this->value)) {
$this->value = preg_replace(
'/name="_token" value=".*"/',
'name="_token" value="1"',
$this->value
);
}
return $next();
});
test('pass using pipes', function () {
expect('<input type="hidden" name="_token" value="'.random_int(1, 999).'" />')
->toMatchSnapshot();
});
test('pass with `__toString`', function () {
TestSuite::getInstance()->snapshots->save($this->snapshotable);