Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Add tests #367

Merged
merged 1 commit into from
Aug 4, 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
20 changes: 20 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,26 @@ parameters:
count: 1
path: test/Double/Faker/FalseGenerator.php

-
message: "#^Method Ergebnis\\\\FactoryBot\\\\Test\\\\Double\\\\Faker\\\\MaximumGenerator\\:\\:numberBetween\\(\\) has parameter \\$max with no typehint specified\\.$#"
count: 1
path: test/Double/Faker/MaximumGenerator.php

-
message: "#^Method Ergebnis\\\\FactoryBot\\\\Test\\\\Double\\\\Faker\\\\MaximumGenerator\\:\\:numberBetween\\(\\) has parameter \\$min with no typehint specified\\.$#"
count: 1
path: test/Double/Faker/MaximumGenerator.php

-
message: "#^Method Ergebnis\\\\FactoryBot\\\\Test\\\\Double\\\\Faker\\\\MinimumGenerator\\:\\:numberBetween\\(\\) has parameter \\$max with no typehint specified\\.$#"
count: 1
path: test/Double/Faker/MinimumGenerator.php

-
message: "#^Method Ergebnis\\\\FactoryBot\\\\Test\\\\Double\\\\Faker\\\\MinimumGenerator\\:\\:numberBetween\\(\\) has parameter \\$min with no typehint specified\\.$#"
count: 1
path: test/Double/Faker/MinimumGenerator.php

-
message: "#^Method Ergebnis\\\\FactoryBot\\\\Test\\\\Double\\\\Faker\\\\TrueGenerator\\:\\:boolean\\(\\) has parameter \\$chanceOfGettingTrue with no typehint specified\\.$#"
count: 1
Expand Down
24 changes: 24 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,30 @@
<code>$max</code>
</MixedArgument>
</file>
<file src="test/Double/Faker/MaximumGenerator.php">
<MissingParamType occurrences="2">
<code>$min</code>
<code>$max</code>
</MissingParamType>
<MixedInferredReturnType occurrences="1">
<code>int</code>
</MixedInferredReturnType>
<MixedReturnStatement occurrences="1">
<code>$max</code>
</MixedReturnStatement>
</file>
<file src="test/Double/Faker/MinimumGenerator.php">
<MissingParamType occurrences="2">
<code>$min</code>
<code>$max</code>
</MissingParamType>
<MixedInferredReturnType occurrences="1">
<code>int</code>
</MixedInferredReturnType>
<MixedReturnStatement occurrences="1">
<code>$min</code>
</MixedReturnStatement>
</file>
<file src="test/Double/Faker/TrueGenerator.php">
<MissingParamType occurrences="3">
<code>$chanceOfGettingTrue</code>
Expand Down
24 changes: 24 additions & 0 deletions test/Double/Faker/MaximumGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 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/factory-bot
*/

namespace Ergebnis\FactoryBot\Test\Double\Faker;

use Faker\Generator;

final class MaximumGenerator extends Generator
{
public function numberBetween($min = 0, $max = 2147483647): int
{
return $max;
}
}
24 changes: 24 additions & 0 deletions test/Double/Faker/MinimumGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 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/factory-bot
*/

namespace Ergebnis\FactoryBot\Test\Double\Faker;

use Faker\Generator;

final class MinimumGenerator extends Generator
{
public function numberBetween($min = 0, $max = 2147483647): int
{
return $min;
}
}
44 changes: 44 additions & 0 deletions test/Unit/Strategy/DefaultStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,50 @@ public function testResolveCountResolvesCountWithFakerWhenCountIsExact(): void
self::assertSame($value, $resolved);
}

/**
* @dataProvider \Ergebnis\FactoryBot\Test\DataProvider\IntProvider::greaterThanOrEqualToZero()
*
* @param int $minimum
*/
public function testResolveCountResolvesCountWithFakerWhenCountIsBetweenAndFakerReturnsMinimum(int $minimum): void
{
$maximum = self::faker()->numberBetween($minimum + 1);

$strategy = new DefaultStrategy();

$resolved = $strategy->resolveCount(
new Double\Faker\MinimumGenerator(),
Count::between(
$minimum,
$maximum
)
);

self::assertSame($minimum, $resolved);
}

/**
* @dataProvider \Ergebnis\FactoryBot\Test\DataProvider\IntProvider::greaterThanZero()
*
* @param int $maximum
*/
public function testResolveCountResolvesCountWithFakerWhenCountIsBetweenAndFakerReturnsMaximum(int $maximum): void
{
$minimum = self::faker()->numberBetween(0, $maximum - 1);

$strategy = new DefaultStrategy();

$resolved = $strategy->resolveCount(
new Double\Faker\MaximumGenerator(),
Count::between(
$minimum,
$maximum
)
);

self::assertSame($maximum, $resolved);
}

public function testResolveCountResolvesCountWithFakerWhenCountIsBetween(): void
{
$faker = self::faker();
Expand Down