Skip to content

Commit 4cae06d

Browse files
committed
IHF: is_email fully covered.
1 parent ed7552c commit 4cae06d

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

tests/email/IsEmailTest.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
class IsEmailTest extends TestCase
4+
{
5+
/** @test */
6+
public function it_returns_false_for_null()
7+
{
8+
$this->assertFalse(is_email(null));
9+
}
10+
11+
/** @test */
12+
public function it_returns_false_for_boolean_true()
13+
{
14+
$this->assertFalse(is_email(true));
15+
}
16+
17+
/** @test */
18+
public function it_returns_false_for_boolean_false()
19+
{
20+
$this->assertFalse(is_email(false));
21+
}
22+
23+
/** @test */
24+
public function it_returns_false_for_integer()
25+
{
26+
$this->assertFalse(is_email(123));
27+
}
28+
29+
/** @test */
30+
public function it_returns_false_for_float()
31+
{
32+
$this->assertFalse(is_email(123.45));
33+
}
34+
35+
/** @test */
36+
public function it_returns_false_for_empty_array()
37+
{
38+
$this->assertFalse(is_email([]));
39+
}
40+
41+
/** @test */
42+
public function it_returns_false_for_array()
43+
{
44+
$this->assertFalse(is_email(['user@example.com']));
45+
}
46+
47+
/** @test */
48+
public function it_returns_false_for_an_object()
49+
{
50+
$this->assertFalse(is_email(new StdClass()));
51+
}
52+
53+
/** @test */
54+
public function it_returns_false_for_invalid_emails()
55+
{
56+
$this->assertFalse(is_email('user'));
57+
$this->assertFalse(is_email('user@'));
58+
$this->assertFalse(is_email('user@example'));
59+
$this->assertFalse(is_email('user@example.'));
60+
}
61+
62+
/** @test */
63+
public function it_returns_true_for_valid_emails()
64+
{
65+
$this->assertTrue(is_email('user@example.com'));
66+
$this->assertTrue(is_email('user.name@example.com'));
67+
$this->assertTrue(is_email('user.name-long@example.com'));
68+
}
69+
}

0 commit comments

Comments
 (0)