RandomEnglishGeneratorTest   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 2
dl 0
loc 102
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testFakerRandomName() 0 6 1
A testSentence() 0 6 1
A testComma() 0 6 1
A testTitle() 0 6 1
A testCapitalFirstWord() 0 6 1
A testVerbing() 0 6 1
A testRandomCountry() 0 6 1
A testRandomColour() 0 6 1
A testRandomWordVerticalBars() 0 9 2
A testPluralNoun() 0 6 1
A testParagraph() 0 7 1
1
<?php declare(strict_types = 1);
2
3
namespace Tests\Suilven\RandomEnglish;
4
5
use PHPUnit\Framework\TestCase;
6
use Suilven\RandomEnglish\RandomEnglishGenerator;
7
8
class RandomEnglishGeneratorTest extends TestCase
9
{
10
11
    public function setUp(): void
12
    {
13
        parent::setUp();
14
15
        \srand(1000);
16
    }
17
18
19
    public function testFakerRandomName(): void
20
    {
21
        $generator = new RandomEnglishGenerator();
22
        $generator->setConfig('My name is [name]');
23
        $this->assertEquals('My name is Prof. Tomasa Lind Jr.', $generator->sentence());
24
    }
25
26
27
    public function testSentence(): void
28
    {
29
        $generator = new RandomEnglishGenerator();
30
        $generator->setConfig('The [adjective] [noun] [verb] [preposition] the [noun]');
31
        $this->assertEquals('The quiet bank reply next the god.', $generator->sentence());
32
    }
33
34
35
    public function testComma(): void
36
    {
37
        $generator = new RandomEnglishGenerator();
38
        $generator->setConfig('It was [adjective] in the [noun], [contraction] [noun] was [adjective]');
39
        $this->assertEquals('It was quiet in the bank, your bread was low.', $generator->sentence());
40
    }
41
42
43
    public function testTitle(): void
44
    {
45
        $generator = new RandomEnglishGenerator();
46
        $generator->setConfig('It was [adjective] in the [noun], [contraction] [noun] was [adjective]');
47
        $this->assertEquals('It Was Quiet In The Bank, Your Bread Was Low', $generator->title());
48
    }
49
50
51
    public function testCapitalFirstWord(): void
52
    {
53
        $generator = new RandomEnglishGenerator();
54
        $generator->setConfig('[control_verb]!!  You cannot [verb] here');
55
        $this->assertEquals('Order!! You cannot egg here.', $generator->sentence());
56
    }
57
58
59
    public function testVerbing(): void
60
    {
61
        $generator = new RandomEnglishGenerator();
62
        $generator->setConfig('What are you [verb_ing]?');
63
        $this->assertEquals('What are you puting?', $generator->sentence());
64
    }
65
66
67
    public function testRandomCountry(): void
68
    {
69
        $generator = new RandomEnglishGenerator();
70
        $generator->setConfig('Can I go on holiday to [country] due to Covid 19?');
71
        $this->assertEquals('Can I go on holiday to Saint Lucia due to Covid 19?', $generator->sentence());
72
    }
73
74
75
    public function testRandomColour(): void
76
    {
77
        $generator = new RandomEnglishGenerator();
78
        $generator->setConfig('I like [colour]');
79
        $this->assertEquals('I like saddle brown.', $generator->sentence());
80
    }
81
82
83
    public function testRandomWordVerticalBars(): void
84
    {
85
        $generator = new RandomEnglishGenerator();
86
        $generator->setConfig('a|b|c|d');
87
        for ($i=0; $i<100; $i++) {
88
            $sentence = $generator->sentence();
89
            $this->assertTrue(\in_array($sentence, ['A.', 'B.', 'C.', 'D.'], true));
90
        }
91
    }
92
93
94
    public function testPluralNoun(): void
95
    {
96
        $generator = new RandomEnglishGenerator();
97
        $generator->setConfig('How many [plural_noun] do you have?');
98
        $this->assertEquals('How many norths do you have?', $generator->sentence());
99
    }
100
101
    
102
    public function testParagraph(): void
103
    {
104
        $generator = new RandomEnglishGenerator();
105
        $paragraph = $generator->paragraph(2);
106
        $this->assertEquals('The baby is a future of an public prize and is so in the soft for his front and' .
107
            ' the mildness of his city.  It was fun in the soup, as first was sound.', $paragraph);
108
    }
109
}
110