public function testAuthRequestFailure() { $mockFile = 'v2.authTest.error'; // 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'); $utilityAuthRequest = new AuthRequest($direct); // set a mock response on the client $mock = new Mock([MockResponse::read($mockFile)]); $utilityAuthRequest->getHttpClient()->getEmitter()->attach($mock); $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 = trim($response->getHeader('Location')); $this->assertTrue(empty($locationHeader)); // body should contain 'Incorrect signature' $bodyIsInvalid = 0 === strcasecmp('Incorrect signature', trim((string) $response->getBody())); $this->assertTrue($bodyIsInvalid); }
/** * Check if Chargify Direct credentials are correct * * @return boolean */ public function checkAuth() { // set a fake redirect URL. Chargify will 500 on us if we don't have a redirect URL $this->setRedirect('http://localhost'); return $this->authTestUtility->test(); }