1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
<?php
namespace Faker\Test\Provider;
use Faker\Provider\en_US\Text;
use Faker\Test\TestCase;
use PHPUnit\Framework\Attributes\TestWith;
/**
* @group legacy
*/
final class TextTest extends TestCase
{
#[TestWith([10])]
#[TestWith([20])]
#[TestWith([50])]
#[TestWith([70])]
#[TestWith([90])]
#[TestWith([120])]
#[TestWith([150])]
#[TestWith([200])]
#[TestWith([500])]
public function testRealTextMaxLength($length)
{
self::assertLessThan($length, strlen($this->faker->realText($length)));
}
#[TestWith([10])]
#[TestWith([20])]
#[TestWith([50])]
#[TestWith([70])]
#[TestWith([90])]
#[TestWith([120])]
#[TestWith([150])]
#[TestWith([200])]
#[TestWith([500])]
public function testRealTextMinLength($length)
{
self::assertGreaterThanOrEqual($length * 0.8, strlen($this->faker->realText($length)));
}
public function testRealTextMaxIndex()
{
$this->expectException(\InvalidArgumentException::class);
$this->faker->realText(200, 11);
self::fail('The index should be less than or equal to 5.');
}
public function testRealTextMinIndex()
{
$this->expectException(\InvalidArgumentException::class);
$this->faker->realText(200, 0);
self::fail('The index should be greater than or equal to 1.');
}
public function testRealTextMinNbChars()
{
$this->expectException(\InvalidArgumentException::class);
$this->faker->realText(9);
self::fail('The text should be at least 10 characters.');
}
#[TestWith([1, 10])]
#[TestWith([5, 10])]
#[TestWith([8, 10])]
#[TestWith([18, 20])]
#[TestWith([45, 50])]
#[TestWith([180, 200])]
#[TestWith([1950, 2000])]
public function testRealTextBetweenTextLength($min, $max)
{
$strlen = strlen($this->faker->realTextBetween($min, $max));
self::assertGreaterThan($min, $strlen);
self::assertLessThan($max, $strlen);
}
public function testRealTextBetweenMinNbChars()
{
$this->expectException(\InvalidArgumentException::class);
$this->faker->realTextBetween(25, 20);
self::fail('minNbChars should be smaller than maxNbChars');
}
public function testRealTextBetweenMinNbCharsGreaterThan1()
{
$this->expectException(\InvalidArgumentException::class);
$this->faker->realTextBetween(0, 30);
self::fail('minNbChars must be bigger than 0');
}
protected function getProviders(): iterable
{
yield new Text($this->faker);
}
}
|