1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class StringFunctionsTest extends PHPUnit_Framework_TestCase |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
/** |
6
|
|
|
* @var StringFunctions |
7
|
|
|
*/ |
8
|
|
|
private $e; |
9
|
|
|
|
10
|
|
|
public function setUp() |
11
|
|
|
{ |
12
|
|
|
$this->e = new StringFunctions(); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
public function tearDown() |
16
|
|
|
{ |
17
|
|
|
$this->e = null; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function testFormatAsUsername() { |
21
|
|
|
// Happy path |
22
|
|
|
$this->assertEquals($this->e->formatAsUsername("this"), "This"); |
23
|
|
|
$this->assertEquals($this->e->formatAsUsername("1this"), "1this"); |
24
|
|
|
$this->assertEquals($this->e->formatAsUsername("This"), "This"); |
25
|
|
|
$this->assertEquals($this->e->formatAsUsername("This "), "This"); |
26
|
|
|
$this->assertEquals($this->e->formatAsUsername("This_"), "This"); |
27
|
|
|
|
28
|
|
|
// Sad Path |
29
|
|
|
$this->assertNotEquals($this->e->formatAsUsername("This "), "This "); |
30
|
|
|
$this->assertNotEquals($this->e->formatAsUsername("This_"), "This_"); |
31
|
|
|
$this->assertNotEquals($this->e->formatAsUsername("this"), "this"); |
32
|
|
|
$this->assertNotEquals($this->e->formatAsUsername("1this"), "1This"); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testFormatAsEmail() |
36
|
|
|
{ |
37
|
|
|
$this->assertEquals($this->e->formatAsEmail("[email protected]"), "[email protected]"); |
38
|
|
|
$this->assertEquals($this->e->formatAsEmail("[email protected]"), "[email protected]"); |
39
|
|
|
$this->assertEquals($this->e->formatAsEmail(" [email protected]"), "[email protected]"); |
40
|
|
|
$this->assertEquals($this->e->formatAsEmail("[email protected] "), "[email protected]"); |
41
|
|
|
$this->assertEquals($this->e->formatAsEmail("1this12345 @example.com"), "[email protected]"); |
42
|
|
|
$this->assertEquals($this->e->formatAsEmail("1this12345@ example.com"), "[email protected]"); |
43
|
|
|
|
44
|
|
|
// Sad Path |
45
|
|
|
$this->assertNotEquals($this->e->formatAsEmail(" [email protected]"), " [email protected]"); |
46
|
|
|
$this->assertNotEquals($this->e->formatAsEmail("[email protected] "), "[email protected] "); |
47
|
|
|
$this->assertNotEquals($this->e->formatAsEmail("1this12345 @example.com"), "1this12345 @example.com"); |
48
|
|
|
$this->assertNotEquals($this->e->formatAsEmail("1this12345@ example.com"), "1this12345@ example.com"); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.