@@ -616,21 +616,16 @@ public function nextId(): string
616616 };
617617
618618 $ service = new DomainService ($ transport , null , $ generator );
619- $ result = $ service ->renew ([
620- 'currentExpirationDate ' => '2027-02-01 ' ,
621- 'name ' => 'example.rs ' ,
622- 'period ' => 1 ,
623- 'periodUnit ' => 'y ' ,
624- ]);
619+ $ result = $ service ->renew ('example.rs ' , 1 , '2027-02-01 ' );
625620
626621 self ::assertStringContainsString ('<domain:renew ' , $ transport ->writtenPayload );
627622 self ::assertStringContainsString (
628623 '<domain:curExpDate>2027-02-01</domain:curExpDate> ' ,
629624 $ transport ->writtenPayload ,
630625 );
631- self ::assertSame ('example.rs ' , $ result ['name ' ]);
632- self ::assertInstanceOf (\DateTimeImmutable::class, $ result ['expirationDate ' ]);
633- self ::assertSame ('2028-02-01T00:00:00+00:00 ' , $ result ['expirationDate ' ]?->format('c ' ));
626+ self ::assertSame ('example.rs ' , $ result ['domain ' ]);
627+ self ::assertInstanceOf (\DateTimeImmutable::class, $ result ['expiryDate ' ]);
628+ self ::assertSame ('2028-02-01T00:00:00+00:00 ' , $ result ['expiryDate ' ]?->format('c ' ));
634629 }
635630
636631 public function testDeleteSendsDomainDeleteCommandAndMapsParsedResponse (): void
@@ -751,8 +746,126 @@ public function readFrame(): string
751746 '<domain:period unit="y">1</domain:period> ' ,
752747 $ transport ->writtenPayload ,
753748 );
754- self ::assertInstanceOf (\DateTimeImmutable::class, $ result ['expirationDate ' ]);
755- self ::assertSame ('2028-02-01T00:00:00+00:00 ' , $ result ['expirationDate ' ]?->format('c ' ));
749+ self ::assertSame ('example.rs ' , $ result ['domain ' ]);
750+ self ::assertInstanceOf (\DateTimeImmutable::class, $ result ['expiryDate ' ]);
751+ self ::assertSame ('2028-02-01T00:00:00+00:00 ' , $ result ['expiryDate ' ]?->format('c ' ));
752+ }
753+
754+ public function testRenewAcceptsDateTimeInterfaceExpiry (): void
755+ {
756+ $ transport = new class () implements Transport {
757+ public string $ writtenPayload = '' ;
758+
759+ public function connect (): void
760+ {
761+ // Not needed for this unit test.
762+ }
763+
764+ public function disconnect (): void
765+ {
766+ // Not needed for this unit test.
767+ }
768+
769+ public function writeFrame (string $ payload ): void
770+ {
771+ $ this ->writtenPayload = $ payload ;
772+ }
773+
774+ public function readFrame (): string
775+ {
776+ return '<?xml version="1.0" encoding="UTF-8"?> '
777+ . '<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"> '
778+ . '<response> '
779+ . '<result code="1000"><msg>Command completed successfully</msg></result> '
780+ . '<resData> '
781+ . '<domain:renData xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"> '
782+ . '<domain:name>example.rs</domain:name> '
783+ . '<domain:exDate>2028-02-01T00:00:00.0Z</domain:exDate> '
784+ . '</domain:renData> '
785+ . '</resData> '
786+ . '<trID><clTRID>DOMAIN-00000012</clTRID><svTRID>SV-12</svTRID></trID> '
787+ . '</response> '
788+ . '</epp> ' ;
789+ }
790+ };
791+
792+ $ service = new DomainService ($ transport );
793+ $ service ->renew ('example.rs ' , 1 , new \DateTimeImmutable ('2027-02-01T08:00:00+01:00 ' ));
794+
795+ self ::assertStringContainsString (
796+ '<domain:curExpDate>2027-02-01</domain:curExpDate> ' ,
797+ $ transport ->writtenPayload ,
798+ );
799+ }
800+
801+ public function testRenewThrowsWhenYearsAreOutsideAllowedRange (): void
802+ {
803+ $ transport = new class () implements Transport {
804+ public function connect (): void
805+ {
806+ // Not needed for this unit test.
807+ }
808+
809+ public function disconnect (): void
810+ {
811+ // Not needed for this unit test.
812+ }
813+
814+ public function writeFrame (string $ payload ): void
815+ {
816+ // Not needed for this unit test.
817+ }
818+
819+ public function readFrame (): string
820+ {
821+ return '' ;
822+ }
823+ };
824+
825+ $ service = new DomainService ($ transport );
826+
827+ $ this ->expectException (\InvalidArgumentException::class);
828+ $ this ->expectExceptionMessage ('Domain renew years must be between 1 and 10. ' );
829+
830+ $ service ->renew ('example.rs ' , 11 , '2027-02-01 ' );
831+ }
832+
833+ public function testRenewThrowsProtocolExceptionWhenExpiryDoesNotMatchRegistryState (): void
834+ {
835+ $ transport = new class () implements Transport {
836+ public function connect (): void
837+ {
838+ // Not needed for this unit test.
839+ }
840+
841+ public function disconnect (): void
842+ {
843+ // Not needed for this unit test.
844+ }
845+
846+ public function writeFrame (string $ payload ): void
847+ {
848+ // Not needed for this unit test.
849+ }
850+
851+ public function readFrame (): string
852+ {
853+ return '<?xml version="1.0" encoding="UTF-8"?> '
854+ . '<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"> '
855+ . '<response> '
856+ . '<result code="2306"><msg>Current expiration date does not match object state</msg></result> '
857+ . '<trID><clTRID>DOMAIN-00000013</clTRID><svTRID>SV-13</svTRID></trID> '
858+ . '</response> '
859+ . '</epp> ' ;
860+ }
861+ };
862+
863+ $ service = new DomainService ($ transport );
864+
865+ $ this ->expectException (\RNIDS \Exception \ProtocolException::class);
866+ $ this ->expectExceptionMessage ('EPP command failed with result code 2306 ' );
867+
868+ $ service ->renew ('example.rs ' , 1 , '2027-02-01 ' );
756869 }
757870
758871 public function testTransferApprovesDomainTransferAndMapsParsedResponse (): void
0 commit comments