Fix bad type after using findByUrlAndUserId

It returns an object since few commits this part of (untested) code still use an array.
Also add test for that part of code.
This commit is contained in:
Jeremy Benoist 2016-01-21 16:37:25 +01:00
parent e56983af1f
commit a0d6ccc5ca
2 changed files with 30 additions and 5 deletions

View file

@ -54,10 +54,10 @@ class EntryController extends Controller
if (false !== $existingEntry) {
$this->get('session')->getFlashBag()->add(
'notice',
'Entry already saved on '.$existingEntry['createdAt']->format('d-m-Y')
'Entry already saved on '.$existingEntry->getCreatedAt()->format('d-m-Y')
);
return $this->redirect($this->generateUrl('view', array('id' => $existingEntry['id'])));
return $this->redirect($this->generateUrl('view', array('id' => $existingEntry->getId())));
}
$this->updateEntry($entry);

View file

@ -127,10 +127,35 @@ class EntryControllerTest extends WallabagCoreTestCase
$this->assertEquals(302, $client->getResponse()->getStatusCode());
$crawler = $client->followRedirect();
$content = $client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
$this->assertGreaterThan(1, $alert = $crawler->filter('h2 a')->extract(array('_text')));
$this->assertContains('Google', $alert[0]);
$this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
$this->assertEquals($this->url, $content->getUrl());
$this->assertContains('Google', $content->getTitle());
}
public function testPostNewOkUrlExist()
{
$this->logInAs('admin');
$client = $this->getClient();
$crawler = $client->request('GET', '/new');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
$form = $crawler->filter('button[type=submit]')->form();
$data = array(
'entry[url]' => $this->url,
);
$client->submit($form, $data);
$this->assertEquals(302, $client->getResponse()->getStatusCode());
$this->assertContains('/view/', $client->getResponse()->getTargetUrl());
}
/**