mirror of
https://github.com/pestphp/pest.git
synced 2026-03-10 17:57:23 +01:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 60c0636523 | |||
| 16b6f96b47 | |||
| 042f2ec3f3 | |||
| 851ce36010 | |||
| 4f386894bd | |||
| 2289adade2 | |||
| 29e21e3814 | |||
| 8367af22e7 | |||
| e3d678dc04 | |||
| 4ae482c707 |
@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
## [v1.18.0 (2021-08-30)](https://github.com/pestphp/pest/compare/v1.17.0...v1.18.0)
|
||||||
|
### Added
|
||||||
|
- `toHaveLength` expectation ([#386](https://github.com/pestphp/pest/pull/386))
|
||||||
|
- `nunomaduro/collision:^6.0` support ([4ae482c](https://github.com/pestphp/pest/commit/4ae482c7073fb77782b8a4b5738ef1fcea0f82ab))
|
||||||
|
|
||||||
## [v1.17.0 (2021-08-26)](https://github.com/pestphp/pest/compare/v1.16.0...v1.17.0)
|
## [v1.17.0 (2021-08-26)](https://github.com/pestphp/pest/compare/v1.16.0...v1.17.0)
|
||||||
### Added
|
### Added
|
||||||
- `toThrow` expectation ([#361](https://github.com/pestphp/pest/pull/361))
|
- `toThrow` expectation ([#361](https://github.com/pestphp/pest/pull/361))
|
||||||
|
|||||||
@ -31,6 +31,10 @@ composer lint
|
|||||||
```
|
```
|
||||||
## Tests
|
## Tests
|
||||||
|
|
||||||
|
Update the snapshots:
|
||||||
|
```bash
|
||||||
|
composer update:snapshots
|
||||||
|
```
|
||||||
Run all tests:
|
Run all tests:
|
||||||
```bash
|
```bash
|
||||||
composer test
|
composer test
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.3 || ^8.0",
|
"php": "^7.3 || ^8.0",
|
||||||
"nunomaduro/collision": "^5.4.0",
|
"nunomaduro/collision": "^5.4.0|^6.0",
|
||||||
"pestphp/pest-plugin": "^1.0.0",
|
"pestphp/pest-plugin": "^1.0.0",
|
||||||
"phpunit/phpunit": "^9.5.5"
|
"phpunit/phpunit": "^9.5.5"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -327,6 +327,36 @@ final class Expectation
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that $number matches value's Length.
|
||||||
|
*/
|
||||||
|
public function toHaveLength(int $number): Expectation
|
||||||
|
{
|
||||||
|
if (is_string($this->value)) {
|
||||||
|
Assert::assertEquals($number, mb_strlen($this->value));
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_iterable($this->value)) {
|
||||||
|
return $this->toHaveCount($number);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_object($this->value)) {
|
||||||
|
if (method_exists($this->value, 'toArray')) {
|
||||||
|
$array = $this->value->toArray();
|
||||||
|
} else {
|
||||||
|
$array = (array) $this->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert::assertCount($number, $array);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new BadMethodCallException('Expectation value length is not countable.');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that $count matches the number of elements of the value.
|
* Asserts that $count matches the number of elements of the value.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -6,7 +6,7 @@ namespace Pest;
|
|||||||
|
|
||||||
function version(): string
|
function version(): string
|
||||||
{
|
{
|
||||||
return '1.17.0';
|
return '1.18.0';
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDirectory(string $file = ''): string
|
function testDirectory(string $file = ''): string
|
||||||
|
|||||||
@ -419,6 +419,20 @@
|
|||||||
✓ failures
|
✓ failures
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|
||||||
|
PASS Tests\Features\Expect\toHaveLength
|
||||||
|
✓ it passes with ('Fortaleza')
|
||||||
|
✓ it passes with ('Sollefteå')
|
||||||
|
✓ it passes with ('Ιεράπετρα')
|
||||||
|
✓ it passes with (stdClass Object (...))
|
||||||
|
✓ it passes with (Illuminate\Support\Collection Object (...))
|
||||||
|
✓ it passes with array
|
||||||
|
✓ it passes with *not*
|
||||||
|
✓ it properly fails with *not*
|
||||||
|
✓ it fails with (1)
|
||||||
|
✓ it fails with (1.5)
|
||||||
|
✓ it fails with (true)
|
||||||
|
✓ it fails with (null)
|
||||||
|
|
||||||
PASS Tests\Features\Expect\toHaveProperty
|
PASS Tests\Features\Expect\toHaveProperty
|
||||||
✓ pass
|
✓ pass
|
||||||
✓ failures
|
✓ failures
|
||||||
@ -662,5 +676,5 @@
|
|||||||
✓ it is a test
|
✓ it is a test
|
||||||
✓ it uses correct parent class
|
✓ it uses correct parent class
|
||||||
|
|
||||||
Tests: 4 incompleted, 9 skipped, 432 passed
|
Tests: 4 incompleted, 9 skipped, 444 passed
|
||||||
|
|
||||||
27
tests/Features/Expect/toHaveLength.php
Normal file
27
tests/Features/Expect/toHaveLength.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
|
it('passes', function ($value) {
|
||||||
|
expect($value)->toHaveLength(9);
|
||||||
|
})->with([
|
||||||
|
'Fortaleza', 'Sollefteå', 'Ιεράπετρα',
|
||||||
|
(object) [1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||||
|
collect([1, 2, 3, 4, 5, 6, 7, 8, 9]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
it('passes with array', function () {
|
||||||
|
expect([1, 2, 3])->toHaveLength(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('passes with *not*', function () {
|
||||||
|
expect('')->not->toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('properly fails with *not*', function () {
|
||||||
|
expect('pest')->not->toHaveLength(4);
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|
||||||
|
it('fails', function ($value) {
|
||||||
|
expect($value)->toHaveLength(1);
|
||||||
|
})->with([1, 1.5, true, null])->throws(BadMethodCallException::class);
|
||||||
Reference in New Issue
Block a user