Skip to content

Instantly share code, notes, and snippets.

@albe
Created January 27, 2016 18:00
Show Gist options
  • Save albe/03f0f87663ac73677749 to your computer and use it in GitHub Desktop.
Save albe/03f0f87663ac73677749 to your computer and use it in GitHub Desktop.
/**
* @test
*/
public function resourceCanBeUpdatedViaRestCall()
{
$arguments = array(
'resource' => array(
'title' => 'Foo'
)
);
$response = $this->browser->request('http://localhost/test/api/aggregate', 'POST', $arguments);
$resourceUri = $response->getHeader('Location');
$this->persistenceManager->clearState();
// Will work nicely without this clearState. With the clearstate:
// Uncaught Exception in Flow An exception occurred while executing 'UPDATE acme_tests_functional_api_fixtures_domain_mod_bda44 SET title = ? WHERE persistence_object_identifier = ?' with params ["Bar", "a6124056-41b7-4fcd-a1d5-3739f9c5a675"]:
// SQLSTATE[HY000]: General error: 1 no such table: acme_tests_functional_api_fixtures_domain_mod_bda44
$arguments = array(
'resource' => array(
'title' => 'Bar'
)
);
$response = $this->browser->request($resourceUri, 'PUT', $arguments);
$this->assertEquals(200, $response->getStatusCode());
$this->assertNotEmpty($response->getContent());
$createdEntity = json_decode($response->getContent(), true);
$this->assertEquals('Bar', $createdEntity['title']);
}
/**
* @test
*/
public function resourceCanBeDeletedViaRestCall()
{
$arguments = array(
'resource' => array(
'title' => 'Foo'
)
);
$response = $this->browser->request('http://localhost/test/api/aggregate', 'POST', $arguments);
$resourceUri = $response->getHeader('Location');
$this->persistenceManager->clearState();
// Only works with the clearState(). Without it, the entity will not be removed from persistence, even when directly calling persistenceManager->remove($resource); persistenceManager->persistAll();
$response = $this->browser->request($resourceUri, 'DELETE');
$this->assertEquals(204, $response->getStatusCode());
$this->assertEmpty($response->getContent());
$response = $this->browser->request($resourceUri, 'GET');
$this->assertEquals(404, $response->getStatusCode());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment