src/Context/ApiContext.php
public function addMultipartFileToRequest($path, $partName) {
        if (!file_exists($path)) {
            throw new InvalidArgumentException(sprintf('File does not exist: "%s"', $path));
        }

        // Create the multipart entry in the request options if it does not already exist
        if (!isset($this->requestOptions['multipart'])) {
            $this->requestOptions['multipart'] = [];
        }

        // Add an entry to the multipart array
        $this->requestOptions['multipart'][] = [
            'name' => $partName,
            'contents' => fopen($path, 'r'),
            'filename' => basename($path),
        ];

        return $this;
    }
public function addMultipartFileToRequest($path, $partName) {
        if (!file_exists($path)) {
            throw new InvalidArgumentException(sprintf('File does not exist: "%s"', $path));
        }

        // Create the multipart entry in the request options if it does not already exist
        if (!isset($this->requestOptions['multipart'])) {
            $this->requestOptions['multipart'] = [];
        }

        // Add an entry to the multipart array
        $this->requestOptions['multipart'][] = [
            'name' => $partName,
            'contents' => fopen($path, 'r'),
            'filename' => basename($path),
        ];

        return $this;
    }
public function addMultipartFileToRequest ( $ path , $ partName ) { if ( ! file_exists ( $ path ) ) { throw new InvalidArgumentException ( sprintf ( 'File does not exist: "%s"' , $ path ) ) ; } // Create the multipart entry in the request options if it does not already exist if ( ! isset ( $ this -> requestOptions [ 'multipart' ] ) ) { $ this -> requestOptions [ 'multipart' ] = [ ] ; } // Add an entry to the multipart array $ this -> requestOptions [ 'multipart' ] [ ] = [ 'name' => $ partName , 'contents' => fopen ( $ path , 'r' ) , 'filename' => basename ( $ path ) , ] ; return $ this ; }
Attach a file to the request

@param string $path Path to the image to add to the request
@param string $partName Multipart entry name
@throws InvalidArgumentException If the $path does not point to a file, an exception is
thrown
@return self

@Given I attach :path to the request as :partName
Attach a file to the request