@@ -76,4 +76,41 @@ public function clientGetsDefinedIfNotSpecified(): void
7676 $ pushGateway = new PushGateway ('http://foo.bar ' );
7777 $ pushGateway ->push ($ mockedCollectorRegistry , 'foo ' );
7878 }
79+
80+ /**
81+ * @test
82+ *
83+ * @dataProvider validAddressAndRequestsProvider
84+ */
85+ public function validAddressShouldCreateValidRequests (string $ address , string $ scheme , string $ host , int $ port ): void
86+ {
87+ $ mockedCollectorRegistry = $ this ->createMock (CollectorRegistry::class);
88+ $ mockedCollectorRegistry ->method ('getMetricFamilySamples ' )->with ()->willReturn ([
89+ $ this ->createMock (MetricFamilySamples::class)
90+ ]);
91+
92+ $ mockHandler = new MockHandler ([
93+ new Response (200 ),
94+ ]);
95+ $ handler = HandlerStack::create ($ mockHandler );
96+ $ client = new Client (['handler ' => $ handler ]);
97+
98+ $ pushGateway = new PushGateway ($ address , $ client );
99+ $ pushGateway ->push ($ mockedCollectorRegistry , 'foo ' );
100+
101+ $ uri = $ mockHandler ->getLastRequest ()->getUri ();
102+ $ this ->assertEquals ($ scheme , $ uri ->getScheme ());
103+ $ this ->assertEquals ($ host , $ uri ->getHost ());
104+ $ this ->assertEquals ($ port , $ uri ->getPort ());
105+ $ this ->assertEquals ('/metrics/job/foo ' , $ uri ->getPath ());
106+ }
107+
108+ public function validAddressAndRequestsProvider ()
109+ {
110+ return [
111+ ['foo.bar:123 ' , 'http ' , 'foo.bar ' , 123 ],
112+ ['http://foo.bar:123 ' , 'http ' , 'foo.bar ' , 123 ],
113+ ['https://foo.bar:123 ' , 'https ' , 'foo.bar ' , 123 ],
114+ ];
115+ }
79116}
0 commit comments