php - PHPUnit testing, simulate call to external API -


i have class follows

class accountsprocessor{       protected $remoteaccountdata = [];     /**      * process data passed input array      */     public function process($inputcsv): array     {         $this->loadremotedata($inputcsv);         return $this->remoteaccountdata;      }      /**      * given data retrieved local csv file, iterate each account, retrieve status info server      * , save result instance variable array remoteaccountdata      *      * @param $inputcsv      */     protected function loadremotedata($inputcsv)     {         foreach ($inputcsv $account)         {             // lookup status data on remote server account , add remoteaccountdata array             $this->remoteaccountdata["{$account[0]}"]                   = $this->callapi("get", "http://examplurl.com/v1/accounts/{$account[0]}");         }     }      /**      * curl call remote server retrieve missing status data on each account      *      * @param $method      * @param $url      * @param bool $data      * @return mixed      */     private function callapi($method, $url, $data = false)     {         ..... internal code ...     } } 

the class has public process method accepts array , passes on protected function iterates each account in array , makes call external api using curl

my question this, when unit testing class want test process method public method, others private or protected.

i can so:

protected $processor;  protected function setup() {     $this->processor = new accountsprocessor(); } /** @test */ public function it_works_with_correctly_formatted_data() {      $inputcsv = [         ["12345", "beedge", "kevin", "5/24/16"],         ["8172", "joe", "bloggs", "1/1/12"]     ];      $processeddata = $this->processor->process($inputcsv);     $this->assertequals("good", $processeddata[0][3]); } 

but running test makes call external api

how can simulate call private function callapi() ?


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -