forked from jkapuscik2/design-patterns-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserTest.php
More file actions
55 lines (42 loc) · 1.72 KB
/
UserTest.php
File metadata and controls
55 lines (42 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Structural\DependencyInjection;
use PHPUnit\Framework\TestCase;
class UserTest extends TestCase {
public function testRegisterOk () {
$userStorage = $this->getMockBuilder(UserStorage::class)
->disableOriginalConstructor()
->setMethods(["save"])
->getMock();
$userStorage->expects($this->once())->method("save")->willReturn(true);
$user = new User($userStorage);
$testEmail = "aaaaa@wp.pl";
$testPassword = "123456";
$this->assertTrue($user->register($testEmail, $testPassword));
}
public function testRegisterFail () {
$userStorage = $this->getMockBuilder(UserStorage::class)
->disableOriginalConstructor()
->setMethods(["save"])
->getMock();
$userStorage->expects($this->once())->method("save")->willReturn(false);
$user = new User($userStorage);
$testEmail = "aaaaa@wp.pl";
$testPassword = "123456";
$this->assertFalse($user->register($testEmail, $testPassword));
}
public function testRegisterValidationFail () {
$userStorage = $this->getMockBuilder(UserStorage::class)
->disableOriginalConstructor()
->setMethods(["save"])
->getMock();
$userStorage->expects($this->never())->method("save");
$user = new User($userStorage);
$wrongEmail = "aa";
$rightEmail = "aaaa@wp.pl";
$wrongPassword = "12";
$rightPassword = "123456";
$this->assertFalse($user->register($wrongEmail, $wrongPassword));
$this->assertFalse($user->register($wrongEmail, $rightPassword));
$this->assertFalse($user->register($rightEmail, $wrongPassword));
}
}