mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Merge branch '2.x' into feature/traversable-sequence
This commit is contained in:
20
tests/Features/Expect/toBeAlpha.php
Normal file
20
tests/Features/Expect/toBeAlpha.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('abc')->toBeAlpha();
|
||||
expect('123')->not->toBeAlpha();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect('123')->toBeAlpha();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
expect('123')->toBeAlpha('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
expect('abc')->not->toBeAlpha();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
20
tests/Features/Expect/toBeAlphaNumeric.php
Normal file
20
tests/Features/Expect/toBeAlphaNumeric.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('abc123')->toBeAlphaNumeric();
|
||||
expect('-')->not->toBeAlphaNumeric();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect('-')->toBeAlphaNumeric();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
expect('-')->toBeAlphaNumeric('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
expect('abc123')->not->toBeAlphaNumeric();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
20
tests/Features/Expect/toBeDigits.php
Normal file
20
tests/Features/Expect/toBeDigits.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('123')->toBeDigits();
|
||||
expect('123.14')->not->toBeDigits();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect('123.14')->toBeDigits();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
expect('123.14')->toBeDigits('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
expect('445')->not->toBeDigits();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
20
tests/Features/Expect/toBeLowercase.php
Normal file
20
tests/Features/Expect/toBeLowercase.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('lowercase')->toBeLowercase();
|
||||
expect('UPPERCASE')->not->toBeLowercase();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect('UPPERCASE')->toBeLowercase();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
expect('UPPERCASE')->toBeLowercase('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
expect('lowercase')->not->toBeLowercase();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
20
tests/Features/Expect/toBeUppercase.php
Normal file
20
tests/Features/Expect/toBeUppercase.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('UPPERCASE')->toBeUppercase();
|
||||
expect('lowercase')->not->toBeUppercase();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect('lowercase')->toBeUppercase();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
expect('lowercase')->toBeUppercase('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
expect('UPPERCASE')->not->toBeUppercase();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
@ -16,13 +16,13 @@ beforeEach(function () {
|
||||
});
|
||||
|
||||
test('pass', function () {
|
||||
TestSuite::getInstance()->snapshots->save($this, $this->snapshotable);
|
||||
TestSuite::getInstance()->snapshots->save($this->snapshotable);
|
||||
|
||||
expect($this->snapshotable)->toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('pass with `__toString`', function () {
|
||||
TestSuite::getInstance()->snapshots->save($this, $this->snapshotable);
|
||||
TestSuite::getInstance()->snapshots->save($this->snapshotable);
|
||||
|
||||
$object = new class($this->snapshotable)
|
||||
{
|
||||
@ -36,11 +36,11 @@ test('pass with `__toString`', function () {
|
||||
}
|
||||
};
|
||||
|
||||
expect($object)->toMatchSnapshot()->toMatchSnapshot();
|
||||
expect($object)->toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('pass with `toString`', function () {
|
||||
TestSuite::getInstance()->snapshots->save($this, $this->snapshotable);
|
||||
TestSuite::getInstance()->snapshots->save($this->snapshotable);
|
||||
|
||||
$object = new class($this->snapshotable)
|
||||
{
|
||||
@ -54,12 +54,12 @@ test('pass with `toString`', function () {
|
||||
}
|
||||
};
|
||||
|
||||
expect($object)->toMatchSnapshot()->toMatchSnapshot();
|
||||
expect($object)->toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('pass with dataset', function ($data) {
|
||||
TestSuite::getInstance()->snapshots->save($this, $this->snapshotable);
|
||||
[$filename] = TestSuite::getInstance()->snapshots->get($this, $this->snapshotable);
|
||||
TestSuite::getInstance()->snapshots->save($this->snapshotable);
|
||||
[$filename] = TestSuite::getInstance()->snapshots->get();
|
||||
|
||||
expect($filename)->toEndWith('pass_with_dataset_with_data_set____my_datas_set_value______my_datas_set_value__.snap')
|
||||
->and($this->snapshotable)->toMatchSnapshot();
|
||||
@ -67,8 +67,8 @@ test('pass with dataset', function ($data) {
|
||||
|
||||
describe('within describe', function () {
|
||||
test('pass with dataset', function ($data) {
|
||||
TestSuite::getInstance()->snapshots->save($this, $this->snapshotable);
|
||||
[$filename] = TestSuite::getInstance()->snapshots->get($this, $this->snapshotable);
|
||||
TestSuite::getInstance()->snapshots->save($this->snapshotable);
|
||||
[$filename] = TestSuite::getInstance()->snapshots->get();
|
||||
|
||||
expect($filename)->toEndWith('pass_with_dataset_with_data_set____my_datas_set_value______my_datas_set_value__.snap')
|
||||
->and($this->snapshotable)->toMatchSnapshot();
|
||||
@ -76,7 +76,7 @@ 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));
|
||||
TestSuite::getInstance()->snapshots->save(json_encode(['key' => $this->snapshotable], JSON_PRETTY_PRINT));
|
||||
|
||||
$object = new class($this->snapshotable)
|
||||
{
|
||||
@ -92,31 +92,57 @@ test('pass with `toArray`', function () {
|
||||
}
|
||||
};
|
||||
|
||||
expect($object)->toMatchSnapshot()->toMatchSnapshot();
|
||||
expect($object)->toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('pass with array', function () {
|
||||
TestSuite::getInstance()->snapshots->save($this, json_encode(['key' => $this->snapshotable], JSON_PRETTY_PRINT));
|
||||
TestSuite::getInstance()->snapshots->save(json_encode(['key' => $this->snapshotable], JSON_PRETTY_PRINT));
|
||||
|
||||
expect([
|
||||
'key' => $this->snapshotable,
|
||||
])->toMatchSnapshot()->toMatchSnapshot();
|
||||
])->toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
TestSuite::getInstance()->snapshots->save($this, $this->snapshotable);
|
||||
TestSuite::getInstance()->snapshots->save($this->snapshotable);
|
||||
|
||||
expect('contain that does not match snapshot')->toMatchSnapshot();
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that two strings are identical.');
|
||||
|
||||
test('failures with custom message', function () {
|
||||
TestSuite::getInstance()->snapshots->save($this, $this->snapshotable);
|
||||
TestSuite::getInstance()->snapshots->save($this->snapshotable);
|
||||
|
||||
expect('contain that does not match snapshot')->toMatchSnapshot('oh no');
|
||||
})->throws(ExpectationFailedException::class, 'oh no');
|
||||
|
||||
test('not failures', function () {
|
||||
TestSuite::getInstance()->snapshots->save($this, $this->snapshotable);
|
||||
TestSuite::getInstance()->snapshots->save($this->snapshotable);
|
||||
|
||||
expect($this->snapshotable)->not->toMatchSnapshot();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('multiple snapshot expectations', function () {
|
||||
expect('foo bar 1')->toMatchSnapshot();
|
||||
|
||||
expect('foo bar 2')->toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('multiple snapshot expectations with datasets', function () {
|
||||
expect('foo bar 1')->toMatchSnapshot();
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user