Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Refactoring of the TextTest class #1590

Merged
merged 7 commits into from
Sep 18, 2019
64 changes: 39 additions & 25 deletions test/Faker/Provider/TextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,63 @@

class TextTest extends TestCase
{
public function testTextMaxLength()
/**
* @var Generator
*/
private $generator;

/**
* @before
*/
public function buildGenerator()
{
$generator = new Generator();
$generator->addProvider(new Text($generator));
$generator->seed(0);

$lengths = array(10, 20, 50, 70, 90, 120, 150, 200, 500);

foreach ($lengths as $length) {
$this->assertLessThan($length, $generator->realText($length));
}
$this->generator = $generator;
}

/**
* @expectedException \InvalidArgumentException
* @testWith [10]
* [20]
* [50]
* [70]
* [90]
* [120]
* [150]
* [200]
* [500]
*/
public function testTextMaxLength($length)
{
$this->assertLessThan($length, $this->generator->realText($length));
}

public function testTextMaxIndex()
{
$generator = new Generator();
$generator->addProvider(new Text($generator));
$generator->seed(0);
$generator->realText(200, 11);
$this->setExpectedException('InvalidArgumentException');

$this->generator->realText(200, 11);

$this->fail('The index should be less than or equal to 5.');
}

/**
* @expectedException \InvalidArgumentException
*/
public function testTextMinIndex()
{
$generator = new Generator();
$generator->addProvider(new Text($generator));
$generator->seed(0);
$generator->realText(200, 0);
$this->setExpectedException('InvalidArgumentException');

$this->generator->realText(200, 0);

$this->fail('The index should be greater than or equal to 1.');
}

/**
* @expectedException \InvalidArgumentException
*/
public function testTextMinLength()
{
$generator = new Generator();
$generator->addProvider(new Text($generator));
$generator->seed(0);
$generator->realText(9);
$this->setExpectedException('InvalidArgumentException');

$this->generator->realText(9);

$this->fail('The text should be at least 10 characters.');
}
}