mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 00:07:22 +01:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| be7fe41179 | |||
| 204f343831 | |||
| aa230a1716 | |||
| 97f98569bc | |||
| 1318bf9830 | |||
| 3b58f946f1 | |||
| dfc2470764 | |||
| f650978dd0 | |||
| c6ba469e68 | |||
| 3a9997f9af | |||
| fb6cb891be | |||
| 76beda74c9 | |||
| bcc206d183 | |||
| 1e7b6a0396 | |||
| cc1abe7f06 | |||
| 0c16942d37 | |||
| fa413aafbb | |||
| 75f17bb118 |
12
CHANGELOG.md
12
CHANGELOG.md
@ -6,6 +6,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [v0.3.2 (2020-09-13)](https://github.com/pestphp/pest/compare/v0.3.2...v0.3.3)
|
||||||
|
### Added
|
||||||
|
- `toHaveKeys` expectation ([204f343](https://github.com/pestphp/pest/commit/204f343831adc17bb3734553c24fac92d02f27c7))
|
||||||
|
|
||||||
|
## [v0.3.2 (2020-09-12)](https://github.com/pestphp/pest/compare/v0.3.1...v0.3.2)
|
||||||
|
### Added
|
||||||
|
- Support to PHPUnit 9.3.9, and 9.3.10 ([1318bf9](https://github.com/pestphp/pest/commit/97f98569bc86e8b87f8cde963fe7b4bf5399623b))
|
||||||
|
|
||||||
|
## [v0.3.1 (2020-08-29)](https://github.com/pestphp/pest/compare/v0.3.0...v0.3.1)
|
||||||
|
### Added
|
||||||
|
- Support to PHPUnit 9.3.8 ([#174](https://github.com/pestphp/pest/pull/174))
|
||||||
|
|
||||||
## [v0.3.0 (2020-08-27)](https://github.com/pestphp/pest/compare/v0.2.3...v0.3.0)
|
## [v0.3.0 (2020-08-27)](https://github.com/pestphp/pest/compare/v0.2.3...v0.3.0)
|
||||||
### Added
|
### Added
|
||||||
- Expectation API (TODO)
|
- Expectation API (TODO)
|
||||||
|
|||||||
10
README.md
10
README.md
@ -1,7 +1,7 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://raw.githubusercontent.com/pestphp/art/master/readme.png" width="600" alt="PEST">
|
<img src="https://raw.githubusercontent.com/pestphp/art/master/readme.png" width="600" alt="PEST">
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://github.com/pestphp/pest/actions"><img alt="GitHub Workflow Status (master)" src="https://img.shields.io/github/workflow/status/pestphp/pest/Continuous Integration/master"></a>
|
<a href="https://github.com/pestphp/pest/actions"><img alt="GitHub Workflow Status (master)" src="https://img.shields.io/github/workflow/status/pestphp/pest/Tests/master"></a>
|
||||||
<a href="https://packagist.org/packages/pestphp/pest"><img alt="Total Downloads" src="https://img.shields.io/packagist/dt/pestphp/pest"></a>
|
<a href="https://packagist.org/packages/pestphp/pest"><img alt="Total Downloads" src="https://img.shields.io/packagist/dt/pestphp/pest"></a>
|
||||||
<a href="https://packagist.org/packages/pestphp/pest"><img alt="Latest Version" src="https://img.shields.io/packagist/v/pestphp/pest"></a>
|
<a href="https://packagist.org/packages/pestphp/pest"><img alt="Latest Version" src="https://img.shields.io/packagist/v/pestphp/pest"></a>
|
||||||
<a href="https://packagist.org/packages/pestphp/pest"><img alt="License" src="https://img.shields.io/packagist/l/pestphp/pest"></a>
|
<a href="https://packagist.org/packages/pestphp/pest"><img alt="License" src="https://img.shields.io/packagist/l/pestphp/pest"></a>
|
||||||
@ -15,4 +15,12 @@
|
|||||||
- Follow us on Twitter: **[@pestphp »](https://twitter.com/pestphp)**
|
- Follow us on Twitter: **[@pestphp »](https://twitter.com/pestphp)**
|
||||||
- Join us on the Discord Server: **[discord.gg/bMAJv82 »](https://discord.gg/bMAJv82)**
|
- Join us on the Discord Server: **[discord.gg/bMAJv82 »](https://discord.gg/bMAJv82)**
|
||||||
|
|
||||||
|
## Pest Sponsors
|
||||||
|
|
||||||
|
We would like to extend our thanks to the following sponsors for funding Pest development. If you are interested in becoming a sponsor, please visit the Nuno Maduro's [Sponsors page](https://github.com/sponsors/nunomaduro).
|
||||||
|
|
||||||
|
### Premium Sponsors
|
||||||
|
|
||||||
|
- **[Scout APM](https://github.com/scoutapp)**
|
||||||
|
|
||||||
Pest was created by **[Nuno Maduro](https://twitter.com/enunomaduro)** under the **[Sponsorware license](https://github.com/sponsorware/docs)**. It got open-sourced and is now licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.
|
Pest was created by **[Nuno Maduro](https://twitter.com/enunomaduro)** under the **[Sponsorware license](https://github.com/sponsorware/docs)**. It got open-sourced and is now licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
"pestphp/pest-plugin": "^0.3",
|
"pestphp/pest-plugin": "^0.3",
|
||||||
"pestphp/pest-plugin-coverage": "^0.3",
|
"pestphp/pest-plugin-coverage": "^0.3",
|
||||||
"pestphp/pest-plugin-init": "^0.3",
|
"pestphp/pest-plugin-init": "^0.3",
|
||||||
"phpunit/phpunit": "9.3.7"
|
"phpunit/phpunit": "9.3.7 || 9.3.8 || 9.3.9 || 9.3.10"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|||||||
@ -22,3 +22,12 @@ parameters:
|
|||||||
- "#has parameter \\$closure with default value.#"
|
- "#has parameter \\$closure with default value.#"
|
||||||
- "#has parameter \\$description with default value.#"
|
- "#has parameter \\$description with default value.#"
|
||||||
- "#Method Pest\\\\Support\\\\Reflection::getParameterClassName\\(\\) has a nullable return type declaration.#"
|
- "#Method Pest\\\\Support\\\\Reflection::getParameterClassName\\(\\) has a nullable return type declaration.#"
|
||||||
|
-
|
||||||
|
message: '#Call to an undefined method PHPUnit\\Framework\\Test::getName\(\)#'
|
||||||
|
path: src/TeamCity.php
|
||||||
|
-
|
||||||
|
message: '#invalid typehint type Pest\\Concerns\\TestCase#'
|
||||||
|
path: src/TeamCity.php
|
||||||
|
-
|
||||||
|
message: '#is not subtype of native type PHPUnit\\Framework\\Test#'
|
||||||
|
path: src/TeamCity.php
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use Rector\Core\Configuration\Option;
|
use Rector\Core\Configuration\Option;
|
||||||
|
use Rector\Php70\Rector\StaticCall\StaticCallOnNonStaticToInstanceCallRector;
|
||||||
use Rector\Set\ValueObject\SetList;
|
use Rector\Set\ValueObject\SetList;
|
||||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||||
|
|
||||||
@ -27,5 +28,8 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||||||
SetList::SOLID,
|
SetList::SOLID,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$parameters->set(Option::PATHS, [__DIR__.'/src', __DIR__.'/tests']);
|
$parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/tests']);
|
||||||
|
$parameters->set(Option::EXCLUDE_RECTORS, [
|
||||||
|
StaticCallOnNonStaticToInstanceCallRector::class,
|
||||||
|
]);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -5,12 +5,16 @@ declare(strict_types=1);
|
|||||||
namespace Pest\Actions;
|
namespace Pest\Actions;
|
||||||
|
|
||||||
use NunoMaduro\Collision\Adapters\Phpunit\Printer;
|
use NunoMaduro\Collision\Adapters\Phpunit\Printer;
|
||||||
|
use Pest\TeamCity;
|
||||||
|
use PHPUnit\TextUI\DefaultResultPrinter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
final class AddsDefaults
|
final class AddsDefaults
|
||||||
{
|
{
|
||||||
|
private const PRINTER = 'printer';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds default arguments to the given `arguments` array.
|
* Adds default arguments to the given `arguments` array.
|
||||||
*
|
*
|
||||||
@ -20,8 +24,12 @@ final class AddsDefaults
|
|||||||
*/
|
*/
|
||||||
public static function to(array $arguments): array
|
public static function to(array $arguments): array
|
||||||
{
|
{
|
||||||
if (!array_key_exists('printer', $arguments)) {
|
if (!array_key_exists(self::PRINTER, $arguments)) {
|
||||||
$arguments['printer'] = new Printer(null, $arguments['verbose'] ?? false, $arguments['colors'] ?? 'always');
|
$arguments[self::PRINTER] = new Printer(null, $arguments['verbose'] ?? false, $arguments['colors'] ?? DefaultResultPrinter::COLOR_ALWAYS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($arguments[self::PRINTER] === \PHPUnit\Util\Log\TeamCity::class) {
|
||||||
|
$arguments[self::PRINTER] = new TeamCity($arguments['verbose'] ?? false, $arguments['colors'] ?? DefaultResultPrinter::COLOR_ALWAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $arguments;
|
return $arguments;
|
||||||
|
|||||||
@ -65,6 +65,11 @@ trait TestCase
|
|||||||
return $this->__description;
|
return $this->__description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function __getFileName(): string
|
||||||
|
{
|
||||||
|
return self::$__filename;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called before the first test of this test class is run.
|
* This method is called before the first test of this test class is run.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -376,14 +376,30 @@ final class Expectation
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that the value array has the provided $key.
|
* Asserts that the value array has the provided $key.
|
||||||
|
*
|
||||||
|
* @param string|int $key
|
||||||
*/
|
*/
|
||||||
public function toHaveKey(string $key): Expectation
|
public function toHaveKey($key): Expectation
|
||||||
{
|
{
|
||||||
Assert::assertArrayHasKey($key, $this->value);
|
Assert::assertArrayHasKey($key, $this->value);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the value array has the provided $keys.
|
||||||
|
*
|
||||||
|
* @param array<int, int|string> $keys
|
||||||
|
*/
|
||||||
|
public function toHaveKeys(array $keys): Expectation
|
||||||
|
{
|
||||||
|
foreach ($keys as $key) {
|
||||||
|
$this->toHaveKey($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that the value is a directory.
|
* Asserts that the value is a directory.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -27,6 +27,26 @@ final class OppositeExpectation
|
|||||||
$this->original = $original;
|
$this->original = $original;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the value array not has the provided $keys.
|
||||||
|
*
|
||||||
|
* @param array<int, int|string> $keys
|
||||||
|
*/
|
||||||
|
public function toHaveKeys(array $keys): Expectation
|
||||||
|
{
|
||||||
|
foreach ($keys as $key) {
|
||||||
|
try {
|
||||||
|
$this->original->toHaveKey($key);
|
||||||
|
} catch (ExpectationFailedException $e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->throwExpectationFailedExpection('toHaveKey', [$key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->original;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle dynamic method calls into the original expectation.
|
* Handle dynamic method calls into the original expectation.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -6,5 +6,5 @@ namespace Pest;
|
|||||||
|
|
||||||
function version(): string
|
function version(): string
|
||||||
{
|
{
|
||||||
return '0.3.0';
|
return '0.3.1';
|
||||||
}
|
}
|
||||||
|
|||||||
235
src/TeamCity.php
Normal file
235
src/TeamCity.php
Normal file
@ -0,0 +1,235 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Pest;
|
||||||
|
|
||||||
|
use function getmypid;
|
||||||
|
use Pest\Concerns\TestCase;
|
||||||
|
use PHPUnit\Framework\AssertionFailedError;
|
||||||
|
use PHPUnit\Framework\Test;
|
||||||
|
use PHPUnit\Framework\TestResult;
|
||||||
|
use PHPUnit\Framework\TestSuite;
|
||||||
|
use PHPUnit\Framework\Warning;
|
||||||
|
use PHPUnit\TextUI\DefaultResultPrinter;
|
||||||
|
use function round;
|
||||||
|
use function str_replace;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
final class TeamCity extends DefaultResultPrinter
|
||||||
|
{
|
||||||
|
private const PROTOCOL = 'pest_qn://';
|
||||||
|
private const NAME = 'name';
|
||||||
|
private const LOCATION_HINT = 'locationHint';
|
||||||
|
private const DURATION = 'duration';
|
||||||
|
private const TEST_SUITE_STARTED = 'testSuiteStarted';
|
||||||
|
private const TEST_SUITE_FINISHED = 'testSuiteFinished';
|
||||||
|
private const TEST_FAILED = 'testFailed';
|
||||||
|
|
||||||
|
/** @var int */
|
||||||
|
private $flowId;
|
||||||
|
|
||||||
|
/** @var bool */
|
||||||
|
private $isSummaryTestCountPrinted = false;
|
||||||
|
|
||||||
|
/** @var \PHPUnit\Util\Log\TeamCity */
|
||||||
|
private $phpunitTeamCity;
|
||||||
|
|
||||||
|
public function __construct(bool $verbose, string $colors)
|
||||||
|
{
|
||||||
|
parent::__construct(null, $verbose, $colors, false, 80, false);
|
||||||
|
$this->phpunitTeamCity = new \PHPUnit\Util\Log\TeamCity(
|
||||||
|
null,
|
||||||
|
$verbose,
|
||||||
|
$colors,
|
||||||
|
false,
|
||||||
|
80,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function printResult(TestResult $result): void
|
||||||
|
{
|
||||||
|
$this->printHeader($result);
|
||||||
|
$this->printFooter($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @phpstan-ignore-next-line */
|
||||||
|
public function startTestSuite(TestSuite $suite): void
|
||||||
|
{
|
||||||
|
$this->flowId = getmypid();
|
||||||
|
|
||||||
|
if (!$this->isSummaryTestCountPrinted) {
|
||||||
|
$this->printEvent(
|
||||||
|
'testCount',
|
||||||
|
['count' => $suite->count()]
|
||||||
|
);
|
||||||
|
$this->isSummaryTestCountPrinted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$suiteName = $suite->getName();
|
||||||
|
|
||||||
|
if (file_exists($suiteName) || !method_exists($suiteName, '__getFileName')) {
|
||||||
|
$this->printEvent(
|
||||||
|
self::TEST_SUITE_STARTED, [
|
||||||
|
self::NAME => $suiteName,
|
||||||
|
self::LOCATION_HINT => self::PROTOCOL . $suiteName,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$fileName = $suiteName::__getFileName();
|
||||||
|
|
||||||
|
$this->printEvent(
|
||||||
|
self::TEST_SUITE_STARTED, [
|
||||||
|
self::NAME => substr($suiteName, 2),
|
||||||
|
self::LOCATION_HINT => self::PROTOCOL . $fileName,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @phpstan-ignore-next-line */
|
||||||
|
public function endTestSuite(TestSuite $suite): void
|
||||||
|
{
|
||||||
|
$suiteName = $suite->getName();
|
||||||
|
|
||||||
|
if (file_exists($suiteName) || !method_exists($suiteName, '__getFileName')) {
|
||||||
|
$this->printEvent(
|
||||||
|
self::TEST_SUITE_FINISHED, [
|
||||||
|
self::NAME => $suiteName,
|
||||||
|
self::LOCATION_HINT => self::PROTOCOL . $suiteName,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->printEvent(
|
||||||
|
self::TEST_SUITE_FINISHED, [
|
||||||
|
self::NAME => substr($suiteName, 2),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Test|TestCase $test
|
||||||
|
*/
|
||||||
|
public function startTest(Test $test): void
|
||||||
|
{
|
||||||
|
if (!TeamCity::isPestTest($test)) {
|
||||||
|
$this->phpunitTeamCity->startTest($test);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->printEvent('testStarted', [
|
||||||
|
self::NAME => $test->getName(),
|
||||||
|
/* @phpstan-ignore-next-line */
|
||||||
|
self::LOCATION_HINT => self::PROTOCOL . $test->toString(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Test|TestCase $test
|
||||||
|
*/
|
||||||
|
public function endTest(Test $test, float $time): void
|
||||||
|
{
|
||||||
|
if (!TeamCity::isPestTest($test)) {
|
||||||
|
$this->phpunitTeamCity->endTest($test, $time);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->printEvent('testFinished', [
|
||||||
|
self::NAME => $test->getName(),
|
||||||
|
self::DURATION => self::toMilliseconds($time),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Test|TestCase $test
|
||||||
|
*/
|
||||||
|
public function addError(Test $test, Throwable $t, float $time): void
|
||||||
|
{
|
||||||
|
if (!TeamCity::isPestTest($test)) {
|
||||||
|
$this->phpunitTeamCity->addError($test, $t, $time);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->printEvent(
|
||||||
|
self::TEST_FAILED, [
|
||||||
|
self::NAME => $test->getName(),
|
||||||
|
'message' => $t->getMessage(),
|
||||||
|
'details' => $t->getTraceAsString(),
|
||||||
|
self::DURATION => self::toMilliseconds($time),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @phpstan-ignore-next-line
|
||||||
|
*
|
||||||
|
* @param Test|TestCase $test
|
||||||
|
*/
|
||||||
|
public function addWarning(Test $test, Warning $e, float $time): void
|
||||||
|
{
|
||||||
|
if (!TeamCity::isPestTest($test)) {
|
||||||
|
$this->phpunitTeamCity->addWarning($test, $e, $time);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->printEvent(
|
||||||
|
self::TEST_FAILED, [
|
||||||
|
self::NAME => $test->getName(),
|
||||||
|
'message' => $e->getMessage(),
|
||||||
|
'details' => $e->getTraceAsString(),
|
||||||
|
self::DURATION => self::toMilliseconds($time),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
|
||||||
|
{
|
||||||
|
$this->phpunitTeamCity->addFailure($test, $e, $time);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function writeProgress(string $progress): void
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, string|int> $params
|
||||||
|
*/
|
||||||
|
private function printEvent(string $eventName, array $params = []): void
|
||||||
|
{
|
||||||
|
$this->write("\n##teamcity[{$eventName}");
|
||||||
|
|
||||||
|
if ($this->flowId !== 0) {
|
||||||
|
$params['flowId'] = $this->flowId;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($params as $key => $value) {
|
||||||
|
$escapedValue = self::escapeValue((string) $value);
|
||||||
|
$this->write(" {$key}='{$escapedValue}'");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->write("]\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function escapeValue(string $text): string
|
||||||
|
{
|
||||||
|
return str_replace(
|
||||||
|
['|', "'", "\n", "\r", ']', '['],
|
||||||
|
['||', "|'", '|n', '|r', '|]', '|['],
|
||||||
|
$text
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function toMilliseconds(float $time): int
|
||||||
|
{
|
||||||
|
return (int) round($time * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function isPestTest(Test $test): bool
|
||||||
|
{
|
||||||
|
return in_array(TestCase::class, class_uses($test), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -180,6 +180,11 @@
|
|||||||
PASS Tests\Expect\toHaveKey
|
PASS Tests\Expect\toHaveKey
|
||||||
✓ pass
|
✓ pass
|
||||||
✓ failures
|
✓ failures
|
||||||
|
✓ not failures
|
||||||
|
|
||||||
|
PASS Tests\Expect\toHaveKeys
|
||||||
|
✓ pass
|
||||||
|
✓ failures
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|
||||||
PASS Tests\Expect\toHaveProperty
|
PASS Tests\Expect\toHaveProperty
|
||||||
@ -353,5 +358,5 @@
|
|||||||
✓ depends with defined arguments
|
✓ depends with defined arguments
|
||||||
✓ depends run test only once
|
✓ depends run test only once
|
||||||
|
|
||||||
Tests: 6 skipped, 208 passed
|
Tests: 6 skipped, 211 passed
|
||||||
|
|
||||||
15
tests/Expect/toHaveKeys.php
Normal file
15
tests/Expect/toHaveKeys.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
|
test('pass', function () {
|
||||||
|
expect(['a' => 1, 'b', 'c' => 'world'])->toHaveKeys(['a', 'c']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('failures', function () {
|
||||||
|
expect(['a' => 1, 'b', 'c' => 'world'])->toHaveKeys(['a', 'd']);
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|
||||||
|
test('not failures', function () {
|
||||||
|
expect(['a' => 1, 'hello' => 'world', 'c'])->not->toHaveKeys(['hello', 'c']);
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
Reference in New Issue
Block a user