Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Enhancement: Implement IntProvider #335

Merged
merged 1 commit into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ on: # yamllint disable-line rule:truthy

env:
ERGEBNIS_BOT_NAME: "ergebnis-bot"
MIN_COVERED_MSI: 91
MIN_MSI: 91
MIN_COVERED_MSI: 90
MIN_MSI: 88
PHP_EXTENSIONS: "mbstring"

jobs:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ For a full diff see [`1.1.0...main`][1.1.0...main].
* Added `DataProvider\BooleanProvider` ([#326]), by [@localheinz]
* Added `DataProvider\NullProvider` ([#327]), by [@localheinz]
* Added `DataProvider\StringProvider` ([#328]), by [@localheinz]
* Added `DataProvider\IntProvider` ([#335]), by [@localheinz]
*
### Changed

Expand Down Expand Up @@ -122,6 +123,7 @@ For a full diff see [`0.7.0...0.8.0`][0.7.0...0.8.0].
[#327]: https://github.com/ergebnis/test-util/pull/327
[#328]: https://github.com/ergebnis/test-util/pull/328
[#334]: https://github.com/ergebnis/test-util/pull/334
[#335]: https://github.com/ergebnis/test-util/pull/335

[@ergebnis]: https://github.com/ergebnis
[@localheinz]: https://github.com/localheinz
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MIN_COVERED_MSI:=91
MIN_MSI:=91
MIN_COVERED_MSI:=90
MIN_MSI:=88

.PHONY: it
it: coding-standards static-code-analysis tests ## Runs the coding-standards, static-code-analysis, and tests targets
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ final class ExampleTest extends Framework\TestCase

For examples, see [`Ergebnis\Test\Util\Test\Unit\DataProvider\BoolProviderTest`](test/Unit/DataProvider/BoolProviderTest.php).

#### `DataProvider\IntProvider`

* `arbitrary()` provides arbitrary `int`s
* `greaterThanOne()` provides `int`s greater than `1`
* `greaterThanZero()` provides `int`s greater than `0`
* `lessThanOne()` provides `int`s less than `1`
* `lessThanZero()` provides `int`s less than `0`
* `one()` provides `1`
* `zero()` provides `0`

For examples, see [`Ergebnis\Test\Util\Test\Unit\DataProvider\IntProviderTest`](test/Unit/DataProvider/IntProviderTest.php).

#### `DataProvider\NullProvider`

* `null()` provides `null`
Expand Down
115 changes: 115 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,121 @@ parameters:
count: 1
path: src/DataProvider/BoolProvider.php

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:faker\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
path: src/DataProvider/IntProvider.php

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:assertClassesAreAbstractOrFinal\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
path: src/DataProvider/IntProvider.php

-
message: "#^Parameter \\#1 \\$argument of class ReflectionClass constructor expects class\\-string\\<T of object\\>\\|T of object, string given\\.$#"
count: 2
path: src/DataProvider/IntProvider.php

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:assertClassesHaveTests\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
path: src/DataProvider/IntProvider.php

-
message: "#^Call to an undefined static method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:assertEmpty\\(\\)\\.$#"
count: 2
path: src/DataProvider/IntProvider.php

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:assertClassyConstructsSatisfySpecification\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
path: src/DataProvider/IntProvider.php

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:assertClassExists\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
path: src/DataProvider/IntProvider.php

-
message: "#^Call to an undefined static method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:assertTrue\\(\\)\\.$#"
count: 11
path: src/DataProvider/IntProvider.php

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:assertClassExtends\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
path: src/DataProvider/IntProvider.php

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:assertClassImplementsInterface\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
path: src/DataProvider/IntProvider.php

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:assertClassIsAbstract\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
path: src/DataProvider/IntProvider.php

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:assertClassIsFinal\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
path: src/DataProvider/IntProvider.php

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:assertClassSatisfiesSpecification\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
path: src/DataProvider/IntProvider.php

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:assertClassUsesTrait\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
path: src/DataProvider/IntProvider.php

-
message: "#^Call to an undefined static method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:assertContains\\(\\)\\.$#"
count: 1
path: src/DataProvider/IntProvider.php

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:assertInterfaceExists\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
path: src/DataProvider/IntProvider.php

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:assertInterfaceExtends\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
path: src/DataProvider/IntProvider.php

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:assertInterfaceSatisfiesSpecification\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
path: src/DataProvider/IntProvider.php

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:assertTraitExists\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
path: src/DataProvider/IntProvider.php

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:assertTraitSatisfiesSpecification\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
path: src/DataProvider/IntProvider.php

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:provideDataForValues\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
path: src/DataProvider/IntProvider.php

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:provideDataForValuesWhere\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
path: src/DataProvider/IntProvider.php

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:provideDataForValuesWhereNot\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
path: src/DataProvider/IntProvider.php

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\NullProvider\\:\\:faker\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
Expand Down
16 changes: 16 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
<code>true === $value</code>
</RedundantIdentityWithTrue>
</file>
<file src="src/DataProvider/IntProvider.php">
<MoreSpecificReturnType occurrences="7">
<code>\Generator&lt;string, array{0: int}&gt;</code>
<code>\Generator&lt;string, array{0: int}&gt;</code>
<code>\Generator&lt;string, array{0: int}&gt;</code>
<code>\Generator&lt;string, array{0: int}&gt;</code>
<code>\Generator&lt;string, array{0: int}&gt;</code>
<code>\Generator&lt;string, array{0: int}&gt;</code>
<code>\Generator&lt;string, array{0: int}&gt;</code>
</MoreSpecificReturnType>
</file>
<file src="src/DataProvider/NullProvider.php">
<MoreSpecificReturnType occurrences="1">
<code>\Generator&lt;string, array{0: null}&gt;</code>
Expand Down Expand Up @@ -43,6 +54,11 @@
<code>class-string</code>
</UnnecessaryVarAnnotation>
</file>
<file src="test/Unit/DataProvider/IntProviderTest.php">
<MissingClosureParamType occurrences="1">
<code>$value</code>
</MissingClosureParamType>
</file>
<file src="test/Unit/Exception/InvalidExcludeClassNameTest.php">
<MixedInferredReturnType occurrences="1">
<code>\Generator&lt;array&lt;null|array|bool|float|int|resource|\stdClass&gt;&gt;</code>
Expand Down
105 changes: 105 additions & 0 deletions src/DataProvider/IntProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2017-2020 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/test-util
*/

namespace Ergebnis\Test\Util\DataProvider;

use Ergebnis\Test\Util;

final class IntProvider
{
use Util\Helper;

/**
* @return \Generator<string, array{0: int}>
*/
public static function arbitrary(): \Generator
{
yield from self::provideDataForValues(self::values());
}

/**
* @return \Generator<string, array{0: int}>
*/
public static function lessThanZero(): \Generator
{
yield from self::provideDataForValuesWhere(self::values(), static function (int $value): bool {
return 0 > $value;
});
}

/**
* @return \Generator<string, array{0: int}>
*/
public static function zero(): \Generator
{
yield from self::provideDataForValuesWhere(self::values(), static function (int $value): bool {
return 0 === $value;
});
}

/**
* @return \Generator<string, array{0: int}>
*/
public static function greaterThanZero(): \Generator
{
yield from self::provideDataForValuesWhere(self::values(), static function (int $value): bool {
return 0 < $value;
});
}

/**
* @return \Generator<string, array{0: int}>
*/
public static function lessThanOne(): \Generator
{
yield from self::provideDataForValuesWhere(self::values(), static function (int $value): bool {
return 1 > $value;
});
}

/**
* @return \Generator<string, array{0: int}>
*/
public static function one(): \Generator
{
yield from self::provideDataForValuesWhere(self::values(), static function (int $value): bool {
return 1 === $value;
});
}

/**
* @return \Generator<string, array{0: int}>
*/
public static function greaterThanOne(): \Generator
{
yield from self::provideDataForValuesWhere(self::values(), static function (int $value): bool {
return 1 < $value;
});
}

/**
* @return array<string, int>
*/
private static function values(): array
{
$faker = self::faker();

return [
'int-less-than-minus-one' => -1 * $faker->numberBetween(1),
'int-minus-one' => -1,
'int-zero' => 0,
'int-plus-one' => 1,
'int-greater-than-plus-one' => $faker->numberBetween(1),
];
}
}
Loading