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

Commit

Permalink
Enhancement: Implement DataProvider\FloatProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Oct 4, 2020
1 parent 3c5dc82 commit d1dcf5f
Show file tree
Hide file tree
Showing 8 changed files with 442 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/integrate.yaml
Expand Up @@ -10,8 +10,8 @@ on: # yamllint disable-line rule:truthy

env:
ERGEBNIS_BOT_NAME: "ergebnis-bot"
MIN_COVERED_MSI: 93
MIN_MSI: 91
MIN_COVERED_MSI: 94
MIN_MSI: 92
PHP_EXTENSIONS: "mbstring"

jobs:
Expand Down
11 changes: 9 additions & 2 deletions CHANGELOG.md
Expand Up @@ -6,14 +6,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

For a full diff see [`1.1.0...main`][1.1.0...main].
For a full diff see [`1.2.0...main`][1.2.0...main].

## [`1.2.0`][1.2.0]

For a full diff see [`1.1.0...1.2.0`][1.1.0...1.2.0].

### Added

* Added `DataProvider\BooleanProvider` ([#326]), by [@localheinz]
* Added `DataProvider\NullProvider` ([#327]), by [@localheinz]
* Added `DataProvider\StringProvider` ([#328]), by [@localheinz]
* Added `DataProvider\IntProvider` ([#335]), by [@localheinz]
* Added `DataProvider\FloatProvider` ([#341]), by [@localheinz]
*
### Changed

Expand Down Expand Up @@ -109,7 +114,8 @@ For a full diff see [`0.7.0...0.8.0`][0.7.0...0.8.0].
[0.9.1...1.0.0]: https://github.com/ergebnis/test-util/compare/0.9.1...1.0.0
[1.0.0...1.0.1]: https://github.com/ergebnis/test-util/compare/1.0.0...1.0.1
[1.0.1...1.1.0]: https://github.com/ergebnis/test-util/compare/1.0.1...1.1.0
[1.1.0...main]: https://github.com/ergebnis/test-util/compare/1.1.0...main
[1.1.0...1.2.0]: https://github.com/ergebnis/test-util/compare/1.1.0...1.2.0
[1.2.0...main]: https://github.com/ergebnis/test-util/compare/1.2.0...main

[#118]: https://github.com/ergebnis/test-util/pull/118
[#119]: https://github.com/ergebnis/test-util/pull/119
Expand All @@ -124,6 +130,7 @@ For a full diff see [`0.7.0...0.8.0`][0.7.0...0.8.0].
[#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
[#341]: https://github.com/ergebnis/test-util/pull/341

[@ergebnis]: https://github.com/ergebnis
[@localheinz]: https://github.com/localheinz
4 changes: 2 additions & 2 deletions Makefile
@@ -1,5 +1,5 @@
MIN_COVERED_MSI:=93
MIN_MSI:=91
MIN_COVERED_MSI:=94
MIN_MSI:=92

.PHONY: it
it: coding-standards static-code-analysis tests ## Runs the coding-standards, static-code-analysis, and tests targets
Expand Down
13 changes: 13 additions & 0 deletions README.md
Expand Up @@ -102,6 +102,7 @@ In addition to the assertions made available by extending from `PHPUnit\Framewor
This package provides the following generic data providers:

* [`Ergebnis\Test\Util\DataProvider\BoolProvider`](https://github.com/ergebnis/test-util#dataproviderboolprovider)
* [`Ergebnis\Test\Util\DataProvider\FloatProvider`](https://github.com/ergebnis/test-util#dataproviderfloatprovider)
* [`Ergebnis\Test\Util\DataProvider\IntProvider`](https://github.com/ergebnis/test-util#dataproviderintprovider)
* [`Ergebnis\Test\Util\DataProvider\NullProvider`](https://github.com/ergebnis/test-util#dataprovidernullprovider)
* [`Ergebnis\Test\Util\DataProvider\StringProvider`](https://github.com/ergebnis/test-util#dataproviderstringprovider)
Expand Down Expand Up @@ -143,6 +144,18 @@ final class ExampleTest extends Framework\TestCase

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

#### `DataProvider\FloatProvider`

* `arbitrary()` provides arbitrary `float`s
* `greaterThanOne()` provides `int`s greater than `1.0`
* `greaterThanZero()` provides `int`s greater than `0.0`
* `lessThanOne()` provides `int`s less than `1.0`
* `lessThanZero()` provides `int`s less than `0.0`
* `one()` provides `1.0`
* `zero()` provides `0.0`

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

#### `DataProvider\IntProvider`

* `arbitrary()` provides arbitrary `int`s
Expand Down
115 changes: 115 additions & 0 deletions phpstan-baseline.neon
Expand Up @@ -115,6 +115,121 @@ parameters:
count: 1
path: src/DataProvider/BoolProvider.php

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\IntProvider\\:\\:faker\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
Expand Down
14 changes: 14 additions & 0 deletions psalm-baseline.xml
Expand Up @@ -10,6 +10,20 @@
<code>true === $value</code>
</RedundantIdentityWithTrue>
</file>
<file src="src/DataProvider/FloatProvider.php">
<InvalidOperand occurrences="1">
<code>-1 * $faker-&gt;randomFloat(null, 1.01)</code>
</InvalidOperand>
<MoreSpecificReturnType occurrences="7">
<code>\Generator&lt;string, array{0: float}&gt;</code>
<code>\Generator&lt;string, array{0: float}&gt;</code>
<code>\Generator&lt;string, array{0: float}&gt;</code>
<code>\Generator&lt;string, array{0: float}&gt;</code>
<code>\Generator&lt;string, array{0: float}&gt;</code>
<code>\Generator&lt;string, array{0: float}&gt;</code>
<code>\Generator&lt;string, array{0: float}&gt;</code>
</MoreSpecificReturnType>
</file>
<file src="src/DataProvider/IntProvider.php">
<MoreSpecificReturnType occurrences="7">
<code>\Generator&lt;string, array{0: int}&gt;</code>
Expand Down
105 changes: 105 additions & 0 deletions src/DataProvider/FloatProvider.php
@@ -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 FloatProvider
{
use Util\Helper;

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

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

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

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

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

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

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

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

return [
'float-less-than-minus-one' => -1 * $faker->randomFloat(null, 1.01),
'float-minus-one' => -1.0,
'float-zero' => 0.0,
'float-plus-one' => 1.0,
'float-greater-than-plus-one' => $faker->randomFloat(null, 1.01),
];
}
}

0 comments on commit d1dcf5f

Please sign in to comment.