@@ -708,4 +708,55 @@ public function testCreateClientWillCancelTimerWhenConnectionRejects(): void
708708
709709 $ deferred ->reject (new \RuntimeException ());
710710 }
711+
712+ public function testWillWriteAuthCommandIfTargetContainsUsernameAndPasswordQueryParameter (): void
713+ {
714+ $ stream = $ this ->createMock (ConnectionInterface::class);
715+ $ stream ->expects ($ this ->once ())->method ('write ' )->with ("*3 \r\n$4 \r\nauth \r\n$5 \r\nhello \r\n$5 \r\nworld \r\n" );
716+
717+ $ loop = $ this ->createMock (LoopInterface::class);
718+ $ loop ->expects ($ this ->once ())->method ('addTimer ' );
719+ assert ($ loop instanceof LoopInterface);
720+ Loop::set ($ loop );
721+
722+ $ this ->connector
723+ ->expects ($ this ->once ())
724+ ->method ('connect ' )
725+ ->with ('example.com:6379 ' )
726+ ->willReturn (resolve ($ stream ));
727+
728+ $ this ->factory ->createClient (
729+ 'redis://example.com?username=hello&password=world '
730+ );
731+ }
732+
733+ public function testWillResolveWhenAuthCommandReceivesOkResponseWithUsernameAndPassword (): void
734+ {
735+ $ dataHandler = null ;
736+ $ stream = $ this ->createMock (ConnectionInterface::class);
737+ $ stream ->expects ($ this ->once ())->method ('write ' )->with ("*3 \r\n$4 \r\nauth \r\n$4 \r\nuser \r\n$4 \r\npass \r\n" );
738+ $ stream ->expects ($ this ->exactly (2 ))->method ('on ' )->withConsecutive (
739+ ['data ' , $ this ->callback (function ($ cb ) use (&$ dataHandler ) {
740+ $ dataHandler = $ cb ;
741+ return true ;
742+ })],
743+ ['close ' , $ this ->anything ()]
744+ );
745+
746+ $ this ->connector
747+ ->expects ($ this ->once ())
748+ ->method ('connect ' )
749+ ->willReturn (resolve ($ stream ));
750+
751+ $ promise = $ this ->factory ->createClient (
752+ 753+ );
754+
755+ $ this ->assertTrue (is_callable ($ dataHandler ));
756+ $ dataHandler ("+OK \r\n" );
757+
758+ $ promise ->then ($ this ->expectCallableOnceWith (
759+ $ this ->isInstanceOf (StreamingClient::class)
760+ ));
761+ }
711762}
0 commit comments