Skip to content

Commit 8832be5

Browse files
authored
Merge pull request #7 from faissaloux/toReturnUnique
`toReturnUnique()`
2 parents 8e3fbb7 + 75b09ba commit 8832be5

16 files changed

+200
-9
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ This plugin checks what's inside the files.
55

66
[![Tests](https://github.com/faissaloux/pest-plugin-inside/actions/workflows/tests.yml/badge.svg)](https://github.com/faissaloux/pest-plugin-inside/actions/workflows/tests.yml) ![Codecov](https://img.shields.io/codecov/c/github/faissaloux/pest-plugin-inside) ![Packagist Version](https://img.shields.io/packagist/v/faissaloux/pest-plugin-inside) ![Packagist License](https://img.shields.io/packagist/l/faissaloux/pest-plugin-inside)
77

8+
## Available Methods
9+
### toReturnLowercase
10+
Make sure a file or directory files returns an array with all lowercase values.
11+
```php
12+
expect('file.php')->toReturnLowercase();
13+
```
14+
15+
### toReturnUnique
16+
Make sure a file or directory files returns an array with unique values.
17+
```php
18+
expect('file.php')->toReturnUnique();
19+
```
20+
21+
----
22+
823
### Success
924

1025
```php

src/Expectation.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,39 @@
44

55
use Pest\Expectation as PestExpectation;
66

7+
expect()->extend(
8+
'toReturnUnique',
9+
function (int $depth = -1): PestExpectation {
10+
$files = [$this->value];
11+
12+
if (is_dir($files[0])) {
13+
$files = getFilesIn($files[0], $depth);
14+
15+
if ($files === []) {
16+
expect(true)->toBeTrue();
17+
18+
return $this;
19+
}
20+
}
21+
22+
foreach ((array) $files as $file) {
23+
if (! file_exists($file)) {
24+
expect(true)->toBeFalse("$file not found!");
25+
}
26+
27+
$content = include $file;
28+
29+
expect($content)->toBeArray();
30+
31+
$duplicates = array_diff_assoc($content, array_unique($content));
32+
33+
expect($duplicates)->toBeEmpty('Duplicates found:'.implode(',', $duplicates)." in $file");
34+
}
35+
36+
return $this;
37+
}
38+
);
39+
740
expect()->extend(
841
'toReturnLowercase',
942
function (int $depth = -1): PestExpectation {
File renamed without changes.
File renamed without changes.

tests/Fixtures/shouldAllBeLowercase/subdirectory/notAllLowerCase.php renamed to tests/Fixtures/directory/subdirectory/notAllLowerCase.php

File renamed without changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
return [
6+
'',
7+
'f@issa!oux',
8+
'pest',
9+
'plugin',
10+
'inside',
11+
'duplicate',
12+
'word',
13+
'duplicate',
14+
];
File renamed without changes.
File renamed without changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
return [
6+
'',
7+
'f@issa!oux',
8+
'pest',
9+
'plugin',
10+
'inside',
11+
'duplicate',
12+
'word',
13+
'duplicate',
14+
];

tests/Fixtures/returnsArrayOnlyLowercase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
return [
66
'',
77
'f@issa!oux',
8+
'pestphp',
89
'pest',
10+
'plugin inside',
911
'plugin',
1012
'inside',
1113
'lowercase',

0 commit comments

Comments
 (0)