Skip to content

Commit 1841369

Browse files
committed
Mutation testing + more UT
1 parent 0843757 commit 1841369

19 files changed

+268
-21
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Makefile text
2222
/.unused.php export-ignore
2323
/CHANGELOG.md export-ignore
2424
/CONTRIBUTING.md export-ignore
25+
/infection.json export-ignore
2526
/Makefile export-ignore
2627
/phpmd.xml export-ignore
2728
/phpstan.neon export-ignore

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
/.php_cs.cache
66
/.phpunit.cache/
77
/.phpunit.result.cache
8+
/infection.log

.php_cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,6 @@ return PhpCsFixer\Config::create()
256256
'no_php4_constructor' => true,
257257
// Adds or removes `?` before type declarations for parameters with a default `null` value.
258258
'nullable_type_declaration_for_default_null_value' => true,
259-
// A return statement wishing to return `void` should not return `null`.
260-
'simplified_null_return' => true,
261259
// Changes doc blocks from single to multi line, or reversed. Works for class constants, properties and methods only.
262260
'phpdoc_line_span' => ['const'=>'multi','property'=>'single'],
263261
// Function `implode` must be called with 2 arguments in the documented order.

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Add **Deprecated** section in `CHANGELOG.md`
1313
- Add Redis pipeline support
1414
- Prefix properties name with `@` in Aggregation's SortBy (keep BC)
15-
- Add more unit tests (Aggregation options, Field creation)
15+
- Add more unit tests (Aggregation options, Field creation, DataHelper, RedisHelper)
16+
- (dev) Add mutation testing
1617

1718
### Changed
1819

CONTRIBUTING.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,20 @@ The application use PSR-12 code conventions, strong typing.
3434

3535
The source code must be, at least, compatible with **PHP 7.2**.
3636

37-
Check your code by running the command:
37+
Check your code by running the commands:
3838
```sh
3939
make analyze
40+
make test
4041
```
4142
The command will output any information worth knowing. No error should be left.
4243

44+
If Xdebug is installed, you can also run the commands:
45+
```sh
46+
make coverage
47+
make mutation-test
48+
```
49+
Ideally, coverage should only increase, and **Covered Code MSI** shouldn't be below 95%
50+
4351
----
4452

4553
Thanks!

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: analyze fix-code test coverage
1+
.PHONY: analyze fix-code test coverage mutation-test clean
22

33
analyze: | vendor
44
$(COMPOSER) exec -v parallel-lint -- src
@@ -24,6 +24,14 @@ coverage: | vendor
2424
@if [ -z "`php -v | grep -i 'xdebug'`" ]; then echo "You need to install Xdebug in order to do this action"; exit 1; fi
2525
$(COMPOSER) exec -v phpunit -- --coverage-text --color
2626

27+
mutation-test: | vendor
28+
@if [ -z "`php -v | grep -i 'xdebug'`" ]; then echo "You need to install Xdebug in order to do this action"; exit 1; fi
29+
$(COMPOSER) exec -v infection -- --only-covered --min-covered-msi=95
30+
31+
clean:
32+
rm -rf .phpunit.cache vendor
33+
rm -f .php_cs.cache .phpunit.result.cache composer.phar composer.lock infection.log
34+
2735
vendor: composer.json
2836
$(COMPOSER) install --optimize-autoloader --no-suggest --prefer-dist
2937
touch vendor

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"enlightn/security-checker": "^1.5",
2525
"ergebnis/composer-normalize": "^2.13",
2626
"friendsofphp/php-cs-fixer": "^2.16",
27+
"infection/infection": "^0.18.2",
2728
"insolita/unused-scanner": "^2.2",
2829
"phan/phan": "^3.2",
2930
"php-parallel-lint/php-parallel-lint": "^1.2",

infection.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"source": {
3+
"directories": [
4+
"src"
5+
]
6+
},
7+
"logs": {
8+
"text": "infection.log"
9+
},
10+
"mutators": {
11+
"@default": true,
12+
"global-ignoreSourceCodeByRegex": [
13+
"throw new RuntimeException\\(sprintf\\('The assertion of %s::%s at line %d failed\\.'.+",
14+
"for \\(.+\\) \\{"
15+
],
16+
"DecrementInteger": {
17+
"ignore": [
18+
"MacFJA\\RediSearch\\Aggregate\\Exception\\UnknownSortDirectionException",
19+
"MacFJA\\RediSearch\\Search\\Exception\\UnknownUnitException"
20+
]
21+
},
22+
"OneZeroInteger": {
23+
"ignore": [
24+
"MacFJA\\RediSearch\\Aggregate\\Exception\\UnknownSortDirectionException",
25+
"MacFJA\\RediSearch\\Search\\Exception\\UnknownUnitException"
26+
]
27+
}
28+
}
29+
}

src/Aggregate/Exception/UnknownSortDirectionException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class UnknownSortDirectionException extends UnexpectedValueException
3333
*/
3434
public function __construct(array $directions, int $code = 0, ?Throwable $previous = null)
3535
{
36-
$message = sprintf('Sort By direction can only be "ASC" or "DESC". Provided: %s', implode(', ', $directions));
36+
$message = sprintf('Sort By direction can only be "ASC" or "DESC". Provided: %s.', implode(', ', $directions));
3737
parent::__construct($message, $code, $previous);
3838
}
3939
}

src/Aggregate/SortBy.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class SortBy implements \MacFJA\RediSearch\PartialQuery
3939

4040
public const SORT_DESC = 'DESC';
4141

42+
private const SORT_ACCEPTABLE_VALUES = [self::SORT_ASC, self::SORT_DESC];
43+
4244
/**
4345
* @psalm-var array<string,"ASC"|"DESC">
4446
* @phpstan-var array<string,"ASC"|"DESC">
@@ -61,10 +63,10 @@ class SortBy implements \MacFJA\RediSearch\PartialQuery
6163
public function __construct(array $properties, ?int $max = null)
6264
{
6365
DataHelper::assertArrayOf(array_keys($properties), 'string');
64-
$allValues = array_unique(array_merge($properties, ['ASC', 'DESC']));
66+
$allValues = array_unique(array_merge($properties, self::SORT_ACCEPTABLE_VALUES));
6567
DataHelper::assert(
6668
2 === count($allValues),
67-
new UnknownSortDirectionException(array_diff($allValues, ['ASC', 'DESC']))
69+
new UnknownSortDirectionException(array_diff($allValues, self::SORT_ACCEPTABLE_VALUES))
6870

6971
);
7072
DataHelper::assert(null === $max || $max >= 0, new OutOfRangeException('MAX such by greater or equals to 0'));

0 commit comments

Comments
 (0)