assertNull($this->behavior()->retrieveProperty(null, static::COLUMN)); $this->assertNull($this->behavior(true)->retrieveProperty(null, static::COLUMN)); } public function testFromDBTransformsBinaryIpToHumanReadable() { $this->assertSame( static::IPV4, $this->behavior()->retrieveProperty(hex2bin(static::IPV4_HEX), static::COLUMN) ); $this->assertSame( static::IPV6, $this->behavior()->retrieveProperty(hex2bin(static::IPV6_HEX), static::COLUMN) ); $this->assertSame( static::IPV4, $this->behavior(true)->retrieveProperty(hex2bin(static::IPV4_HEX), static::COLUMN) ); $this->assertSame( static::IPV6, $this->behavior(true)->retrieveProperty(hex2bin(static::IPV6_HEX), static::COLUMN) ); } public function testToDbReturnsInvalidValueAsIs() { $this->assertNull($this->behavior()->persistProperty(null, static::COLUMN)); $this->assertSame('*', $this->behavior()->persistProperty('*', static::COLUMN)); $this->assertNull($this->behavior(true)->persistProperty(null, static::COLUMN)); $this->assertSame('*', $this->behavior(true)->persistProperty('*', static::COLUMN)); $ipv4Bin = hex2bin(static::IPV4_HEX); $ipv6Bin = hex2bin(static::IPV6_HEX); $this->assertSame($ipv4Bin, $this->behavior()->persistProperty($ipv4Bin, static::COLUMN)); $this->assertSame($ipv6Bin, $this->behavior()->persistProperty($ipv6Bin, static::COLUMN)); $this->assertSame($ipv4Bin, $this->behavior(true)->persistProperty($ipv4Bin, static::COLUMN)); $this->assertSame($ipv6Bin, $this->behavior(true)->persistProperty($ipv6Bin, static::COLUMN)); } public function testToDbTransformsIpToBinaryCorrectly() { $this->assertSame(hex2bin(static::IPV4_HEX), $this->behavior()->persistProperty(static::IPV4, static::COLUMN)); $this->assertSame(hex2bin(static::IPV6_HEX), $this->behavior()->persistProperty(static::IPV6, static::COLUMN)); $this->assertSame( sprintf('\\x%s', static::IPV4_HEX), $this->behavior(true)->persistProperty(static::IPV4, static::COLUMN) ); $this->assertSame( sprintf('\\x%s', static::IPV6_HEX), $this->behavior(true)->persistProperty(static::IPV6, static::COLUMN) ); } protected function behavior(bool $postgres = false): Ip { return (new Ip(['ip'])) ->setQuery( (new Query()) ->setDb(new Connection(['db' => $postgres ? 'pgsql' : 'mysql'])) ); } }