public function testCompile_Success()
{
$response = array('response_code' => 200, 'data' => array('hash' => testdata('definition_hash'), 'created_at' => date('Y-m-d H:i:s', time()), 'dpu' => 10), 'rate_limit' => 200, 'rate_limit_remaining' => 150);
DataSift_MockApiClient::setResponse($response);
$def = new DataSift_Definition($this->user, testdata('definition'));
$this->assertEquals($def->get(), testdata('definition'), 'Definition string not set correctly');
try {
$def->compile();
} catch (DataSift_Exception_InvalidData $e) {
$this->fail('InvalidData: ' . $e->getMessage() . ' (' . $e->getCode() . ')');
} catch (DataSift_Exception_CompileFailed $e) {
$this->fail('CompileFailed: ' . $e->getMessage() . ' (' . $e->getCode() . ')');
} catch (DataSift_Exception_APIError $e) {
$this->fail('APIError: ' . $e->getMessage() . ' (' . $e->getCode() . ')');
}
// The rate limit values should have been updated
$this->assertEquals(200, $this->user->getRateLimit(), 'Incorrect rate limit');
$this->assertEquals(150, $this->user->getRateLimitRemaining(), 'Incorrect rate limit remaining');
$this->assertEquals(testdata('definition_hash'), $def->getHash(), 'Incorrect hash');
// And a created_at date
$this->assertEquals($response['data']['created_at'], date('Y-m-d H:i:s', $def->getCreatedAt()), 'Incorrect created_at date');
// And a DPU
$this->assertEquals($response['data']['dpu'], $def->getTotalDPU(), 'Incorrect total DPU');
}