title: How to test a method who calls an API? (Laravel)
body: <p>I´m testing a method that stores a credit card information and inside that method I have to call an API to request the bank to store all the card information then they return me a token to make future transactions.</p>
  
  <p>The problem is when I Test the method I have this error </p>
  
  <blockquote>
    <p>cURL error 60: SSL certificate problem: self signed certificate in certificate chain</p>
  </blockquote>
  
  <p>This is my test method</p>
  
  <pre><code>/**
   ** @test
   **/
  public function a_logged_user_can_add_a_credit_debit_card()
  {
    $demoCard = [
          'card_number' =&gt; '5424180279791732',
          'month' =&gt; '05',
          'year' =&gt; '2021',
          'cvc' =&gt; '123',
      ];
  
      $reponse = $this-&gt;postJson(route('card.create'),
          $demoCard, $this-&gt;user-&gt;headersToken());
  
      $reponse-&gt;assertJson(['success' =&gt; true]);
  
      $this-&gt;assertEquals(1, Tarjeta::first()-&gt;user_id);
      $this-&gt;assertEquals($this-&gt;tarjetaDemo['month'], Tarjeta::first()-&gt;month);
      $this-&gt;assertEquals($this-&gt;tarjetaDemo['year'], Tarjeta::first()-&gt;year);
      $this-&gt;assertEquals($this-&gt;tarjetaDemo['cvc'], Tarjeta::first()-&gt;cvc);
      $this-&gt;assertTrue(!empty(Tarjeta::first()-&gt;token));
  }
  </code></pre>
  
  <p>And this is my method</p>
  
  <pre><code> private $clientEcomm;
  /**
   * constructor.
   */
  public function __construct()
  {
      $merchant = env('MERCHANT_ECOMM');
      $apiPassword = env('API_ECOMM_PASSWORD');
      $apiUsername = env('API_ECOMM_USER');
  
      $this-&gt;clientEcomm = new Client([
          'base_uri' =&gt; "https://banamex.dialectpayments.com/api/rest/version/54/merchant/{$merchant}/",
          'auth' =&gt; [$apiUsername, $apiPassword]
      ]);
  }
  
  public function create(CardRequest $request)
  {
  
      $response = $this-&gt;clientEcomm-&gt;put(
          "token",
          [
              'json' =&gt; [
                  'sourceOfFunds' =&gt; [
                      'provided' =&gt; [
                          'card' =&gt; [
                              'number' =&gt; $request-&gt;get('card_number'),
                              'expiry' =&gt; [
                                  'month' =&gt; $request-&gt;get('month'),
                                  'year' =&gt; Str::substr($request-&gt;get('year'), -2),
                              ],
                              'securityCode' =&gt; $request-&gt;get('cvc')
                          ]
                      ],
                      'type' =&gt; 'CARD',
                  ],
              ]
          ]
      );
  
      $response = \GuzzleHttp\json_decode($response-&gt;getBody()-&gt;getContents());
  
      Tarjeta::create([
          'user_id' =&gt; \Auth::user()-&gt;id,
          'mes' =&gt; $request-&gt;get('month'),
          'year' =&gt; $request-&gt;get('year'),
          'cvc' =&gt; $request-&gt;get('cvc'),
          'token' =&gt;  $response-&gt;token,
      ]);
  
      return $this-&gt;successResponse();
  }
  </code></pre>
  
  <p>How can I do this kind of tests?</p>