mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cef5c36885 | |||
| a343ba4a29 | |||
| 21b30b22a7 | |||
| 449c4b6c5e | |||
| 6513ad6ced | |||
| 12421c846e | |||
| a312cecede | |||
| 4be97ed314 | |||
| 5101b9dce3 | |||
| 2ffafd445d | |||
| 6068ef6150 | |||
| 8c0b933fcd | |||
| 991e02649a | |||
| a8b785f69e | |||
| 56610d886d | |||
| be0d9e964b | |||
| 6bc9da3fe1 | |||
| 6f54462070 |
@ -18,15 +18,15 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.1.0",
|
"php": "^8.1.0",
|
||||||
"brianium/paratest": "^7.2.7",
|
"brianium/paratest": "^7.2.9",
|
||||||
"nunomaduro/collision": "^7.8.1",
|
"nunomaduro/collision": "^7.9.0|^8.0.0",
|
||||||
"nunomaduro/termwind": "^1.15.1",
|
"nunomaduro/termwind": "^1.15.1|^2.0.0",
|
||||||
"pestphp/pest-plugin": "^2.1.1",
|
"pestphp/pest-plugin": "^2.1.1",
|
||||||
"pestphp/pest-plugin-arch": "^2.3.3",
|
"pestphp/pest-plugin-arch": "^2.4.0",
|
||||||
"phpunit/phpunit": "^10.3.5"
|
"phpunit/phpunit": "^10.4.1"
|
||||||
},
|
},
|
||||||
"conflict": {
|
"conflict": {
|
||||||
"phpunit/phpunit": ">10.3.5",
|
"phpunit/phpunit": ">10.4.1",
|
||||||
"sebastian/exporter": "<5.1.0",
|
"sebastian/exporter": "<5.1.0",
|
||||||
"webmozart/assert": "<1.11.0"
|
"webmozart/assert": "<1.11.0"
|
||||||
},
|
},
|
||||||
@ -52,7 +52,7 @@
|
|||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"pestphp/pest-dev-tools": "^2.16.0",
|
"pestphp/pest-dev-tools": "^2.16.0",
|
||||||
"pestphp/pest-plugin-type-coverage": "^2.2.0",
|
"pestphp/pest-plugin-type-coverage": "^2.4.0",
|
||||||
"symfony/process": "^6.3.4"
|
"symfony/process": "^6.3.4"
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
|
|||||||
@ -967,6 +967,7 @@ final class Expectation
|
|||||||
}
|
}
|
||||||
|
|
||||||
Assert::assertInstanceOf($exception, $e, $message);
|
Assert::assertInstanceOf($exception, $e, $message);
|
||||||
|
|
||||||
$callback($e);
|
$callback($e);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -1128,4 +1129,33 @@ final class Expectation
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the value is between 2 specified values
|
||||||
|
*
|
||||||
|
* @return self<TValue>
|
||||||
|
*/
|
||||||
|
public function toBeBetween(int|float|DateTimeInterface $lowestValue, int|float|DateTimeInterface $highestValue, string $message = ''): self
|
||||||
|
{
|
||||||
|
Assert::assertGreaterThanOrEqual($lowestValue, $this->value, $message);
|
||||||
|
Assert::assertLessThanOrEqual($highestValue, $this->value, $message);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the value is a url
|
||||||
|
*
|
||||||
|
* @return self<TValue>
|
||||||
|
*/
|
||||||
|
public function toBeUrl(string $message = ''): self
|
||||||
|
{
|
||||||
|
if ($message === '') {
|
||||||
|
$message = "Failed asserting that {$this->value} is a url.";
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert::assertTrue(Str::isUrl((string) $this->value), $message);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ namespace Pest;
|
|||||||
|
|
||||||
function version(): string
|
function version(): string
|
||||||
{
|
{
|
||||||
return '2.19.1';
|
return '2.23.1';
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDirectory(string $file = ''): string
|
function testDirectory(string $file = ''): string
|
||||||
|
|||||||
@ -254,11 +254,11 @@ final class WrapperRunner implements RunnerInterface
|
|||||||
|
|
||||||
private function destroyWorker(int $token): void
|
private function destroyWorker(int $token): void
|
||||||
{
|
{
|
||||||
// Mutation Testing tells us that the following `unset()` already destroys
|
|
||||||
// the `WrapperWorker`, which destroys the Symfony's `Process`, which
|
|
||||||
// automatically calls `Process::stop` within `Process::__destruct()`.
|
|
||||||
// But we prefer to have an explicit stops.
|
|
||||||
$this->workers[$token]->stop();
|
$this->workers[$token]->stop();
|
||||||
|
// We need to wait for ApplicationForWrapperWorker::end to end
|
||||||
|
while ($this->workers[$token]->isRunning()) {
|
||||||
|
usleep(self::CYCLE_SLEEP);
|
||||||
|
}
|
||||||
|
|
||||||
unset($this->workers[$token]);
|
unset($this->workers[$token]);
|
||||||
}
|
}
|
||||||
@ -297,6 +297,7 @@ final class WrapperRunner implements RunnerInterface
|
|||||||
array_merge_recursive($testResultSum->phpDeprecations(), $testResult->phpDeprecations()),
|
array_merge_recursive($testResultSum->phpDeprecations(), $testResult->phpDeprecations()),
|
||||||
array_merge_recursive($testResultSum->phpNotices(), $testResult->phpNotices()),
|
array_merge_recursive($testResultSum->phpNotices(), $testResult->phpNotices()),
|
||||||
array_merge_recursive($testResultSum->phpWarnings(), $testResult->phpWarnings()),
|
array_merge_recursive($testResultSum->phpWarnings(), $testResult->phpWarnings()),
|
||||||
|
$testResultSum->numberOfIssuesIgnoredByBaseline() + $testResult->numberOfIssuesIgnoredByBaseline(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,6 +326,8 @@ final class WrapperRunner implements RunnerInterface
|
|||||||
$testResultSum->phpDeprecations(),
|
$testResultSum->phpDeprecations(),
|
||||||
$testResultSum->phpNotices(),
|
$testResultSum->phpNotices(),
|
||||||
$testResultSum->phpWarnings(),
|
$testResultSum->phpWarnings(),
|
||||||
|
$testResultSum->numberOfIssuesIgnoredByBaseline(),
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->printer->printResults(
|
$this->printer->printResults(
|
||||||
|
|||||||
@ -108,4 +108,12 @@ final class Str
|
|||||||
{
|
{
|
||||||
return sprintf('`%s` → %s', $describeDescription, $testDescription);
|
return sprintf('`%s` → %s', $describeDescription, $testDescription);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a given value is a valid URL.
|
||||||
|
*/
|
||||||
|
public static function isUrl(string $value): bool
|
||||||
|
{
|
||||||
|
return (bool) filter_var($value, FILTER_VALIDATE_URL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
Pest Testing Framework 2.19.1.
|
Pest Testing Framework 2.23.1.
|
||||||
|
|
||||||
USAGE: pest <file> [options]
|
USAGE: pest <file> [options]
|
||||||
|
|
||||||
@ -14,6 +14,9 @@
|
|||||||
--cache-directory [dir] ............................ Specify cache directory
|
--cache-directory [dir] ............................ Specify cache directory
|
||||||
--generate-configuration Generate configuration file with suggested settings
|
--generate-configuration Generate configuration file with suggested settings
|
||||||
--migrate-configuration ....... Migrate configuration file to current format
|
--migrate-configuration ....... Migrate configuration file to current format
|
||||||
|
--generate-baseline [file] .................... Generate baseline for issues
|
||||||
|
--use-baseline [file] ........................ Use baseline to ignore issues
|
||||||
|
--ignore-baseline ..................... Do not use baseline to ignore issues
|
||||||
|
|
||||||
SELECTION OPTIONS:
|
SELECTION OPTIONS:
|
||||||
--bail ........................... Stop execution upon first not-passed test
|
--bail ........................... Stop execution upon first not-passed test
|
||||||
@ -89,7 +92,7 @@
|
|||||||
--testdox-html [file] .. Write test results in TestDox format (HTML) to file
|
--testdox-html [file] .. Write test results in TestDox format (HTML) to file
|
||||||
--testdox-text [file] Write test results in TestDox format (plain text) to file
|
--testdox-text [file] Write test results in TestDox format (plain text) to file
|
||||||
--log-events-text [file] ............... Stream events as plain text to file
|
--log-events-text [file] ............... Stream events as plain text to file
|
||||||
--log-events-verbose-text [file] Stream events as plain text (with telemetry information) to file
|
--log-events-verbose-text [file] Stream events as plain text with extended information to file
|
||||||
--no-logging ....... Ignore logging configured in the XML configuration file
|
--no-logging ....... Ignore logging configured in the XML configuration file
|
||||||
|
|
||||||
CODE COVERAGE OPTIONS:
|
CODE COVERAGE OPTIONS:
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
|
|
||||||
Pest Testing Framework 2.19.1.
|
Pest Testing Framework 2.23.1.
|
||||||
|
|
||||||
|
|||||||
@ -332,6 +332,18 @@
|
|||||||
✓ pass
|
✓ pass
|
||||||
✓ failures
|
✓ failures
|
||||||
✓ failures with custom message
|
✓ failures with custom message
|
||||||
|
✓ not failures
|
||||||
|
|
||||||
|
PASS Tests\Features\Expect\toBeBetween
|
||||||
|
✓ passes with int
|
||||||
|
✓ passes with float
|
||||||
|
✓ passes with float and int
|
||||||
|
✓ passes with DateTime
|
||||||
|
✓ failure with int
|
||||||
|
✓ failure with float
|
||||||
|
✓ failure with float and int
|
||||||
|
✓ failure with DateTime
|
||||||
|
✓ failures with custom message
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|
||||||
PASS Tests\Features\Expect\toBeBool
|
PASS Tests\Features\Expect\toBeBool
|
||||||
@ -578,6 +590,13 @@
|
|||||||
✓ pass
|
✓ pass
|
||||||
✓ failures
|
✓ failures
|
||||||
✓ failures with custom message
|
✓ failures with custom message
|
||||||
|
✓ not failures
|
||||||
|
|
||||||
|
PASS Tests\Features\Expect\toBeUrl
|
||||||
|
✓ pass
|
||||||
|
✓ failures
|
||||||
|
✓ failures with custom message
|
||||||
|
✓ failures with default message
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|
||||||
PASS Tests\Features\Expect\toBeUuid
|
PASS Tests\Features\Expect\toBeUuid
|
||||||
@ -1333,4 +1352,4 @@
|
|||||||
WARN Tests\Visual\Version
|
WARN Tests\Visual\Version
|
||||||
- visual snapshot of help command output
|
- visual snapshot of help command output
|
||||||
|
|
||||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 943 passed (2224 assertions)
|
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 958 passed (2281 assertions)
|
||||||
43
tests/Features/Expect/toBeBetween.php
Normal file
43
tests/Features/Expect/toBeBetween.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
|
test('passes with int', function () {
|
||||||
|
expect(2)->toBeBetween(1, 3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('passes with float', function () {
|
||||||
|
expect(1.5)->toBeBetween(1.25, 1.75);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('passes with float and int', function () {
|
||||||
|
expect(1.5)->toBeBetween(1, 2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('passes with DateTime', function () {
|
||||||
|
expect(new DateTime('2023-09-22'))->toBeBetween(new DateTime('2023-09-21'), new DateTime('2023-09-23'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('failure with int', function () {
|
||||||
|
expect(4)->toBeBetween(1, 3);
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|
||||||
|
test('failure with float', function () {
|
||||||
|
expect(2)->toBeBetween(1.5, 1.75);
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|
||||||
|
test('failure with float and int', function () {
|
||||||
|
expect(2.1)->toBeBetween(1, 2);
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|
||||||
|
test('failure with DateTime', function () {
|
||||||
|
expect(new DateTime('2023-09-20'))->toBeBetween(new DateTime('2023-09-21'), new DateTime('2023-09-23'));
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|
||||||
|
test('failures with custom message', function () {
|
||||||
|
expect(4)->toBeBetween(1, 3, 'oh no!');
|
||||||
|
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||||
|
|
||||||
|
test('not failures', function () {
|
||||||
|
expect(2)->not->toBeBetween(1, 3);
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
24
tests/Features/Expect/toBeUrl.php
Normal file
24
tests/Features/Expect/toBeUrl.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
|
test('pass', function () {
|
||||||
|
expect('https://pestphp.com')->toBeUrl()
|
||||||
|
->and('pestphp.com')->not->toBeUrl();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('failures', function () {
|
||||||
|
expect('pestphp.com')->toBeUrl();
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|
||||||
|
test('failures with custom message', function () {
|
||||||
|
expect('pestphp.com')->toBeUrl('oh no!');
|
||||||
|
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||||
|
|
||||||
|
test('failures with default message', function () {
|
||||||
|
expect('pestphp.com')->toBeUrl();
|
||||||
|
})->throws(ExpectationFailedException::class, 'Failed asserting that pestphp.com is a url.');
|
||||||
|
|
||||||
|
test('not failures', function () {
|
||||||
|
expect('https://pestphp.com')->not->toBeUrl();
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
@ -57,8 +57,9 @@ test('failures 3', function () {
|
|||||||
expect(function () {
|
expect(function () {
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
})->toThrow(function (RuntimeException $e) {
|
})->toThrow(function (RuntimeException $e) {
|
||||||
|
//
|
||||||
});
|
});
|
||||||
})->throws(ExpectationFailedException::class, 'Failed asserting that Exception Object');
|
})->throws(ExpectationFailedException::class, 'Failed asserting that an object is an instance of class RuntimeException.');
|
||||||
|
|
||||||
test('failures 4', function () {
|
test('failures 4', function () {
|
||||||
expect(function () {
|
expect(function () {
|
||||||
@ -73,7 +74,7 @@ test('failures 5', function () {
|
|||||||
expect(function () {
|
expect(function () {
|
||||||
throw new Exception('actual message');
|
throw new Exception('actual message');
|
||||||
})->toThrow('expected message');
|
})->toThrow('expected message');
|
||||||
})->throws(ExpectationFailedException::class, 'Failed asserting that \'actual message\' contains "expected message".');
|
})->throws(ExpectationFailedException::class, 'Failed asserting that \'actual message\' [ASCII](length: 14) contains "expected message" [ASCII](length: 16).');
|
||||||
|
|
||||||
test('failures 6', function () {
|
test('failures 6', function () {
|
||||||
expect(function () {
|
expect(function () {
|
||||||
|
|||||||
@ -16,7 +16,7 @@ $run = function () {
|
|||||||
|
|
||||||
test('parallel', function () use ($run) {
|
test('parallel', function () use ($run) {
|
||||||
expect($run('--exclude-group=integration'))
|
expect($run('--exclude-group=integration'))
|
||||||
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 932 passed (2209 assertions)')
|
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 947 passed (2266 assertions)')
|
||||||
->toContain('Parallel: 3 processes');
|
->toContain('Parallel: 3 processes');
|
||||||
})->skipOnWindows();
|
})->skipOnWindows();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user