mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| af6240b4ee | |||
| 78b328e970 | |||
| c92fa45ad7 | |||
| d050ef8d54 | |||
| 1c2f1facac | |||
| 8e695d62e9 | |||
| b9a301a13e | |||
| 4b9da9e3c1 | |||
| 239fceab9e | |||
| bedf033655 | |||
| 66f69617f1 | |||
| 5721e8c29a | |||
| 546d19fd84 | |||
| c1b32b9ffb | |||
| 298b1e6784 | |||
| 63f009fadf | |||
| 1066c2270d | |||
| 984f237a92 | |||
| dccd8239dd | |||
| e103623ecb | |||
| 542fc046d2 | |||
| 4720e0655b | |||
| a533772fe2 | |||
| 2218a0c137 | |||
| 2831629f1b | |||
| 1b7f1dc5b3 |
6
.github/workflows/tests.yml
vendored
6
.github/workflows/tests.yml
vendored
@ -8,7 +8,7 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
php: ['7.3', '7.4', '8.0', '8.1']
|
||||
php: ['7.3', '7.4', '8.0', '8.1', '8.2']
|
||||
dependency-version: [prefer-lowest, prefer-stable]
|
||||
parallel: ['', '--parallel']
|
||||
exclude:
|
||||
@ -16,6 +16,10 @@ jobs:
|
||||
os: macos-latest
|
||||
- php: 8.1
|
||||
os: windows-latest
|
||||
- php: 8.2
|
||||
os: macos-latest
|
||||
- php: 8.2
|
||||
os: windows-latest
|
||||
|
||||
name: PHP ${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }} - ${{ matrix.parallel }}
|
||||
|
||||
|
||||
16
CHANGELOG.md
16
CHANGELOG.md
@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [v1.22.1 (2022-08-29)](https://github.com/pestphp/pest/compare/v1.22.0...v1.22.1)
|
||||
### Fixed
|
||||
- Initial PHP 8.2 support ([d050ef8](https://github.com/pestphp/pest/commit/d050ef8d54ffe8dfe015adeb1188aae2cca33c33))
|
||||
|
||||
## [v1.22.0 (2022-08-28)](https://github.com/pestphp/pest/compare/v1.21.3...v1.22.0)
|
||||
### Added
|
||||
- Initial PHP 8.2 support ([#563](https://github.com/pestphp/pest/pull/563))
|
||||
|
||||
## [v1.21.3 (2022-05-12)](https://github.com/pestphp/pest/compare/v1.21.2...v1.21.3)
|
||||
### Fixed
|
||||
- Debug of high order tests ([c1b32b9](https://github.com/pestphp/pest/commit/c1b32b9ffb5134803c490592454b11b8c05ea27d))
|
||||
|
||||
## [v1.21.2 (2022-03-05)](https://github.com/pestphp/pest/compare/v1.21.1...v1.21.2)
|
||||
### Fixed
|
||||
- `toThrow` expectation when exception does not exist ([#487](https://github.com/pestphp/pest/pull/487))
|
||||
|
||||
## [v1.21.1 (2021-11-25)](https://github.com/pestphp/pest/compare/v1.21.0...v1.21.1)
|
||||
### Fixed
|
||||
- sequence callables causing problems ([#442](https://github.com/pestphp/pest/pull/442))
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
|
||||
When releasing a new version of Pest there are some checks and updates that need to be done:
|
||||
|
||||
- Clear your local repository with: `git add . && git reset --hard && git checkout master`
|
||||
- On the GitHub repository, check the contents of [github.com/pestphp/pest/compare/{latest_version}...master](https://github.com/pestphp/pest/compare/{latest_version}...master) and update the [changelog](CHANGELOG.md) file with the main changes for this release
|
||||
- Clear your local repository with: `git add . && git reset --hard && git checkout 1.x`
|
||||
- On the GitHub repository, check the contents of [github.com/pestphp/pest/compare/{latest_version}...1.x](https://github.com/pestphp/pest/compare/{latest_version}...1.x) and update the [changelog](CHANGELOG.md) file with the main changes for this release
|
||||
- Update the version number in [src/Pest.php](src/Pest.php)
|
||||
- Run the tests locally using: `composer test`
|
||||
- Commit the CHANGELOG and Pest file with the message: `git commit -m "release: vX.X.X"`
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.3 || ^8.0",
|
||||
"nunomaduro/collision": "^5.4.0|^6.0",
|
||||
"nunomaduro/collision": "^5.10.0|^6.0",
|
||||
"pestphp/pest-plugin": "^1.0.0",
|
||||
"phpunit/phpunit": "^9.5.5"
|
||||
},
|
||||
@ -50,14 +50,17 @@
|
||||
"prefer-stable": true,
|
||||
"config": {
|
||||
"sort-packages": true,
|
||||
"preferred-install": "dist"
|
||||
"preferred-install": "dist",
|
||||
"allow-plugins": {
|
||||
"pestphp/pest-plugin": true
|
||||
}
|
||||
},
|
||||
"bin": [
|
||||
"bin/pest"
|
||||
],
|
||||
"scripts": {
|
||||
"lint": "php-cs-fixer fix -v",
|
||||
"test:lint": "php-cs-fixer fix -v --dry-run",
|
||||
"lint": "PHP_CS_FIXER_IGNORE_ENV=true php-cs-fixer fix -v",
|
||||
"test:lint": "PHP_CS_FIXER_IGNORE_ENV=true php-cs-fixer fix -v --dry-run",
|
||||
"test:types": "phpstan analyse --ansi --memory-limit=-1",
|
||||
"test:unit": "php bin/pest --colors=always --exclude-group=integration",
|
||||
"test:parallel": "php bin/pest -p --colors=always --exclude-group=integration",
|
||||
@ -73,7 +76,7 @@
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.x-dev"
|
||||
"dev-1.x": "1.x-dev"
|
||||
},
|
||||
"pest": {
|
||||
"plugins": [
|
||||
|
||||
@ -140,11 +140,6 @@ parameters:
|
||||
count: 2
|
||||
path: src/Expectation.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$value of method Pest\\\\Expectation\\<TValue\\>\\:\\:and\\(\\) expects TValue, mixed given\\.$#"
|
||||
count: 2
|
||||
path: src/Expectation.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$haystack of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertContains\\(\\) expects iterable, mixed given\\.$#"
|
||||
count: 1
|
||||
|
||||
@ -5,7 +5,9 @@ declare(strict_types=1);
|
||||
namespace Pest\Actions;
|
||||
|
||||
use Pest\Support\Str;
|
||||
|
||||
use function Pest\testDirectory;
|
||||
|
||||
use PHPUnit\Util\FileLoader;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
@ -50,6 +52,7 @@ final class LoadStructure
|
||||
$directory = new RecursiveDirectoryIterator($filename);
|
||||
$iterator = new RecursiveIteratorIterator($directory);
|
||||
foreach ($iterator as $file) {
|
||||
/* @phpstan-ignore-next-line */
|
||||
$filename = $file->__toString();
|
||||
if (Str::endsWith($filename, '.php') && file_exists($filename)) {
|
||||
require_once $filename;
|
||||
|
||||
@ -6,6 +6,7 @@ namespace Pest;
|
||||
|
||||
use BadMethodCallException;
|
||||
use Closure;
|
||||
use Error;
|
||||
use InvalidArgumentException;
|
||||
use Pest\Concerns\Extendable;
|
||||
use Pest\Concerns\RetrievesValues;
|
||||
@ -722,7 +723,7 @@ final class Expectation
|
||||
try {
|
||||
Assert::assertTrue(Arr::has($array, $key));
|
||||
|
||||
/* @phpstan-ignore-next-line */
|
||||
/* @phpstan-ignore-next-line */
|
||||
} catch (ExpectationFailedException $exception) {
|
||||
throw new ExpectationFailedException("Failed asserting that an array has the key '$key'", $exception->getComparisonFailure());
|
||||
}
|
||||
@ -911,8 +912,12 @@ final class Expectation
|
||||
|
||||
try {
|
||||
($this->value)();
|
||||
} catch (Throwable $e) { // @phpstan-ignore-line
|
||||
} catch (Throwable $e) {
|
||||
if (!class_exists($exception)) {
|
||||
if ($e instanceof Error && (bool) preg_match("/Class [\"']{$exception}[\"'] not found/", $e->getMessage())) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
Assert::assertStringContainsString($exception, $e->getMessage());
|
||||
|
||||
return $this;
|
||||
|
||||
@ -216,6 +216,7 @@ final class TestCaseFactory
|
||||
eval("
|
||||
namespace $namespace;
|
||||
|
||||
#[\AllowDynamicProperties]
|
||||
final class $className extends $baseClass implements $hasPrintableTestCaseClassFQN {
|
||||
$traitsCode
|
||||
|
||||
|
||||
@ -8,7 +8,9 @@ use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
use Pest\Exceptions\InvalidConsoleArgument;
|
||||
|
||||
use function Pest\testDirectory;
|
||||
|
||||
use Pest\TestSuite;
|
||||
|
||||
/**
|
||||
|
||||
@ -8,7 +8,9 @@ use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Pest\Console\Thanks;
|
||||
use Pest\Exceptions\InvalidConsoleArgument;
|
||||
|
||||
use function Pest\testDirectory;
|
||||
|
||||
use Pest\TestSuite;
|
||||
|
||||
/**
|
||||
|
||||
@ -8,7 +8,9 @@ use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Pest\Exceptions\InvalidConsoleArgument;
|
||||
use Pest\Support\Str;
|
||||
|
||||
use function Pest\testDirectory;
|
||||
|
||||
use Pest\TestSuite;
|
||||
|
||||
/**
|
||||
|
||||
@ -13,11 +13,14 @@ declare(strict_types=1);
|
||||
namespace Pest\Logging;
|
||||
|
||||
use function class_exists;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMElement;
|
||||
use Exception;
|
||||
|
||||
use function get_class;
|
||||
use function method_exists;
|
||||
|
||||
use Pest\Concerns\Testable;
|
||||
use PHPUnit\Framework\AssertionFailedError;
|
||||
use PHPUnit\Framework\ExceptionWrapper;
|
||||
@ -32,9 +35,12 @@ use PHPUnit\Util\Printer;
|
||||
use PHPUnit\Util\Xml;
|
||||
use ReflectionClass;
|
||||
use ReflectionException;
|
||||
|
||||
use function sprintf;
|
||||
use function str_replace;
|
||||
|
||||
use Throwable;
|
||||
|
||||
use function trim;
|
||||
|
||||
/**
|
||||
@ -173,7 +179,6 @@ final class JUnit extends Printer implements TestListener
|
||||
$this->doAddSkipped();
|
||||
}
|
||||
|
||||
/** @phpstan-ignore-next-line */
|
||||
public function startTestSuite(TestSuite $suite): void
|
||||
{
|
||||
$testSuite = $this->document->createElement('testsuite');
|
||||
@ -212,7 +217,6 @@ final class JUnit extends Printer implements TestListener
|
||||
$this->testSuiteTimes[$this->testSuiteLevel] = 0;
|
||||
}
|
||||
|
||||
/** @phpstan-ignore-next-line */
|
||||
public function endTestSuite(TestSuite $suite): void
|
||||
{
|
||||
$this->testSuites[$this->testSuiteLevel]->setAttribute(
|
||||
|
||||
@ -5,10 +5,13 @@ declare(strict_types=1);
|
||||
namespace Pest\Logging;
|
||||
|
||||
use function getmypid;
|
||||
|
||||
use Pest\Concerns\Logging\WritesToConsole;
|
||||
use Pest\Concerns\Testable;
|
||||
use Pest\Support\ExceptionTrace;
|
||||
|
||||
use function Pest\version;
|
||||
|
||||
use PHPUnit\Framework\AssertionFailedError;
|
||||
use PHPUnit\Framework\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@ -16,9 +19,11 @@ use PHPUnit\Framework\TestResult;
|
||||
use PHPUnit\Framework\TestSuite;
|
||||
use PHPUnit\Framework\Warning;
|
||||
use PHPUnit\TextUI\DefaultResultPrinter;
|
||||
|
||||
use function round;
|
||||
use function str_replace;
|
||||
use function strlen;
|
||||
|
||||
use Throwable;
|
||||
|
||||
final class TeamCity extends DefaultResultPrinter
|
||||
@ -106,7 +111,6 @@ final class TeamCity extends DefaultResultPrinter
|
||||
- $result->riskyCount();
|
||||
}
|
||||
|
||||
/** @phpstan-ignore-next-line */
|
||||
public function startTestSuite(TestSuite $suite): void
|
||||
{
|
||||
$suiteName = $suite->getName();
|
||||
@ -164,7 +168,6 @@ final class TeamCity extends DefaultResultPrinter
|
||||
);
|
||||
}
|
||||
|
||||
/** @phpstan-ignore-next-line */
|
||||
public function endTestSuite(TestSuite $suite): void
|
||||
{
|
||||
$suiteName = $suite->getName();
|
||||
|
||||
@ -183,7 +183,7 @@ final class TestCall
|
||||
*/
|
||||
public function __get(string $name): self
|
||||
{
|
||||
return $this->addChain($name);
|
||||
return $this->addChain(Backtrace::file(), Backtrace::line(), $name);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -193,7 +193,7 @@ final class TestCall
|
||||
*/
|
||||
public function __call(string $name, array $arguments): self
|
||||
{
|
||||
return $this->addChain($name, $arguments);
|
||||
return $this->addChain(Backtrace::file(), Backtrace::line(), $name, $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -201,11 +201,11 @@ final class TestCall
|
||||
*
|
||||
* @param array<int, mixed>|null $arguments
|
||||
*/
|
||||
private function addChain(string $name, array $arguments = null): self
|
||||
private function addChain(string $file, int $line, string $name, array $arguments = null): self
|
||||
{
|
||||
$this->testCaseFactory
|
||||
->chains
|
||||
->add(Backtrace::file(), Backtrace::line(), $name, $arguments);
|
||||
->add($file, $line, $name, $arguments);
|
||||
|
||||
if ($this->descriptionLess) {
|
||||
$exporter = new Exporter();
|
||||
|
||||
@ -6,7 +6,7 @@ namespace Pest;
|
||||
|
||||
function version(): string
|
||||
{
|
||||
return '1.21.1';
|
||||
return '1.22.1';
|
||||
}
|
||||
|
||||
function testDirectory(string $file = ''): string
|
||||
|
||||
@ -5,7 +5,9 @@ declare(strict_types=1);
|
||||
namespace Pest\Plugins;
|
||||
|
||||
use Pest\Contracts\Plugins\HandlesArguments;
|
||||
|
||||
use function Pest\version;
|
||||
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
|
||||
@ -26,6 +26,7 @@ final class Backtrace
|
||||
$current = null;
|
||||
|
||||
foreach (debug_backtrace(self::BACKTRACE_OPTIONS) as $trace) {
|
||||
assert(array_key_exists(self::FILE, $trace));
|
||||
if (Str::endsWith($trace[self::FILE], (string) realpath('vendor/phpunit/phpunit/src/Util/FileLoader.php'))) {
|
||||
break;
|
||||
}
|
||||
@ -45,7 +46,11 @@ final class Backtrace
|
||||
*/
|
||||
public static function file(): string
|
||||
{
|
||||
return debug_backtrace(self::BACKTRACE_OPTIONS)[1][self::FILE];
|
||||
$trace = debug_backtrace(self::BACKTRACE_OPTIONS)[1];
|
||||
|
||||
assert(array_key_exists(self::FILE, $trace));
|
||||
|
||||
return $trace[self::FILE];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,7 +58,11 @@ final class Backtrace
|
||||
*/
|
||||
public static function dirname(): string
|
||||
{
|
||||
return dirname(debug_backtrace(self::BACKTRACE_OPTIONS)[1][self::FILE]);
|
||||
$trace = debug_backtrace(self::BACKTRACE_OPTIONS)[1];
|
||||
|
||||
assert(array_key_exists(self::FILE, $trace));
|
||||
|
||||
return dirname($trace[self::FILE]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,6 +70,10 @@ final class Backtrace
|
||||
*/
|
||||
public static function line(): int
|
||||
{
|
||||
return debug_backtrace(self::BACKTRACE_OPTIONS)[1]['line'];
|
||||
$trace = debug_backtrace(self::BACKTRACE_OPTIONS)[1];
|
||||
|
||||
assert(array_key_exists('line', $trace));
|
||||
|
||||
return $trace['line'];
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,6 +44,7 @@ final class ExceptionTrace
|
||||
*/
|
||||
public static function removePestReferences(Throwable $t): void
|
||||
{
|
||||
/* @phpstan-ignore-next-line */
|
||||
if (!property_exists($t, 'serializableTrace')) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -496,6 +496,8 @@
|
||||
✓ not failures
|
||||
✓ closure missing parameter
|
||||
✓ closure missing type-hint
|
||||
✓ it can handle a non-defined exception
|
||||
✓ it can handle a class not found Error
|
||||
|
||||
PASS Tests\Features\Expect\unless
|
||||
✓ it pass
|
||||
@ -720,5 +722,5 @@
|
||||
✓ it is a test
|
||||
✓ it uses correct parent class
|
||||
|
||||
Tests: 4 incompleted, 9 skipped, 478 passed
|
||||
Tests: 4 incompleted, 9 skipped, 480 passed
|
||||
|
||||
@ -8,7 +8,7 @@ use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
it('has plugin')->assertTrue(class_exists(CoveragePlugin::class));
|
||||
|
||||
it('adds coverage if --coverage exist', function () {
|
||||
$plugin = new CoveragePlugin(new ConsoleOutput());
|
||||
$plugin = new CoveragePlugin(new ConsoleOutput());
|
||||
$testSuite = TestSuite::getInstance();
|
||||
|
||||
expect($plugin->coverage)->toBeFalse();
|
||||
|
||||
@ -9,9 +9,15 @@ test('an exception is thrown if the the type is not iterable', function () {
|
||||
test('allows for sequences of checks to be run on iterable data', function () {
|
||||
expect([1, 2, 3])
|
||||
->sequence(
|
||||
function ($expectation) { $expectation->toBeInt()->toEqual(1); },
|
||||
function ($expectation) { $expectation->toBeInt()->toEqual(2); },
|
||||
function ($expectation) { $expectation->toBeInt()->toEqual(3); },
|
||||
function ($expectation) {
|
||||
$expectation->toBeInt()->toEqual(1);
|
||||
},
|
||||
function ($expectation) {
|
||||
$expectation->toBeInt()->toEqual(2);
|
||||
},
|
||||
function ($expectation) {
|
||||
$expectation->toBeInt()->toEqual(3);
|
||||
},
|
||||
);
|
||||
|
||||
expect(static::getCount())->toBe(6);
|
||||
@ -20,9 +26,15 @@ test('allows for sequences of checks to be run on iterable data', function () {
|
||||
test('loops back to the start if it runs out of sequence items', function () {
|
||||
expect([1, 2, 3, 1, 2, 3, 1, 2])
|
||||
->sequence(
|
||||
function ($expectation) { $expectation->toBeInt()->toEqual(1); },
|
||||
function ($expectation) { $expectation->toBeInt()->toEqual(2); },
|
||||
function ($expectation) { $expectation->toBeInt()->toEqual(3); },
|
||||
function ($expectation) {
|
||||
$expectation->toBeInt()->toEqual(1);
|
||||
},
|
||||
function ($expectation) {
|
||||
$expectation->toBeInt()->toEqual(2);
|
||||
},
|
||||
function ($expectation) {
|
||||
$expectation->toBeInt()->toEqual(3);
|
||||
},
|
||||
);
|
||||
|
||||
expect(static::getCount())->toBe(16);
|
||||
@ -31,17 +43,29 @@ test('loops back to the start if it runs out of sequence items', function () {
|
||||
test('fails if the number of iterable items is greater than the number of expectations', function () {
|
||||
expect([1, 2])
|
||||
->sequence(
|
||||
function ($expectation) { $expectation->toBeInt()->toEqual(1); },
|
||||
function ($expectation) { $expectation->toBeInt()->toEqual(2); },
|
||||
function ($expectation) { $expectation->toBeInt()->toEqual(3); },
|
||||
function ($expectation) {
|
||||
$expectation->toBeInt()->toEqual(1);
|
||||
},
|
||||
function ($expectation) {
|
||||
$expectation->toBeInt()->toEqual(2);
|
||||
},
|
||||
function ($expectation) {
|
||||
$expectation->toBeInt()->toEqual(3);
|
||||
},
|
||||
);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('it works with associative arrays', function () {
|
||||
expect(['foo' => 'bar', 'baz' => 'boom'])
|
||||
->sequence(
|
||||
function ($expectation, $key) { $expectation->toEqual('bar'); $key->toEqual('foo'); },
|
||||
function ($expectation, $key) { $expectation->toEqual('boom'); $key->toEqual('baz'); },
|
||||
function ($expectation, $key) {
|
||||
$expectation->toEqual('bar');
|
||||
$key->toEqual('foo');
|
||||
},
|
||||
function ($expectation, $key) {
|
||||
$expectation->toEqual('boom');
|
||||
$key->toEqual('baz');
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@ -54,7 +78,9 @@ test('it can be passed non-callable values', function () {
|
||||
test('it can be passed a mixture of value types', function () {
|
||||
expect(['foo', 'bar', 'baz'])->sequence(
|
||||
'foo',
|
||||
function ($expectation) { $expectation->toEqual('bar')->toBeString(); },
|
||||
function ($expectation) {
|
||||
$expectation->toEqual('bar')->toBeString();
|
||||
},
|
||||
'baz'
|
||||
);
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ use PHPUnit\Framework\ExpectationFailedException;
|
||||
expect(true)->toBeTrue()->and(false)->toBeFalse();
|
||||
|
||||
test('strict comparisons', function () {
|
||||
$nuno = new stdClass();
|
||||
$nuno = new stdClass();
|
||||
$dries = new stdClass();
|
||||
|
||||
expect($nuno)->toBe($nuno)->not->toBe($dries);
|
||||
|
||||
@ -3,24 +3,24 @@
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
$object = new stdClass();
|
||||
$object = new stdClass();
|
||||
$object->name = 'Jhon';
|
||||
$object->age = 21;
|
||||
$object->age = 21;
|
||||
|
||||
expect($object)->toHaveProperties(['name', 'age']);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
$object = new stdClass();
|
||||
$object = new stdClass();
|
||||
$object->name = 'Jhon';
|
||||
|
||||
expect($object)->toHaveProperties(['name', 'age']);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () {
|
||||
$object = new stdClass();
|
||||
$object = new stdClass();
|
||||
$object->name = 'Jhon';
|
||||
$object->age = 21;
|
||||
$object->age = 21;
|
||||
|
||||
expect($object)->not->toHaveProperties(['name', 'age']);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@ -58,3 +58,15 @@ test('closure missing parameter', function () {
|
||||
test('closure missing type-hint', function () {
|
||||
expect(function () {})->toThrow(function ($e) {});
|
||||
})->throws(InvalidArgumentException::class, 'The given closure\'s parameter must be type-hinted as the class string.');
|
||||
|
||||
it('can handle a non-defined exception', function () {
|
||||
expect(function () {
|
||||
throw new NonExistingException();
|
||||
})->toThrow(NonExistingException::class);
|
||||
})->throws(Error::class);
|
||||
|
||||
it('can handle a class not found Error', function () {
|
||||
expect(function () {
|
||||
throw new NonExistingException();
|
||||
})->toThrow(Error::class);
|
||||
});
|
||||
|
||||
@ -3,9 +3,9 @@
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->unlessObject = new stdClass();
|
||||
$this->unlessObject = new stdClass();
|
||||
$this->unlessObject->trueValue = true;
|
||||
$this->unlessObject->foo = 'foo';
|
||||
$this->unlessObject->foo = 'foo';
|
||||
});
|
||||
|
||||
it('pass', function () {
|
||||
|
||||
@ -3,9 +3,9 @@
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->whenObject = new stdClass();
|
||||
$this->whenObject = new stdClass();
|
||||
$this->whenObject->trueValue = true;
|
||||
$this->whenObject->foo = 'foo';
|
||||
$this->whenObject->foo = 'foo';
|
||||
});
|
||||
|
||||
it('pass', function () {
|
||||
|
||||
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Tests\CustomTestCase;
|
||||
|
||||
use function PHPUnit\Framework\assertTrue;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CustomTestCase extends TestCase
|
||||
|
||||
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Tests\CustomTestCase;
|
||||
|
||||
use function PHPUnit\Framework\assertTrue;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ExecutedTest extends TestCase
|
||||
|
||||
@ -23,7 +23,7 @@ test('default php unit tests', function () {
|
||||
});
|
||||
|
||||
it('removes warnings', function () {
|
||||
$testSuite = new TestSuite();
|
||||
$testSuite = new TestSuite();
|
||||
$warningTestCase = new WarningTestCase('No tests found in class "Pest\TestCase".');
|
||||
$testSuite->addTest($warningTestCase);
|
||||
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
<?php
|
||||
|
||||
use Pest\Plugins\Version;
|
||||
|
||||
use function Pest\version;
|
||||
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
|
||||
it('outputs the version when --version is used', function () {
|
||||
|
||||
@ -10,7 +10,7 @@ it('gets file name from closure', function () {
|
||||
});
|
||||
|
||||
it('gets property values', function () {
|
||||
$class = new class() {
|
||||
$class = new class() {
|
||||
private $foo = 'bar';
|
||||
};
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ use Pest\TestSuite;
|
||||
|
||||
it('does not allow to add the same test description twice', function () {
|
||||
$testSuite = new TestSuite(getcwd(), 'tests');
|
||||
$test = function () {};
|
||||
$test = function () {};
|
||||
$testSuite->tests->set(new TestCaseFactory(__FILE__, 'foo', $test));
|
||||
$testSuite->tests->set(new TestCaseFactory(__FILE__, 'foo', $test));
|
||||
})->throws(
|
||||
@ -18,7 +18,7 @@ it('does not allow to add the same test description twice', function () {
|
||||
|
||||
it('alerts users about tests with arguments but no input', function () {
|
||||
$testSuite = new TestSuite(getcwd(), 'tests');
|
||||
$test = function (int $arg) {};
|
||||
$test = function (int $arg) {};
|
||||
$testSuite->tests->set(new TestCaseFactory(__FILE__, 'foo', $test));
|
||||
})->throws(
|
||||
DatasetMissing::class,
|
||||
@ -27,7 +27,7 @@ it('alerts users about tests with arguments but no input', function () {
|
||||
|
||||
it('can return an array of all test suite filenames', function () {
|
||||
$testSuite = TestSuite::getInstance(getcwd(), 'tests');
|
||||
$test = function () {};
|
||||
$test = function () {};
|
||||
$testSuite->tests->set(new TestCaseFactory(__FILE__, 'foo', $test));
|
||||
$testSuite->tests->set(new TestCaseFactory(__FILE__, 'bar', $test));
|
||||
|
||||
@ -39,9 +39,9 @@ it('can return an array of all test suite filenames', function () {
|
||||
|
||||
it('can filter the test suite filenames to those with the only method', function () {
|
||||
$testSuite = new TestSuite(getcwd(), 'tests');
|
||||
$test = function () {};
|
||||
$test = function () {};
|
||||
|
||||
$testWithOnly = new TestCaseFactory(__FILE__, 'foo', $test);
|
||||
$testWithOnly = new TestCaseFactory(__FILE__, 'foo', $test);
|
||||
$testWithOnly->only = true;
|
||||
$testSuite->tests->set($testWithOnly);
|
||||
|
||||
@ -59,7 +59,7 @@ it('does not filter the test suite filenames to those with the only method when
|
||||
|
||||
$test = function () {};
|
||||
|
||||
$testWithOnly = new TestCaseFactory(__FILE__, 'foo', $test);
|
||||
$testWithOnly = new TestCaseFactory(__FILE__, 'foo', $test);
|
||||
$testWithOnly->only = true;
|
||||
$testSuite->tests->set($testWithOnly);
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ test('visual snapshot of help command output', function () {
|
||||
|
||||
if (getenv('REBUILD_SNAPSHOTS')) {
|
||||
$outputBuffer = new BufferedOutput();
|
||||
$plugin = new Help($outputBuffer);
|
||||
$plugin = new Help($outputBuffer);
|
||||
|
||||
$plugin();
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
test('visual snapshot of test suite on success', function () {
|
||||
$testsPath = dirname(__DIR__);
|
||||
$snapshot = implode(DIRECTORY_SEPARATOR, [
|
||||
$snapshot = implode(DIRECTORY_SEPARATOR, [
|
||||
$testsPath,
|
||||
'.snapshots',
|
||||
'success.txt',
|
||||
|
||||
Reference in New Issue
Block a user