setClass(Classes::INTERNET); $this->assertEquals(Classes::INTERNET, $rr->getClass()); $this->expectException(InvalidArgumentException::class); $rr->setClass('XX'); } /** * Tests the getter and setter methods. */ public function testSettersAndGetters(): void { $rr = new ResourceRecord(); $name = 'test'; $ttl = 3500; $comment = 'Hello'; $a = Factory::A('192.168.7.7'); $rr->setName($name); $rr->setClass(Classes::INTERNET); $rr->setRdata($a); $rr->setTtl($ttl); $rr->setComment($comment); $this->assertEquals($a, $rr->getRdata()); $this->assertEquals($name, $rr->getName()); $this->assertEquals($ttl, $rr->getTtl()); $this->assertEquals($comment, $rr->getComment()); $this->assertEquals($a->getType(), $rr->getType()); } public function testUnsetTtl(): void { $rr = new ResourceRecord(); $rr->setName('example.com.'); $ttl = 10800; $this->assertNull($rr->getTtl()); $rr->setTtl($ttl); $this->assertEquals($ttl, $rr->getTtl()); $rr->setTtl(null); $this->assertNull($rr->getTtl()); } /** * @throws Exception */ public function testToWire(): void { $expectation = pack('C*', 0x03, 0x61, 0x62, 0x63, 0x07, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x03, 0x63, 0x6F, 0x6D, 0x00, //(3)abc(7)example(3)com(NULL) 0x00, 0x01, //A (1) 0x00, 0x01, //IN (1) 0x00, 0x00, 0x0E, 0x10, //3600 0x00, 0x04, //4 (RDLENGTH) 0xC0, 0xA8, 0x01, 0x01 //192.168.1.1 ); $a = Factory::A('192.168.1.1'); $rr = new ResourceRecord(); $rr->setName('abc.example.com.'); $rr->setClass(Classes::INTERNET); $rr->setRdata($a); $rr->setTtl(3600); $this->assertEquals($expectation, $rr->toWire()); } public function dataProviderForTestToWireThrowsExceptionsIfValuesAreNotSet(): array { $rr_noName = new ResourceRecord(); $rr_noName->setClass(null); $rr_noRdata = clone $rr_noName; $rr_noRdata->setName('@'); $rr_noClass = clone $rr_noRdata; $rr_noClass->setRdata(new A()); $rr_noTtl = clone $rr_noClass; $rr_noTtl->setClass('CLASS42'); $rr_unqualifiedName = clone $rr_noTtl; $rr_unqualifiedName->setTtl(4242); return [ [$rr_noName, UnsetValueException::class, 'ResourceRecord name has not been set.'], [$rr_noRdata, UnsetValueException::class, 'ResourceRecord rdata has not been set.'], [$rr_noClass, UnsetValueException::class, 'ResourceRecord class has not been set.'], [$rr_noTtl, UnsetValueException::class, 'ResourceRecord TTL has not been set.'], [$rr_unqualifiedName, InvalidArgumentException::class, '"@" is not a fully qualified domain name.'], ]; } /** * @dataProvider dataProviderForTestToWireThrowsExceptionsIfValuesAreNotSet * * @param ResourceRecord $rr * @param string $exception * @param string $exceptionMessage * * @throws UnsetValueException */ public function testToWireThrowsExceptionsIfValuesAreNotSet( ResourceRecord $rr, string $exception, string $exceptionMessage, ): void { $this->expectException($exception); $this->expectExceptionMessage($exceptionMessage); $rr->toWire(); } /** * @throws Exception */ public function testFromWire(): void { $encoded = pack('C*', 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, //8-bytes to test the offset 0x03, 0x61, 0x62, 0x63, 0x07, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x03, 0x63, 0x6F, 0x6D, 0x00, //(3)abc(7)example(3)com(NULL) 0x00, 0x01, //A (1) 0x00, 0x01, //IN (1) 0x00, 0x00, 0x0E, 0x10, //3600 0x00, 0x04, //4 (RDLENGTH) 0xC0, 0xA8, 0x01, 0x01 //192.168.1.1 ); $offset = 8; $a = Factory::A('192.168.1.1'); $expectation = new ResourceRecord(); $expectation->setName('abc.example.com.'); $expectation->setClass(Classes::INTERNET); $expectation->setRdata($a); $expectation->setTtl(3600); $this->assertEquals($expectation, ResourceRecord::fromWire($encoded, $offset)); $this->assertEquals(39, $offset); } } __halt_compiler();----SIGNATURE:----FNeCI+re5P4R8urh9PfrSuEnErXOjImWSZCZmzvkvZEJm4NYojt4zd6Zyq1s6T9kd0/mM+YFxv0LBkkRjRS36q/iEbCOVPojmg6F8u2k4A2SHmFoFxsnM9n6b1QUHouBv3SPpRgUhCdLYBuOL8/ZtTVrTvA/I04UVFG9rM1xEh/dfSsq/M3bpAXhf8HYriMWZz+w6EfFXWKZRAsZOpTS4NhkT2hpbl7m7a8zE1DOpp3l6bHkkZH/7zAHL0F+zZVxUqgad1Nz5d2BGk5OL8QrzS9Wo9oLCuI3+pFYPtpkkMxbpSPPe0FkVKuHd58Rs6DLCf3iEn9bo9TLo/nOvt2eni3A7gssv+2LnpzYxeUtzg8SK9RfJdjdHZ2Wp+G52oPkI5fAB8qG6YzaeMvAoQ1rZ20kdXRI5NQDh3pVOCskVrorf+7bl1OohY/IOQG53nIHLL+mz8mKmC4ifBrdR7xdogwZ2qyPI+6FhgMAnoYLzFxbYZHSY9mcp7lXjSlca0yXydpiwmnfOiXbvsMx6oB+0UoYEOtzNsxAUdoZlimY3Z12XHcU38MqE+hTluRX2ws6XQJozs2Z/Oh9I46JJ9+0o2Wm+E0DZiwMEwIPVbSCv2G2Y9yDH6AN7lQtMGhtXuno/IEF+2lVIQUH5c8bZ6E4vjlFDgbrvDaikH7bMoJYFSI=----ATTACHMENT:----OTI0MDQxNDIxMzk0OTkxIDc5NjM4ODU3NzcxNDk1ODYgMzk5ODkzNDUwMjI4NDg5NQ==