@@ -162,29 +162,46 @@ public static function unexpectedValueForIdFieldDataProvider(): iterable
162162 ];
163163 }
164164
165- public function testConstructorThrowsIfIpAddressArgumentIsInvalid (): void
165+ /**
166+ * @dataProvider bracketedIpv6AddressDataProvider
167+ */
168+ public function testSetIpAddressStripsBracketsFromIpv6 (string $ input , string $ expected ): void
166169 {
167- $ this -> expectException (\InvalidArgumentException::class );
168- $ this -> expectExceptionMessage ( ' The "foo" value is not a valid IP address. ' );
170+ $ userDataBag = new UserDataBag ( );
171+ $ userDataBag -> setIpAddress ( $ input );
169172
170- new UserDataBag (null , null , 'foo ' );
173+ $ this ->assertSame ($ expected , $ userDataBag ->getIpAddress ());
174+ }
175+
176+ public static function bracketedIpv6AddressDataProvider (): iterable
177+ {
178+ yield 'IPv6 loopback with brackets ' => ['[::1] ' , '::1 ' ];
179+ yield 'IPv6 full address with brackets ' => ['[2001:db8::1] ' , '2001:db8::1 ' ];
180+ yield 'IPv6 loopback without brackets ' => ['::1 ' , '::1 ' ];
181+ yield 'IPv4 address ' => ['127.0.0.1 ' , '127.0.0.1 ' ];
171182 }
172183
173- public function testSetIpAddressThrowsIfArgumentIsInvalid (): void
184+ public function testConstructorDoesNotSetInvalidIpAddress (): void
174185 {
175- $ this ->expectException (\InvalidArgumentException::class);
176- $ this ->expectExceptionMessage ('The "foo" value is not a valid IP address. ' );
186+ $ userDataBag = new UserDataBag (null , null , 'foo ' );
177187
188+ $ this ->assertNull ($ userDataBag ->getIpAddress ());
189+ }
190+
191+ public function testSetIpAddressDoesNotSetInvalidIpAddress (): void
192+ {
178193 $ userDataBag = new UserDataBag ();
194+ $ userDataBag ->setIpAddress ('127.0.0.1 ' );
179195 $ userDataBag ->setIpAddress ('foo ' );
196+
197+ $ this ->assertSame ('127.0.0.1 ' , $ userDataBag ->getIpAddress ());
180198 }
181199
182- public function testCreateFromIpAddressThrowsIfArgumentIsInvalid (): void
200+ public function testCreateFromIpAddressDoesNotSetInvalidIpAddress (): void
183201 {
184- $ this ->expectException (\InvalidArgumentException::class);
185- $ this ->expectExceptionMessage ('The "foo" value is not a valid IP address. ' );
202+ $ userDataBag = UserDataBag::createFromUserIpAddress ('foo ' );
186203
187- UserDataBag:: createFromUserIpAddress ( ' foo ' );
204+ $ this -> assertNull ( $ userDataBag -> getIpAddress () );
188205 }
189206
190207 public function testMerge (): void
0 commit comments