55namespace Flow \ETL \Adapter \GoogleSheet \Tests \Integration ;
66
77use function Flow \ETL \DSL \{config , flow_context };
8- use Flow \ETL \Adapter \GoogleSheet \{Columns , GoogleSheetExtractor };
8+ use Flow \ETL \Adapter \GoogleSheet \{Columns , GoogleSheetExtractor , Tests \ GoogleSheetsContext };
99use Flow \ETL \Exception \InvalidArgumentException ;
1010use Flow \ETL \Tests \FlowTestCase ;
11- use Google \Client as GoogleClient ;
12- use Google \Service \Sheets ;
13- use GuzzleHttp \{Client , HandlerStack };
14- use GuzzleHttp \Handler \MockHandler ;
15- use GuzzleHttp \Psr7 \{Response };
1611
1712final class GoogleSheetExtractorTest extends FlowTestCase
1813{
19- public function test_extract_with_cut_extra_columns () : void
14+ private GoogleSheetsContext $ context ;
15+
16+ protected function setUp () : void
2017 {
21- $ client = new GoogleClient ();
22- $ client -> setHttpClient ( $ this -> createHttpClient ());
18+ $ this -> context = new GoogleSheetsContext ();
19+ }
2320
21+ public function test_extract_with_cut_extra_columns () : void
22+ {
2423 $ extractor = new GoogleSheetExtractor (
25- new Sheets ( $ client ),
24+ $ this -> context -> sheets ( __DIR__ . ' /../Fixtures/extra-columns.json ' ),
2625 '1234567890 ' ,
2726 new Columns ('Sheet ' , 'A ' , 'Z ' ),
2827 );
@@ -36,11 +35,8 @@ public function test_extract_with_cut_extra_columns() : void
3635
3736 public function test_extract_without_cut_extra_columns () : void
3837 {
39- $ client = new GoogleClient ();
40- $ client ->setHttpClient ($ this ->createHttpClient ());
41-
4238 $ extractor = new GoogleSheetExtractor (
43- new Sheets ( $ client ),
39+ $ this -> context -> sheet ( __DIR__ . ' /../Fixtures/extra-columns.json ' ),
4440 '1234567890 ' ,
4541 new Columns ('Sheet ' , 'A ' , 'Z ' ),
4642 );
@@ -55,23 +51,4 @@ public function test_extract_without_cut_extra_columns() : void
5551 self ::assertNotNull ($ row );
5652 }
5753 }
58-
59- private function createHttpClient () : Client
60- {
61- return new Client (
62- [
63- 'handler ' => HandlerStack::create (
64- new MockHandler (
65- [
66- new Response (
67- 200 ,
68- ['Content-Type ' => 'application/json ' ],
69- file_get_contents (__DIR__ . '/../Fixtures/extra-columns.json ' ) ?: throw new \RuntimeException ('Failed to read file ' )
70- ),
71- ]
72- )
73- ),
74- ]
75- );
76- }
7754}
0 commit comments