public function testWillGenerateANewIdIfTheGeneratedOneExists()
{
$this->request->expects($this->once())->method('getContent')->will($this->returnValue('{"user": "user", "imageIdentifier": "id"}'));
$this->request->expects($this->once())->method('getUser')->will($this->returnValue('user'));
$this->request->expects($this->once())->method('getImageIdentifier')->will($this->returnValue('id'));
$this->database->expects($this->at(0))->method('imageExists')->with('user', 'id')->will($this->returnValue(true));
$this->database->expects($this->at(1))->method('getShortUrlId')->with('user', 'id', null, [])->will($this->returnValue(null));
$this->database->expects($this->at(2))->method('getShortUrlParams')->with($this->matchesRegularExpression('/[a-zA-Z0-9]{7}/'))->will($this->returnValue(['user' => 'value']));
$this->database->expects($this->at(3))->method('getShortUrlParams')->with($this->matchesRegularExpression('/[a-zA-Z0-9]{7}/'))->will($this->returnValue(['user' => 'value']));
$this->database->expects($this->at(4))->method('getShortUrlParams')->with($this->matchesRegularExpression('/[a-zA-Z0-9]{7}/'))->will($this->returnValue(null));
$this->database->expects($this->at(5))->method('insertShortUrl')->with($this->matchesRegularExpression('/[a-zA-Z0-9]{7}/'), 'user', 'id', null, []);
$this->response->expects($this->once())->method('setModel')->with($this->isInstanceOf('Imbo\\Model\\ArrayModel'))->will($this->returnSelf());
$this->response->expects($this->once())->method('setStatusCode')->with(201);
$this->getNewResource()->createShortUrl($this->event);
}