Could not find wrapper when inspecting a call to Guzzle with PHPUnit

I am writing a unit test for an API that I am developing. The API is written within Codeigniter, which calls another API using Guzzle. The test I am writing is verifying that the API call returns the correct response.

The Test.php file contains the following code

require '/application/libraries/apiWrappers/Breathehr.php';

class BreathehrTest extends PHPUnit_Framework_TestCase {

    public function testCanReturnEmployeeArray() {
        $breatheHR = new Breathehr();

        $employees = $breatheHR->list_employees(1);
        $this->assertArrayHasKey('employees', $employees);
    }


}

      

The method that is being tested is as follows

class Breathehr {

    function __construct() {

    }

    public function list_employees($page)
    {
        $client = new GuzzleHttp\Client(
            ['base_uri' => 'https://xxx/',
                'headers' => ['X-API-KEY' => 'xxx'],
                'verify' => false]
        );

        $request = $client->get('employees?page='.$page);
        $employees = json_decode($request->getBody(true));

        $employeeData = array(
            'employees' => array(),
            'pagination' => array()
        );

        $i = 0;
        foreach($employees->employees as $employee) {
            if($employee->status !== 'Ex-employee') {
                $employeeData['employees'][$i]['firstName'] = $employee->first_name;
                $employeeData['employees'][$i]['lastName'] = $employee->last_name;
                $employeeData['employees'][$i]['jobTitle'] = $employee->job_title;
                if(isset($employee->line_manager)) {
                    $employeeData['employees'][$i]['lineManagerName'] = $employee->line_manager->first_name . ' '. $employee->line_manager->last_name;
                    $employeeData['employees'][$i]['lineManagerID'] = $employee->line_manager->id;
                }
                $employeeData['employees'][$i]['workingHours'] = $employee->full_or_part_time;
                $employeeData['employees'][$i]['email'] = $employee->email;
                $employeeData['employees'][$i]['workPhone'] = $employee->ddi;
                $employeeData['employees'][$i]['personalMobile'] = $employee->personal_mobile;
                $employeeData['employees'][$i]['homeTelephone'] = $employee->home_telephone;
                $employeeData['employees'][$i]['birthday'] = $employee->dob;
                $i++;
            }
        }

        $nextLink = $request->getHeader('Link');
        $nextLinkSplit = explode(',', $nextLink[0]);

        $pageination = array();

        foreach($nextLinkSplit as $data) {
            $split = explode(';', $data);
            preg_match('/"(.*?)"/', $split[1], $keyMatch);
            $key = isset($keyMatch[1]) ? $keyMatch[1] : FALSE;
            $number = substr($split[0], -2, 1);

            $pageination[$key] = $number;
        }

        array_push($employeeData['pagination'], $pageination);

        return $employeeData;
    }

}

      

The API call works correctly through Postman and from the browser, but the result of running PHPUnit from the command line is

RuntimeException: Resource creation error: [message] fopen (): Unable to find the "https" wrapper - did you forget to include it when you configured PHP?

[message] fopen ( https://api.breathehr.com/v1/employees?page=1 ): failed to open stream: no such file or directory

I posted a bug in the bug report and came across this SO message <Could not find wrapper "https" - Did you forget to enable it when configuring PHP?

Making these changes made no difference. It's worth mentioning this on localhost by running MAMP.

Any ideas?

thank

+3


source to share


1 answer


When the CLI is using a different php.ini

one than Apache, so your settings made in the WAMP menu don't apply to the CLI.

Check if the correct extension is loaded by running

command php -i | grep ssl 

      



In the same way, you can find the php.ini script:

php -i | grep ini

      

hope this help

+3


source







All Articles