|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
View Code Duplication |
class StringFunctionsTest extends PHPUnit_Framework_TestCase |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
private $e; |
|
6
|
|
|
|
|
7
|
|
|
public function setUp() |
|
8
|
|
|
{ |
|
9
|
|
|
|
|
10
|
|
|
$this->e = new StringFunctions(); |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
public function tearDown() { |
|
14
|
|
|
$this->e = NULL; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function test_formatAsUsername() { |
|
|
|
|
|
|
18
|
|
|
// Happy path |
|
19
|
|
|
$this->assertEquals($this->e->formatAsUsername("this"), "This"); |
|
20
|
|
|
$this->assertEquals($this->e->formatAsUsername("1this"), "1this"); |
|
21
|
|
|
$this->assertEquals($this->e->formatAsUsername("This"), "This"); |
|
22
|
|
|
$this->assertEquals($this->e->formatAsUsername("This "), "This"); |
|
23
|
|
|
$this->assertEquals($this->e->formatAsUsername("This_"), "This"); |
|
24
|
|
|
|
|
25
|
|
|
// Sad Path |
|
26
|
|
|
$this->assertNotEquals($this->e->formatAsUsername("This "), "This "); |
|
27
|
|
|
$this->assertNotEquals($this->e->formatAsUsername("This_"), "This_"); |
|
28
|
|
|
$this->assertNotEquals($this->e->formatAsUsername("this"), "this"); |
|
29
|
|
|
$this->assertNotEquals($this->e->formatAsUsername("1this"), "1This"); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function test_formatAsEmail() { |
|
|
|
|
|
|
33
|
|
|
$this->assertEquals($this->e->formatAsEmail("[email protected]"), "[email protected]"); |
|
34
|
|
|
$this->assertEquals($this->e->formatAsEmail("[email protected]"), "[email protected]"); |
|
35
|
|
|
$this->assertEquals($this->e->formatAsEmail(" [email protected]"), "[email protected]"); |
|
36
|
|
|
$this->assertEquals($this->e->formatAsEmail("[email protected] "), "[email protected]"); |
|
37
|
|
|
$this->assertEquals($this->e->formatAsEmail("1this12345 @example.com"), "[email protected]"); |
|
38
|
|
|
$this->assertEquals($this->e->formatAsEmail("1this12345@ example.com"), "[email protected]"); |
|
39
|
|
|
|
|
40
|
|
|
// Sad Path |
|
41
|
|
|
$this->assertNotEquals($this->e->formatAsEmail(" [email protected]"), " [email protected]"); |
|
42
|
|
|
$this->assertNotEquals($this->e->formatAsEmail("[email protected] "), "[email protected] "); |
|
43
|
|
|
$this->assertNotEquals($this->e->formatAsEmail("1this12345 @example.com"), "1this12345 @example.com"); |
|
44
|
|
|
$this->assertNotEquals($this->e->formatAsEmail("1this12345@ example.com"), "1this12345@ example.com"); |
|
45
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.