Compare commits

..

32 Commits

Author SHA1 Message Date
cbd6a65057 release: v2.16.0 2023-08-21 09:42:07 +01:00
175004baf3 chore: adds testing on native functions 2023-08-21 09:40:04 +01:00
6d9c0483a6 chore: improves type checking 2023-08-21 09:39:55 +01:00
2dc413cba0 tests: update snapshots 2023-08-19 10:42:42 +01:00
206548af2b Merge pull request #895 from cerbero90/feature/traversable-sequence
[2.x] Add support for nested traversable in sequence
2023-08-19 09:38:46 +00:00
af6de422e9 Merge pull request #921 from leMaur/feat/string-case-expectations
feat: add string case expectations
2023-08-19 09:38:31 +00:00
1c7b254395 Merge branch '2.x' into feat/string-case-expectations 2023-08-19 10:28:48 +02:00
de1c721cd9 chore: improve error messages 2023-08-19 10:27:21 +02:00
f8dd286213 chore: skip array list 2023-08-19 10:27:02 +02:00
e11337df2d Merge branch '2.x' into feature/traversable-sequence 2023-08-19 00:34:30 +02:00
2f90d4ccd7 tests: update snapshots 2023-08-18 12:16:15 +01:00
2db15af24a Merge branch '2.x' into feature/traversable-sequence 2023-08-18 12:33:09 +02:00
c9e3932637 Merge pull request #911 from devajmeireles/feature/add-to-be-digits-expectation
[2.x] Introducing `toBeDigits` Expectation
2023-08-18 03:13:59 +00:00
d218afaf77 introducing new proposal of the PR template 2023-08-17 18:50:23 -03:00
19739ff814 Merge pull request #915 from pestphp/adapting-phpunit-xml-stubs
[2.x] Adapting `phpunit.xml` stubs with PhpUnit
2023-08-17 18:56:50 +00:00
478144fb35 feat: add toHaveStudlyCaseKeys 2023-08-17 20:51:26 +02:00
5d81cf0d4c feat: add toHaveCamelCaseKeys 2023-08-17 20:51:14 +02:00
0b115230f9 feat: add toHaveKebabCaseKeys 2023-08-17 20:50:51 +02:00
0b246f7a76 feat: add toHaveSnakeCaseKeys 2023-08-17 20:50:26 +02:00
7914224ff7 introducing https://schema.phpunit.de/10.3/phpunit.xsd 2023-08-17 15:50:15 -03:00
997b0e9368 feat: add toBeStudlyCase 2023-08-17 20:49:40 +02:00
a76414aeee feat: add toBeCamelCase 2023-08-17 20:49:21 +02:00
d2096df82a feat: add toBeKebabCase 2023-08-17 20:48:51 +02:00
4951b1b0f9 feat: add toBeSnakeCase 2023-08-17 20:48:18 +02:00
f2e31452f2 Merge pull request #912 from devajmeireles/issue-template
Introducing Issue Template
2023-08-17 11:04:27 -03:00
f0223b50d0 introducing sample repository input 2023-08-16 15:50:40 -03:00
0263fcb2ac wip 2023-08-16 14:18:09 -03:00
c0a234317b introducing issue template 2023-08-16 14:16:18 -03:00
398e3ff3b5 introducing toBeDigits 2023-08-14 17:10:58 -03:00
d94a6580f5 fix: type check 2023-08-02 20:49:27 +02:00
fb75b712d3 chore: update snapshot 2023-08-02 20:49:05 +02:00
6ead2a4e8b feat(sequence): Add support for nested traversable 2023-08-02 20:31:53 +02:00
27 changed files with 639 additions and 44 deletions

66
.github/ISSUE_TEMPLATE/bug_report.yml vendored Normal file
View File

@ -0,0 +1,66 @@
name: Bug Report
description: Report an Issue or Bug with the Pest
title: "[Bug]: "
labels: ["bug"]
body:
- type: markdown
attributes:
value: |
We're sorry to hear you have a problem. Can you help us solve it by providing the following details.
- type: textarea
id: what-happened
attributes:
label: What Happened
description: What did you expect to happen?
placeholder: When I use expect()->toBeTrue() in my tests, I get an error
validations:
required: true
- type: textarea
id: how-to-reproduce
attributes:
label: How to Reproduce
description: How did this occur, please add any config values used and provide a set of reliable steps if possible.
placeholder: Install a fresh Laravel app, add Pest, add a test that uses expect()->toBeTrue()
validations:
required: true
- type: input
id: repository-sample
attributes:
label: Sample Repository
description: If possible, please provide a sample repository that reproduces the issue.
placeholder: https://github.com.br/your-username/your-repository
- type: input
id: pest-version
attributes:
label: Pest Version
description: What version of our Package are you running? Please be as specific as possible
placeholder: 2.14.1
validations:
required: true
- type: input
id: php-version
attributes:
label: PHP Version
description: What version of PHP are you running? Please be as specific as possible
placeholder: 8.1.20
validations:
required: true
- type: dropdown
id: operating-systems
attributes:
label: Operation System
description: On which operating systems does the problem occur? You can select more than one.
multiple: true
options:
- macOS
- Windows
- Linux
validations:
required: true
- type: textarea
id: notes
attributes:
label: Notes
description: Use this field to provide any other notes that you feel might be relevant to the issue.
validations:
required: false

View File

@ -1,10 +1,16 @@
| Q | A
| ------------- | ---
| Bug fix? | yes/no
| New feature? | yes/no
| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->
<!--
- Replace this comment by a description of what your PR is solving.
- Fill in the form below correctly. This will help the Pest team to understand the PR and also work on it.
-->
### What:
- [ ] Bug Fix
- [ ] New Feature
### Description:
<!-- describe what your PR is solving -->
### Related:
<!-- link to the issue(s) your PR is solving. If it doesn't exist, remove the "Related" section. -->

View File

@ -22,7 +22,7 @@
"nunomaduro/collision": "^7.8.1",
"nunomaduro/termwind": "^1.15.1",
"pestphp/pest-plugin": "^2.0.1",
"pestphp/pest-plugin-arch": "^2.2.3",
"pestphp/pest-plugin-arch": "^2.3.1",
"phpunit/phpunit": "^10.3.2"
},
"conflict": {
@ -50,7 +50,7 @@
]
},
"require-dev": {
"pestphp/pest-dev-tools": "^2.15.0",
"pestphp/pest-dev-tools": "^2.16.0",
"pestphp/pest-plugin-type-coverage": "^2.0.0",
"symfony/process": "^6.3.2"
},

View File

@ -1,5 +1,6 @@
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/ergebnis/phpstan-rules/rules.neon
- vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon
parameters:
@ -11,4 +12,12 @@ parameters:
reportUnmatchedIgnoredErrors: true
ignoreErrors:
- "#has a nullable return type declaration.#"
- "#Language construct isset\\(\\) should not be used.#"
- "#is not allowed to extend#"
- "#is concrete, but does not have a Test suffix#"
- "#with a nullable type declaration#"
- "#type mixed is not subtype of native#"
- "# with null as default value#"
- "#has parameter \\$closure with default value.#"
- "#has parameter \\$description with default value.#"

View File

@ -6,6 +6,8 @@ namespace Pest;
use BadMethodCallException;
use Closure;
use InvalidArgumentException;
use OutOfRangeException;
use Pest\Arch\Contracts\ArchExpectation;
use Pest\Arch\Expectations\Targeted;
use Pest\Arch\Expectations\ToBeUsedIn;
@ -28,7 +30,6 @@ use Pest\Expectations\OppositeExpectation;
use Pest\Matchers\Any;
use Pest\Support\ExpectationPipeline;
use PHPUnit\Architecture\Elements\ObjectDescription;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\ExpectationFailedException;
/**
@ -219,30 +220,26 @@ final class Expectation
throw new BadMethodCallException('Expectation value is not iterable.');
}
$value = is_array($this->value) ? $this->value : iterator_to_array($this->value);
$keys = array_keys($value);
$values = array_values($value);
$callbacksCount = count($callbacks);
$index = 0;
while (count($callbacks) < count($values)) {
$callbacks[] = $callbacks[$index];
$index = $index < count($values) - 1 ? $index + 1 : 0;
if (count($callbacks) == 0) {
throw new InvalidArgumentException('No sequence expectations defined.');
}
if ($callbacksCount > count($values)) {
Assert::assertLessThanOrEqual(count($value), count($callbacks));
}
$index = $valuesCount = 0;
foreach ($values as $key => $item) {
if ($callbacks[$key] instanceof Closure) {
call_user_func($callbacks[$key], new self($item), new self($keys[$key]));
foreach ($this->value as $key => $value) {
$valuesCount++;
continue;
if ($callbacks[$index] instanceof Closure) {
$callbacks[$index](new self($value), new self($key));
} else {
(new self($value))->toEqual($callbacks[$index]);
}
(new self($item))->toEqual($callbacks[$key]);
$index = isset($callbacks[$index + 1]) ? $index + 1 : 0;
}
if (count($callbacks) > $valuesCount) {
throw new OutOfRangeException('Sequence expectations are more than the iterable items.');
}
return $this;
@ -740,4 +737,100 @@ final class Expectation
FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class'))
);
}
/**
* Asserts that the given expectation is iterable and contains snake_case keys.
*
* @return self<TValue>
*/
public function toHaveSnakeCaseKeys(string $message = ''): self
{
if (! is_iterable($this->value)) {
InvalidExpectationValue::expected('iterable');
}
foreach ($this->value as $k => $item) {
if (is_string($k)) {
$this->and($k)->toBeSnakeCase($message);
}
if (is_array($item)) {
$this->and($item)->toHaveSnakeCaseKeys($message);
}
}
return $this;
}
/**
* Asserts that the given expectation is iterable and contains kebab-case keys.
*
* @return self<TValue>
*/
public function toHaveKebabCaseKeys(string $message = ''): self
{
if (! is_iterable($this->value)) {
InvalidExpectationValue::expected('iterable');
}
foreach ($this->value as $k => $item) {
if (is_string($k)) {
$this->and($k)->toBeKebabCase($message);
}
if (is_array($item)) {
$this->and($item)->toHaveKebabCaseKeys($message);
}
}
return $this;
}
/**
* Asserts that the given expectation is iterable and contains camelCase keys.
*
* @return self<TValue>
*/
public function toHaveCamelCaseKeys(string $message = ''): self
{
if (! is_iterable($this->value)) {
InvalidExpectationValue::expected('iterable');
}
foreach ($this->value as $k => $item) {
if (is_string($k)) {
$this->and($k)->toBeCamelCase($message);
}
if (is_array($item)) {
$this->and($item)->toHaveCamelCaseKeys($message);
}
}
return $this;
}
/**
* Asserts that the given expectation is iterable and contains StudlyCase keys.
*
* @return self<TValue>
*/
public function toHaveStudlyCaseKeys(string $message = ''): self
{
if (! is_iterable($this->value)) {
InvalidExpectationValue::expected('iterable');
}
foreach ($this->value as $k => $item) {
if (is_string($k)) {
$this->and($k)->toBeStudlyCase($message);
}
if (is_array($item)) {
$this->and($item)->toHaveStudlyCaseKeys($message);
}
}
return $this;
}
}

View File

@ -20,7 +20,7 @@ abstract class Attribute
* @param array<int, string> $attributes
* @return array<int, string>
*/
public function __invoke(TestCaseMethodFactory $method, array $attributes): array
public function __invoke(TestCaseMethodFactory $method, array $attributes): array // @phpstan-ignore-line
{
return $attributes;
}

View File

@ -193,7 +193,7 @@ final class TestCaseFactory
}
PHP;
eval($classCode);
eval($classCode); // @phpstan-ignore-line
} catch (ParseError $caught) {
throw new RuntimeException(sprintf(
"Unable to create test case for test file at %s. \n %s",

View File

@ -40,7 +40,7 @@ final class KernelDump
*/
public function disable(): void
{
@ob_clean();
@ob_clean(); // @phpstan-ignore-line
if ($this->buffer !== '') {
$this->flush();

View File

@ -502,6 +502,18 @@ final class Expectation
return $this;
}
/**
* Asserts that the value contains only digits.
*
* @return self<TValue>
*/
public function toBeDigits(string $message = ''): self
{
Assert::assertTrue(ctype_digit((string) $this->value), $message);
return $this;
}
/**
* Asserts that the value is of type object.
*
@ -1009,4 +1021,76 @@ final class Expectation
return $this;
}
/**
* Asserts that the value is snake_case.
*
* @return self<TValue>
*/
public function toBeSnakeCase(string $message = ''): self
{
$value = (string) $this->value;
if ($message === '') {
$message = "Failed asserting that {$value} is snake_case.";
}
Assert::assertTrue((bool) preg_match('/^[\p{Ll}_]+$/u', $value), $message);
return $this;
}
/**
* Asserts that the value is kebab-case.
*
* @return self<TValue>
*/
public function toBeKebabCase(string $message = ''): self
{
$value = (string) $this->value;
if ($message === '') {
$message = "Failed asserting that {$value} is kebab-case.";
}
Assert::assertTrue((bool) preg_match('/^[\p{Ll}-]+$/u', $value), $message);
return $this;
}
/**
* Asserts that the value is camelCase.
*
* @return self<TValue>
*/
public function toBeCamelCase(string $message = ''): self
{
$value = (string) $this->value;
if ($message === '') {
$message = "Failed asserting that {$value} is camelCase.";
}
Assert::assertTrue((bool) preg_match('/^\p{Ll}[\p{Ll}\p{Lu}]+$/u', $value), $message);
return $this;
}
/**
* Asserts that the value is StudlyCase.
*
* @return self<TValue>
*/
public function toBeStudlyCase(string $message = ''): self
{
$value = (string) $this->value;
if ($message === '') {
$message = "Failed asserting that {$value} is StudlyCase.";
}
Assert::assertTrue((bool) preg_match('/^\p{Lu}+\p{Ll}[\p{Ll}\p{Lu}]+$/u', $value), $message);
return $this;
}
}

View File

@ -6,7 +6,7 @@ namespace Pest;
function version(): string
{
return '2.15.0';
return '2.16.0';
}
function testDirectory(string $file = ''): string

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>

View File

@ -1,5 +1,5 @@
Pest Testing Framework 2.15.0.
Pest Testing Framework 2.16.0.
USAGE: pest <file> [options]

View File

@ -1,3 +1,3 @@
Pest Testing Framework 2.15.0.
Pest Testing Framework 2.16.0.

View File

@ -297,12 +297,14 @@
PASS Tests\Features\Expect\sequence
✓ an exception is thrown if the the type is not iterable
✓ an exception is thrown if there are no expectations
✓ allows for sequences of checks to be run on iterable data
✓ loops back to the start if it runs out of sequence items
✓ fails if the number of iterable items is greater than the number of expectations
✓ fails if the number of iterable items is less than the number of expectations
✓ it works with associative arrays
✓ it can be passed non-callable values
✓ it can be passed a mixture of value types
✓ it works with traversables
PASS Tests\Features\Expect\toBe
✓ strict comparisons
@ -338,6 +340,18 @@
✓ pass
✓ failures
✓ failures with custom message
✓ not failures
PASS Tests\Features\Expect\toBeCamelCase
✓ pass
✓ failures
✓ failures with custom message
✓ not failures
PASS Tests\Features\Expect\toBeDigits
✓ pass
✓ failures
✓ failures with custom message
✓ not failures
PASS Tests\Features\Expect\toBeDirectory
@ -441,6 +455,12 @@
✓ pass
✓ failures
✓ failures with custom message
✓ not failures
PASS Tests\Features\Expect\toBeKebabCase
✓ pass
✓ failures
✓ failures with custom message
✓ not failures
PASS Tests\Features\Expect\toBeLessThan
@ -509,12 +529,24 @@
✓ pass
✓ failures
✓ failures with custom message
✓ not failures
PASS Tests\Features\Expect\toBeSnakeCase
✓ pass
✓ failures
✓ failures with custom message
✓ not failures
PASS Tests\Features\Expect\toBeString
✓ pass
✓ failures
✓ failures with custom message
✓ not failures
PASS Tests\Features\Expect\toBeStudlyCase
✓ pass
✓ failures
✓ failures with custom message
✓ not failures
PASS Tests\Features\Expect\toBeTrue
@ -596,12 +628,24 @@
PASS Tests\Features\Expect\toEqualWithDelta
✓ pass
✓ failures with custom message
✓ not failures
PASS Tests\Features\Expect\toHaveCamelCaseKeys
✓ pass
✓ failures
✓ failures with message
✓ not failures
PASS Tests\Features\Expect\toHaveCount
✓ pass
✓ failures
✓ failures with message
✓ not failures
PASS Tests\Features\Expect\toHaveKebabCaseKeys
✓ pass
✓ failures
✓ failures with message
✓ not failures
PASS Tests\Features\Expect\toHaveKey
@ -678,6 +722,18 @@
✓ failures
✓ failures with message
✓ failures with message and Any matcher
✓ not failures
PASS Tests\Features\Expect\toHaveSnakeCaseKeys
✓ pass
✓ failures
✓ failures with message
✓ not failures
PASS Tests\Features\Expect\toHaveStudlyCaseKeys
✓ pass
✓ failures
✓ failures with message
✓ not failures
PASS Tests\Features\Expect\toHaveSuffix
@ -1240,4 +1296,4 @@
WARN Tests\Visual\Version
- visual snapshot of help command output
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 878 passed (2013 assertions)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 916 passed (2190 assertions)

View File

@ -3,7 +3,7 @@
use Pest\Expectation;
test('globals')
->expect(['dd', 'dump', 'ray'])
->expect(['dd', 'dump', 'ray', 'die', 'var_dump', 'sleep'])
->not->toBeUsed()
->ignoring(Expectation::class);

View File

@ -1,11 +1,13 @@
<?php
use PHPUnit\Framework\ExpectationFailedException;
test('an exception is thrown if the the type is not iterable', function () {
expect('Foobar')->each->sequence();
})->throws(BadMethodCallException::class, 'Expectation value is not iterable.');
test('an exception is thrown if there are no expectations', function () {
expect(['Foobar'])->sequence();
})->throws(InvalidArgumentException::class, 'No sequence expectations defined.');
test('allows for sequences of checks to be run on iterable data', function () {
expect([1, 2, 3])
->sequence(
@ -40,7 +42,7 @@ test('loops back to the start if it runs out of sequence items', function () {
expect(static::getCount())->toBe(16);
});
test('fails if the number of iterable items is greater than the number of expectations', function () {
test('fails if the number of iterable items is less than the number of expectations', function () {
expect([1, 2])
->sequence(
function ($expectation) {
@ -53,7 +55,7 @@ test('fails if the number of iterable items is greater than the number of expect
$expectation->toBeInt()->toEqual(3);
},
);
})->throws(ExpectationFailedException::class);
})->throws(OutOfRangeException::class, 'Sequence expectations are more than the iterable items.');
test('it works with associative arrays', function () {
expect(['foo' => 'bar', 'baz' => 'boom'])
@ -86,3 +88,26 @@ test('it can be passed a mixture of value types', function () {
expect(static::getCount())->toBe(4);
});
test('it works with traversables', function () {
$generator = (function () {
yield 'one' => (fn () => yield from [1, 2, 3])();
yield 'two' => (fn () => yield from [4, 5, 6])();
yield 'three' => (fn () => yield from [7, 8, 9])();
})();
expect($generator)->sequence(
fn ($value, $key) => $key->toBe('one')
->and($value)
->toBeInstanceOf(Generator::class)
->sequence(1, 2, 3),
fn ($value, $key) => $key->toBe('two')
->and($value)
->toBeInstanceOf(Generator::class)
->sequence(4, 5, 6),
fn ($value, $key) => $key->toBe('three')
->and($value)
->toBeInstanceOf(Generator::class)
->sequence(7, 8, 9),
);
});

View File

@ -0,0 +1,23 @@
<?php
use PHPUnit\Framework\ExpectationFailedException;
test('pass', function () {
expect('abc')->toBeCamelCase();
expect('abcDef')->toBeCamelCase();
expect('abc-def')->not->toBeCamelCase();
expect('abc-def')->not->toBeCamelCase();
expect('AbcDef')->not->toBeCamelCase();
});
test('failures', function () {
expect('Abc')->toBeCamelCase();
})->throws(ExpectationFailedException::class);
test('failures with custom message', function () {
expect('Abc')->toBeCamelCase('oh no!');
})->throws(ExpectationFailedException::class, 'oh no!');
test('not failures', function () {
expect('abcDef')->not->toBeCamelCase();
})->throws(ExpectationFailedException::class);

View 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);

View File

@ -0,0 +1,23 @@
<?php
use PHPUnit\Framework\ExpectationFailedException;
test('pass', function () {
expect('abc')->toBeKebabCase();
expect('abc-def')->toBeKebabCase();
expect('abc_def')->not->toBeKebabCase();
expect('abcDef')->not->toBeKebabCase();
expect('AbcDef')->not->toBeKebabCase();
});
test('failures', function () {
expect('Abc')->toBeKebabCase();
})->throws(ExpectationFailedException::class);
test('failures with custom message', function () {
expect('Abc')->toBeKebabCase('oh no!');
})->throws(ExpectationFailedException::class, 'oh no!');
test('not failures', function () {
expect('abc-def')->not->toBeKebabCase();
})->throws(ExpectationFailedException::class);

View File

@ -0,0 +1,23 @@
<?php
use PHPUnit\Framework\ExpectationFailedException;
test('pass', function () {
expect('abc')->toBeSnakeCase();
expect('abc_def')->toBeSnakeCase();
expect('abc-def')->not->toBeSnakeCase();
expect('abcDef')->not->toBeSnakeCase();
expect('AbcDef')->not->toBeSnakeCase();
});
test('failures', function () {
expect('Abc')->toBeSnakeCase();
})->throws(ExpectationFailedException::class);
test('failures with custom message', function () {
expect('Abc')->toBeSnakeCase('oh no!');
})->throws(ExpectationFailedException::class, 'oh no!');
test('not failures', function () {
expect('abc_def')->not->toBeSnakeCase();
})->throws(ExpectationFailedException::class);

View File

@ -0,0 +1,23 @@
<?php
use PHPUnit\Framework\ExpectationFailedException;
test('pass', function () {
expect('Abc')->toBeStudlyCase();
expect('AbcDef')->toBeStudlyCase();
expect('abc-def')->not->toBeStudlyCase();
expect('abc-def')->not->toBeStudlyCase();
expect('abc')->not->toBeStudlyCase();
});
test('failures', function () {
expect('abc')->toBeStudlyCase();
})->throws(ExpectationFailedException::class);
test('failures with custom message', function () {
expect('abc')->toBeStudlyCase('oh no!');
})->throws(ExpectationFailedException::class, 'oh no!');
test('not failures', function () {
expect('AbcDef')->not->toBeStudlyCase();
})->throws(ExpectationFailedException::class);

View File

@ -0,0 +1,36 @@
<?php
use Pest\Exceptions\InvalidExpectationValue;
use PHPUnit\Framework\ExpectationFailedException;
$array = [
'camel' => true,
'camelCase' => [
'camel' => true,
'camelCase' => [
'camel' => true,
'camelCase' => true,
],
'list' => [
'abc',
'def',
'ghi',
],
],
];
test('pass', function () use ($array) {
expect($array)->toHaveCamelCaseKeys();
});
test('failures', function () {
expect('not-an-array')->toHaveCamelCaseKeys();
})->throws(InvalidExpectationValue::class);
test('failures with message', function () use ($array) {
expect($array)->not->toHaveCamelCaseKeys('oh no!');
})->throws(ExpectationFailedException::class, 'oh no!');
test('not failures', function () use ($array) {
expect($array)->not->toHaveCamelCaseKeys();
})->throws(ExpectationFailedException::class);

View File

@ -0,0 +1,36 @@
<?php
use Pest\Exceptions\InvalidExpectationValue;
use PHPUnit\Framework\ExpectationFailedException;
$array = [
'kebab' => true,
'kebab-case' => [
'kebab' => true,
'kebab-case' => [
'kebab' => true,
'kebab-case' => true,
],
'list' => [
'abc',
'def',
'ghi',
],
],
];
test('pass', function () use ($array) {
expect($array)->toHaveKebabCaseKeys();
});
test('failures', function () {
expect('not-an-array')->toHaveKebabCaseKeys();
})->throws(InvalidExpectationValue::class);
test('failures with message', function () use ($array) {
expect($array)->not->toHaveKebabCaseKeys('oh no!');
})->throws(ExpectationFailedException::class, 'oh no!');
test('not failures', function () use ($array) {
expect($array)->not->toHaveKebabCaseKeys();
})->throws(ExpectationFailedException::class);

View File

@ -0,0 +1,36 @@
<?php
use Pest\Exceptions\InvalidExpectationValue;
use PHPUnit\Framework\ExpectationFailedException;
$array = [
'snake' => true,
'snake_case' => [
'snake' => true,
'snake_case' => [
'snake' => true,
'snake_case' => true,
],
'list' => [
'abc',
'def',
'ghi',
],
],
];
test('pass', function () use ($array) {
expect($array)->toHaveSnakeCaseKeys();
});
test('failures', function () {
expect('not-an-array')->toHaveSnakeCaseKeys();
})->throws(InvalidExpectationValue::class);
test('failures with message', function () use ($array) {
expect($array)->not->toHaveSnakeCaseKeys('oh no!');
})->throws(ExpectationFailedException::class, 'oh no!');
test('not failures', function () use ($array) {
expect($array)->not->toHaveSnakeCaseKeys();
})->throws(ExpectationFailedException::class);

View File

@ -0,0 +1,36 @@
<?php
use Pest\Exceptions\InvalidExpectationValue;
use PHPUnit\Framework\ExpectationFailedException;
$array = [
'Studly' => true,
'StudlyCase' => [
'Studly' => true,
'StudlyCase' => [
'Studly' => true,
'StudlyCase' => true,
],
'List' => [
'abc',
'def',
'ghi',
],
],
];
test('pass', function () use ($array) {
expect($array)->toHaveStudlyCaseKeys();
});
test('failures', function () {
expect('not-an-array')->toHaveStudlyCaseKeys();
})->throws(InvalidExpectationValue::class);
test('failures with message', function () use ($array) {
expect($array)->not->toHaveStudlyCaseKeys('oh no!');
})->throws(ExpectationFailedException::class, 'oh no!');
test('not failures', function () use ($array) {
expect($array)->not->toHaveStudlyCaseKeys();
})->throws(ExpectationFailedException::class);

View File

@ -16,7 +16,7 @@ $run = function () {
test('parallel', function () use ($run) {
expect($run('--exclude-group=integration'))
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 867 passed (1998 assertions)')
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 905 passed (2175 assertions)')
->toContain('Parallel: 3 processes');
})->skipOnWindows();