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

Commit 242591b

Browse files
authored
Merge pull request #1590 from stevegrunwell/fix/refactor-text-tests
Refactoring of the TextTest class
2 parents 5ddd5bb + ebab5aa commit 242591b

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

test/Faker/Provider/TextTest.php

+39-25
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,63 @@
77

88
class TextTest extends TestCase
99
{
10-
public function testTextMaxLength()
10+
/**
11+
* @var Generator
12+
*/
13+
private $generator;
14+
15+
/**
16+
* @before
17+
*/
18+
public function buildGenerator()
1119
{
1220
$generator = new Generator();
1321
$generator->addProvider(new Text($generator));
1422
$generator->seed(0);
1523

16-
$lengths = array(10, 20, 50, 70, 90, 120, 150, 200, 500);
17-
18-
foreach ($lengths as $length) {
19-
$this->assertLessThan($length, $generator->realText($length));
20-
}
24+
$this->generator = $generator;
2125
}
2226

2327
/**
24-
* @expectedException \InvalidArgumentException
28+
* @testWith [10]
29+
* [20]
30+
* [50]
31+
* [70]
32+
* [90]
33+
* [120]
34+
* [150]
35+
* [200]
36+
* [500]
2537
*/
38+
public function testTextMaxLength($length)
39+
{
40+
$this->assertLessThan($length, $this->generator->realText($length));
41+
}
42+
2643
public function testTextMaxIndex()
2744
{
28-
$generator = new Generator();
29-
$generator->addProvider(new Text($generator));
30-
$generator->seed(0);
31-
$generator->realText(200, 11);
45+
$this->setExpectedException('InvalidArgumentException');
46+
47+
$this->generator->realText(200, 11);
48+
49+
$this->fail('The index should be less than or equal to 5.');
3250
}
3351

34-
/**
35-
* @expectedException \InvalidArgumentException
36-
*/
3752
public function testTextMinIndex()
3853
{
39-
$generator = new Generator();
40-
$generator->addProvider(new Text($generator));
41-
$generator->seed(0);
42-
$generator->realText(200, 0);
54+
$this->setExpectedException('InvalidArgumentException');
55+
56+
$this->generator->realText(200, 0);
57+
58+
$this->fail('The index should be greater than or equal to 1.');
4359
}
4460

45-
/**
46-
* @expectedException \InvalidArgumentException
47-
*/
4861
public function testTextMinLength()
4962
{
50-
$generator = new Generator();
51-
$generator->addProvider(new Text($generator));
52-
$generator->seed(0);
53-
$generator->realText(9);
63+
$this->setExpectedException('InvalidArgumentException');
64+
65+
$this->generator->realText(9);
66+
67+
$this->fail('The text should be at least 10 characters.');
5468
}
5569
}

0 commit comments

Comments
 (0)