File tree Expand file tree Collapse file tree 2 files changed +98
-0
lines changed
Expand file tree Collapse file tree 2 files changed +98
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * This software was built by:
4+ * Daniel Tomé Fernández <danieltomefer@gmail.com>
5+ * GitHub: danitome24
6+ */
7+
8+ namespace PhpValueObject \User ;
9+
10+ use PhpValueObject \ValueObject ;
11+
12+ final class Password implements ValueObject
13+ {
14+ /**
15+ * @var string
16+ */
17+ private $ pwd ;
18+
19+ /**
20+ * Password constructor.
21+ * @param string $pwd
22+ */
23+ private function __construct (string $ pwd )
24+ {
25+ $ this ->pwd = $ pwd ;
26+ }
27+
28+ /**
29+ * Named constructor
30+ *
31+ * @param string $pwd
32+ * @return static
33+ */
34+ public static function build (string $ pwd )
35+ {
36+ return new static ($ pwd );
37+ }
38+
39+ /**
40+ * @return string
41+ */
42+ public function pwd (): string
43+ {
44+ return $ this ->pwd ;
45+ }
46+
47+ /**
48+ * Compare a value object with another one.
49+ *
50+ * @param static|ValueObject $valueObjectToCompare
51+ * @return bool
52+ */
53+ public function equals (ValueObject $ valueObjectToCompare ): bool
54+ {
55+ return ($ this ->pwd () === $ valueObjectToCompare ->pwd ());
56+ }
57+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * This software was built by:
4+ * Daniel Tomé Fernández <danieltomefer@gmail.com>
5+ * GitHub: danitome24
6+ */
7+
8+ namespace Test \User ;
9+
10+ use PHPUnit \Framework \TestCase ;
11+ use PhpValueObject \User \Password ;
12+
13+ class PasswordTest extends TestCase
14+ {
15+
16+ public function testPasswordIsValid ()
17+ {
18+ $ passwd = 'somepassword ' ;
19+ $ pwd = Password::build ($ passwd );
20+ $ this ->assertEquals ($ passwd , $ pwd ->pwd ());
21+ }
22+
23+ /**
24+ * @dataProvider passwords
25+ * @param Password $pwd
26+ * @param Password $pwdToCompare
27+ * @param bool $isEquals
28+ */
29+ public function testPasswordIsEqualsMethod (Password $ pwd , Password $ pwdToCompare , bool $ isEquals )
30+ {
31+ $ this ->assertEquals ($ pwd ->equals ($ pwdToCompare ), $ isEquals );
32+ }
33+
34+ public function passwords ()
35+ {
36+ return [
37+ [Password::build ('somepwd ' ), Password::build ('somepwd ' ), true ],
38+ [Password::build ('somepwd ' ), Password::build ('somepwddif ' ), false ]
39+ ];
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments