public function testCompile_SuccessThenFailure() { $def = new DataSift_Definition($this->user, testdata('definition')); $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); $this->assertEquals($def->get(), testdata('definition'), 'Definition string not set correctly'); try { $def->compile(); } catch (DataSift_Exception_CompileFailed $e) { $this->fail('CompileFailed: ' . $e->getMessage() . ' (' . $e->getCode() . ')'); } catch (DataSift_Exception_InvalidData $e) { $this->fail('InvalidData: ' . $e->getMessage() . ' (' . $e->getCode() . ')'); } catch (DataSift_Exception_APIError $e) { $this->fail('APIError: ' . $e->getMessage() . ' (' . $e->getCode() . ')'); } $this->assertEquals(testdata('definition_hash'), $def->getHash(), 'Hash is not correct'); // Now set the invalid definition in that same object $response = array('response_code' => 400, 'data' => array('error' => 'The target interactin.content does not exist'), 'rate_limit' => 200, 'rate_limit_remaining' => 150); DataSift_MockApiClient::setResponse($response); $def->set(testdata('invalid_definition')); $this->assertEquals($def->get(), testdata('invalid_definition'), 'Definition string not set correctly'); try { $def->compile(); $this->fail('CompileFailed exception expected, but not thrown'); } catch (DataSift_Exception_InvalidData $e) { // Do nothing because this is what's supposed to happen } catch (DataSift_Exception_APIError $e) { $this->fail('APIError: ' . $e->getMessage() . ' (' . $e->getCode() . ')'); } catch (Exception $e) { $this->fail('Unhandled exception: ' . $e->getMessage() . ' (' . $e->getCode() . ')'); } }