Migrate getRepository with entities

This commit is contained in:
Yassine Guedidi
2022-08-25 21:37:10 +02:00
parent 50a941d8b4
commit 8b7b4975d6
38 changed files with 226 additions and 202 deletions

View File

@ -12,7 +12,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase
$this->logInAs('admin');
$client = $this->getClient();
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
$nbClients = $em->getRepository(Client::class)->findAll();
$crawler = $client->request('GET', '/developer/client/create');
$this->assertSame(200, $client->getResponse()->getStatusCode());
@ -27,7 +27,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase
$this->assertSame(200, $client->getResponse()->getStatusCode());
$newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
$newNbClients = $em->getRepository(Client::class)->findAll();
$this->assertGreaterThan(\count($nbClients), \count($newNbClients));
$this->assertGreaterThan(1, $alert = $crawler->filter('.settings table strong')->extract(['_text']));
@ -75,7 +75,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase
$this->logInAs('admin');
$client = $this->getClient();
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
$nbClients = $em->getRepository(Client::class)->findAll();
$crawler = $client->request('GET', '/developer');
$this->assertSame(200, $client->getResponse()->getStatusCode());
@ -120,7 +120,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase
$this->assertSame(302, $client->getResponse()->getStatusCode());
$this->assertNull(
$em->getRepository('WallabagApiBundle:Client')->find($adminApiClient->getId()),
$em->getRepository(Client::class)->find($adminApiClient->getId()),
'The client should have been removed'
);
}

View File

@ -14,7 +14,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findOneBy(['user' => $this->getUserId(), 'isArchived' => false]);
if (!$entry) {
@ -40,7 +40,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findOneBy(['user' => $this->getUserId(), 'url' => 'http://0.0.0.0/entry2']);
if (!$entry) {
@ -59,7 +59,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findOneBy(['user' => $this->getUserId(), 'isArchived' => false]);
if (!$entry) {
@ -107,7 +107,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findOneBy(['user' => $this->getUserId('bob'), 'isArchived' => false]);
if (!$entry) {
@ -205,7 +205,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findOneByUser($this->getUserId());
if (!$entry) {
@ -655,7 +655,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findOneByUser($this->getUserId());
if (!$entry) {
@ -697,7 +697,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findOneByUser($this->getUserId());
if (!$entry) {
@ -731,7 +731,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findOneByUser($this->getUserId());
if (!$entry) {
@ -762,7 +762,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findOneByUser($this->getUserId());
if (!$entry) {
@ -794,7 +794,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findOneByUser($this->getUserId());
if (!$entry) {
@ -816,7 +816,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findOneWithTags($this->user->getId());
$entry = $entry[0];
@ -839,7 +839,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findOneByUser($this->getUserId());
if (!$entry) {
@ -861,7 +861,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
$entryDB = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->find($entry->getId());
$tagsInDB = [];
@ -878,7 +878,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findOneWithTags($this->user->getId());
$entry = $entry[0];
@ -904,7 +904,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]);
if (!$entry) {
@ -926,7 +926,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]);
if (!$entry) {
@ -948,7 +948,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]);
if (!$entry) {
@ -974,7 +974,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
$now = new \DateTime();
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]);
if (!$entry) {
@ -1135,7 +1135,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testReloadEntryErrorWhileFetching()
{
$entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
if (!$entry) {
@ -1171,7 +1171,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testPostEntriesTagsListAction()
{
$entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
$tags = $entry->getTags();
@ -1195,7 +1195,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
$this->assertSame('http://0.0.0.0/entry4', $content[0]['url']);
$entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
$tags = $entry->getTags();
@ -1235,7 +1235,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
$this->client->request('DELETE', '/api/entries/tags/list?list=' . json_encode($list));
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
$entry = $em->getRepository('WallabagCoreBundle:Entry')->find($entry->getId());
$entry = $em->getRepository(Entry::class)->find($entry->getId());
$this->assertCount(0, $entry->getTags());
}

View File

@ -3,6 +3,7 @@
namespace Tests\Wallabag\ApiBundle\Controller;
use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Entity\Tag;
class TagRestControllerTest extends WallabagApiTestCase
@ -35,7 +36,7 @@ class TagRestControllerTest extends WallabagApiTestCase
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findOneWithTags($this->user->getId());
$entry = $entry[0];
@ -61,12 +62,12 @@ class TagRestControllerTest extends WallabagApiTestCase
$this->assertSame($tag->getLabel(), $content['label']);
$this->assertSame($tag->getSlug(), $content['slug']);
$entries = $em->getRepository('WallabagCoreBundle:Entry')
$entries = $em->getRepository(Entry::class)
->findAllByTagId($this->user->getId(), $tag->getId());
$this->assertCount(0, $entries);
$tag = $em->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($tagLabel);
$tag = $em->getRepository(Tag::class)->findOneByLabel($tagLabel);
$this->assertNull($tag, $tagLabel . ' was removed because it begun an orphan tag');
}
@ -74,7 +75,7 @@ class TagRestControllerTest extends WallabagApiTestCase
public function testDeleteOtherUserTag()
{
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
$tag = $em->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($this->otherUserTagLabel);
$tag = $em->getRepository(Tag::class)->findOneByLabel($this->otherUserTagLabel);
$this->client->request('DELETE', '/api/tags/' . $tag->getId() . '.json');
@ -97,7 +98,7 @@ class TagRestControllerTest extends WallabagApiTestCase
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findOneWithTags($this->user->getId());
$entry = $entry[0];
@ -127,7 +128,7 @@ class TagRestControllerTest extends WallabagApiTestCase
$entries = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findAllByTagId($this->user->getId(), $tag->getId());
$this->assertCount(0, $entries);
@ -155,7 +156,7 @@ class TagRestControllerTest extends WallabagApiTestCase
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findOneWithTags($this->user->getId());
$entry = $entry[0];
@ -196,14 +197,14 @@ class TagRestControllerTest extends WallabagApiTestCase
$entries = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findAllByTagId($this->user->getId(), $tag->getId());
$this->assertCount(0, $entries);
$entries = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->getRepository(Entry::class)
->findAllByTagId($this->user->getId(), $tag2->getId());
$this->assertCount(0, $entries);