1010use GuzzleHttp \Psr7 \Request ;
1111use GuzzleHttp \Psr7 \Response ;
1212use MarketDataApp \Client ;
13+ use MarketDataApp \Endpoints \Responses \IndicesCandle ;
14+ use MarketDataApp \Endpoints \Responses \IndicesCandles ;
1315use MarketDataApp \Endpoints \Responses \IndicesQuote ;
1416use PHPUnit \Framework \TestCase ;
1517
@@ -39,7 +41,7 @@ public function testIndicesQuote_success()
3941 ];
4042 $ this ->setMockResponses ([new Response (200 , [], json_encode ($ mocked_response ))]);
4143
42- $ response = $ this ->client ->indices ->quote ("AAPL " );
44+ $ response = $ this ->client ->indices ->quote ("DJI " );
4345 $ this ->assertInstanceOf (IndicesQuote::class, $ response );
4446 $ this ->assertEquals ($ mocked_response ['s ' ], $ response ->status );
4547 $ this ->assertEquals ($ mocked_response ['symbol ' ][0 ], $ response ->symbol );
@@ -51,6 +53,40 @@ public function testIndicesQuote_success()
5153 $ this ->assertEquals (Carbon::parse ($ mocked_response ['updated ' ]), $ response ->updated );
5254 }
5355
56+ public function testIndicesCandles_fromTo_success ()
57+ {
58+ $ mocked_response = [
59+ 's ' => 'ok ' ,
60+ 'c ' => [22.84 , 23.93 , 21.95 , 21.44 , 21.15 ],
61+ 'h ' => [23.27 , 24.68 , 23.92 , 22.66 , 22.58 ],
62+ 'l ' => [22.26 , 22.67 , 21.68 , 21.44 , 20.76 ],
63+ 'o ' => [22.41 , 24.08 , 23.86 , 22.06 , 21.5 ],
64+ 't ' => [1659326400 , 1659412800 , 1659499200 , 1659585600 , 1659672000 ]
65+ ];
66+ $ this ->setMockResponses ([new Response (200 , [], json_encode ($ mocked_response ))]);
67+
68+ $ response = $ this ->client ->indices ->candles (
69+ symbol: "DJI " ,
70+ from: Carbon::parse ('2022-09-01 ' ),
71+ to: Carbon::parse ('2022-09-05 ' ),
72+ resolution: 'D '
73+ );
74+
75+ // Verify that the response is an object of the correct type.
76+ $ this ->assertInstanceOf (IndicesCandles::class, $ response );
77+ $ this ->assertCount (5 , $ response ->candles );
78+
79+ // Verify each item in the response is an object of the correct type and has the correct values.
80+ for ($ i = 0 ; $ i < count ($ response ->candles ); $ i ++) {
81+ $ this ->assertInstanceOf (IndicesCandle::class, $ response ->candles [$ i ]);
82+ $ this ->assertEquals ($ mocked_response ['c ' ][$ i ], $ response ->candles [$ i ]->close );
83+ $ this ->assertEquals ($ mocked_response ['h ' ][$ i ], $ response ->candles [$ i ]->high );
84+ $ this ->assertEquals ($ mocked_response ['l ' ][$ i ], $ response ->candles [$ i ]->low );
85+ $ this ->assertEquals ($ mocked_response ['o ' ][$ i ], $ response ->candles [$ i ]->open );
86+ $ this ->assertEquals (Carbon::parse ($ mocked_response ['t ' ][$ i ]), $ response ->candles [$ i ]->timestamp );
87+ }
88+ }
89+
5490 public function testExceptionHandling_throwsGuzzleException ()
5591 {
5692 $ this ->setMockResponses ([
0 commit comments