|
7 | 7 |
|
8 | 8 | class TextTest extends TestCase
|
9 | 9 | {
|
10 |
| - public function testTextMaxLength() |
| 10 | + /** |
| 11 | + * @var Generator |
| 12 | + */ |
| 13 | + private $generator; |
| 14 | + |
| 15 | + /** |
| 16 | + * @before |
| 17 | + */ |
| 18 | + public function buildGenerator() |
11 | 19 | {
|
12 | 20 | $generator = new Generator();
|
13 | 21 | $generator->addProvider(new Text($generator));
|
14 | 22 | $generator->seed(0);
|
15 | 23 |
|
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; |
21 | 25 | }
|
22 | 26 |
|
23 | 27 | /**
|
24 |
| - * @expectedException \InvalidArgumentException |
| 28 | + * @testWith [10] |
| 29 | + * [20] |
| 30 | + * [50] |
| 31 | + * [70] |
| 32 | + * [90] |
| 33 | + * [120] |
| 34 | + * [150] |
| 35 | + * [200] |
| 36 | + * [500] |
25 | 37 | */
|
| 38 | + public function testTextMaxLength($length) |
| 39 | + { |
| 40 | + $this->assertLessThan($length, $this->generator->realText($length)); |
| 41 | + } |
| 42 | + |
26 | 43 | public function testTextMaxIndex()
|
27 | 44 | {
|
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.'); |
32 | 50 | }
|
33 | 51 |
|
34 |
| - /** |
35 |
| - * @expectedException \InvalidArgumentException |
36 |
| - */ |
37 | 52 | public function testTextMinIndex()
|
38 | 53 | {
|
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.'); |
43 | 59 | }
|
44 | 60 |
|
45 |
| - /** |
46 |
| - * @expectedException \InvalidArgumentException |
47 |
| - */ |
48 | 61 | public function testTextMinLength()
|
49 | 62 | {
|
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.'); |
54 | 68 | }
|
55 | 69 | }
|
0 commit comments