public function testAuthRequestFailure()
 {
     // create a client with invalid credentials
     $chargify = new ChargifyV2(['api_id' => 'fdsafdsaf', 'api_password' => 'fgsdgfdsg', 'api_secret' => 'fdsfdsaf']);
     $direct = $chargify->direct();
     // set a fake redirect URL. Chargify will 500 on us if we don't have a redirect URL
     $direct->setRedirect('http://localhost');
     // set mock response
     $mock = new MockHandler([Psr7\parse_response(MockResponse::read('v2.authTest.error'))]);
     $handler = HandlerStack::create($mock);
     $chargify->getHttpClient()->getConfig('handler')->setHandler($handler);
     $utilityAuthRequest = new AuthRequest($direct);
     $success = $utilityAuthRequest->test();
     $response = $utilityAuthRequest->getLastResponse();
     // test should have failed
     $this->assertFalse($success);
     // status code should be 200
     $this->assertEquals(200, $response->getStatusCode());
     // chargify should not redirect us
     $locationHeader = $response->getHeader('Location');
     $this->assertTrue(empty($locationHeader));
     // body should contain 'Incorrect signature'
     $bodyIsInvalid = 0 === strcasecmp('Incorrect signature', trim((string) $response->getBody()));
     $this->assertTrue($bodyIsInvalid);
 }
 /**
  * Get a Chargify client instance
  *
  * @param string $mockResponseFile Filename containing mocked response
  * @param string $env              (test|dev)
  *
  * @return ChargifyV2
  */
 public static function getInstance($mockResponseFile = null, $env = 'test')
 {
     $config = array();
     switch ($env) {
         case 'test':
             $config = (require dirname(__DIR__) . '/configs/ClientV2Config.Test.php');
             break;
         case 'dev':
             $config = (require dirname(__DIR__) . '/configs/ClientV2Config.Dev.php');
             break;
     }
     $chargify = new ChargifyV2($config);
     if (!empty($mockResponseFile)) {
         $mock = new MockHandler([Psr7\parse_response(MockResponse::read($mockResponseFile))]);
         $handler = HandlerStack::create($mock);
         $chargify->getHttpClient()->getConfig('handler')->setHandler($handler);
     }
     return $chargify;
 }