File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
src/Symfony/Component/Uid Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -94,6 +94,22 @@ public function testEquals()
94
94
$ this ->assertFalse ($ uuid1 ->equals ($ uuid2 ));
95
95
}
96
96
97
+ /**
98
+ * @dataProvider provideInvalidEqualType
99
+ */
100
+ public function testEqualsAgainstOtherType ($ other )
101
+ {
102
+ $ this ->assertFalse ((new Uuid (self ::A_UUID_V4 ))->equals ($ other ));
103
+ }
104
+
105
+ public function provideInvalidEqualType ()
106
+ {
107
+ yield [null ];
108
+ yield [self ::A_UUID_V1 ];
109
+ yield [self ::A_UUID_V4 ];
110
+ yield [new \stdClass ()];
111
+ }
112
+
97
113
public function testCompare ()
98
114
{
99
115
$ uuids = [];
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ public function __construct(string $uuid = null)
42
42
throw new \InvalidArgumentException (sprintf ('Invalid UUID: "%s". ' , $ uuid ));
43
43
}
44
44
45
- $ this ->uuid = $ uuid ;
45
+ $ this ->uuid = strtr ( $ uuid, ' ABCDEF ' , ' abcdef ' ) ;
46
46
}
47
47
48
48
public static function v1 (): self
@@ -85,8 +85,15 @@ public function isNull(): bool
85
85
return uuid_is_null ($ this ->uuid );
86
86
}
87
87
88
- public function equals (self $ other ): bool
88
+ /**
89
+ * Returns whether the argument is of class Uuid and contains the same value as the current instance.
90
+ */
91
+ public function equals ($ other ): bool
89
92
{
93
+ if (!$ other instanceof self) {
94
+ return false ;
95
+ }
96
+
90
97
return 0 === uuid_compare ($ this ->uuid , $ other ->uuid );
91
98
}
92
99
You can’t perform that action at this time.
0 commit comments