Use FQCN instead of service alias

This commit is contained in:
Yassine Guedidi
2022-08-28 02:01:46 +02:00
parent 156158673f
commit eb43c78720
62 changed files with 579 additions and 404 deletions

View File

@ -2,6 +2,7 @@
namespace Tests\Wallabag\ApiBundle\Controller;
use Doctrine\ORM\EntityManagerInterface;
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
use Wallabag\ApiBundle\Entity\Client;
@ -11,7 +12,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase
{
$this->logInAs('admin');
$client = $this->getClient();
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$em = $client->getContainer()->get(EntityManagerInterface::class);
$nbClients = $em->getRepository(Client::class)->findAll();
$crawler = $client->request('GET', '/developer/client/create');
@ -74,7 +75,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase
{
$this->logInAs('admin');
$client = $this->getClient();
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$em = $client->getContainer()->get(EntityManagerInterface::class);
$nbClients = $em->getRepository(Client::class)->findAll();
$crawler = $client->request('GET', '/developer');
@ -95,7 +96,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase
{
$client = $this->getClient();
$adminApiClient = $this->createApiClientForUser('admin');
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$em = $client->getContainer()->get(EntityManagerInterface::class);
// Try to remove an admin's client with a wrong user
$this->logInAs('bob');
@ -134,7 +135,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase
private function createApiClientForUser($username, $grantTypes = ['password'])
{
$client = $this->getClient();
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$em = $client->getContainer()->get(EntityManagerInterface::class);
$userManager = $client->getContainer()->get('fos_user.user_manager.test');
$user = $userManager->findUserBy(['username' => $username]);
$apiClient = new Client($user);

View File

@ -2,6 +2,7 @@
namespace Tests\Wallabag\ApiBundle\Controller;
use Doctrine\ORM\EntityManagerInterface;
use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Entity\Tag;
@ -13,7 +14,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testGetOneEntry()
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneBy(['user' => $this->getUserId(), 'isArchived' => false]);
@ -39,7 +40,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testGetOneEntryWithOriginUrl()
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneBy(['user' => $this->getUserId(), 'url' => 'http://0.0.0.0/entry2']);
@ -58,7 +59,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testExportEntry()
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneBy(['user' => $this->getUserId(), 'isArchived' => false]);
@ -106,7 +107,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testGetOneEntryWrongUser()
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneBy(['user' => $this->getUserId('bob'), 'isArchived' => false]);
@ -204,7 +205,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testGetEntriesPublicOnly()
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneByUser($this->getUserId());
@ -215,7 +216,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
// generate at least one public entry
$entry->generateUid();
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$em->persist($entry);
$em->flush();
@ -421,7 +422,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testDeleteEntry()
{
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$entry = new Entry($em->getReference(User::class, 1));
$entry->setUrl('http://0.0.0.0/test-delete-entry');
$entry->setTitle('Test delete entry');
@ -455,7 +456,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testDeleteEntryExpectId()
{
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$entry = new Entry($em->getReference(User::class, 1));
$entry->setUrl('http://0.0.0.0/test-delete-entry-id');
$em->persist($entry);
@ -526,7 +527,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testPostSameEntry()
{
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$entry = new Entry($em->getReference(User::class, $this->getUserId()));
$entry->setUrl('https://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html');
$entry->setArchived(true);
@ -580,7 +581,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
} finally {
// Remove the created entry to avoid side effects on other tests
if (isset($content['id'])) {
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$entry = $em->getReference(Entry::class, $content['id']);
$em->remove($entry);
$em->flush();
@ -654,7 +655,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testPatchEntry()
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneByUser($this->getUserId());
@ -696,7 +697,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testPatchEntryWithoutQuotes()
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneByUser($this->getUserId());
@ -730,7 +731,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testPatchEntryWithOriginUrl()
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneByUser($this->getUserId());
@ -761,7 +762,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testPatchEntryRemoveOriginUrl()
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneByUser($this->getUserId());
@ -793,7 +794,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testPatchEntryNullOriginUrl()
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneByUser($this->getUserId());
@ -815,7 +816,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testGetTagsEntry()
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneWithTags($this->user->getId());
@ -838,7 +839,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testPostTagsOnEntry()
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneByUser($this->getUserId());
@ -860,7 +861,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
$this->assertCount($nbTags + 3, $content['tags']);
$entryDB = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->find($entry->getId());
@ -877,7 +878,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testDeleteOneTagEntry()
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneWithTags($this->user->getId());
$entry = $entry[0];
@ -903,7 +904,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testSaveIsArchivedAfterPost()
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]);
@ -925,7 +926,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testSaveIsStarredAfterPost()
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]);
@ -947,7 +948,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testSaveIsArchivedAfterPatch()
{
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]);
@ -973,7 +974,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
{
$now = new \DateTime();
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]);
@ -1134,7 +1135,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testReloadEntryErrorWhileFetching()
{
$entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
$entry = $this->client->getContainer()->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
@ -1170,7 +1171,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testPostEntriesTagsListAction()
{
$entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
$entry = $this->client->getContainer()->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
@ -1194,7 +1195,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
$this->assertIsInt($content[0]['entry']);
$this->assertSame('http://0.0.0.0/entry4', $content[0]['url']);
$entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
$entry = $this->client->getContainer()->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId());
@ -1215,7 +1216,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testDeleteEntriesTagsListAction()
{
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$entry = new Entry($em->getReference(User::class, $this->getUserId()));
$entry->setUrl('http://0.0.0.0/test-entry');
$entry->addTag((new Tag())->setLabel('foo-tag'));
@ -1283,7 +1284,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testDeleteEntriesListAction()
{
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$em->persist((new Entry($em->getReference(User::class, $this->getUserId())))->setUrl('http://0.0.0.0/test-entry1'));
$em->flush();
@ -1341,7 +1342,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testRePostEntryAndReUsePublishedAt()
{
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$entry = new Entry($em->getReference(User::class, $this->getUserId()));
$entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »');
$entry->setContent('hihi');

View File

@ -2,6 +2,7 @@
namespace Tests\Wallabag\ApiBundle\Controller;
use Doctrine\ORM\EntityManagerInterface;
use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Entity\Tag;
@ -33,9 +34,9 @@ class TagRestControllerTest extends WallabagApiTestCase
public function testDeleteUserTag()
{
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneWithTags($this->user->getId());
@ -74,7 +75,7 @@ class TagRestControllerTest extends WallabagApiTestCase
public function testDeleteOtherUserTag()
{
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$tag = $em->getRepository(Tag::class)->findOneByLabel($this->otherUserTagLabel);
$this->client->request('DELETE', '/api/tags/' . $tag->getId() . '.json');
@ -95,9 +96,9 @@ class TagRestControllerTest extends WallabagApiTestCase
*/
public function testDeleteTagByLabel($useQueryString)
{
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneWithTags($this->user->getId());
@ -127,7 +128,7 @@ class TagRestControllerTest extends WallabagApiTestCase
$this->assertSame($tag->getSlug(), $content['slug']);
$entries = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findAllByTagId($this->user->getId(), $tag->getId());
@ -153,9 +154,9 @@ class TagRestControllerTest extends WallabagApiTestCase
*/
public function testDeleteTagsByLabel($useQueryString)
{
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$entry = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findOneWithTags($this->user->getId());
@ -196,14 +197,14 @@ class TagRestControllerTest extends WallabagApiTestCase
$this->assertSame($tag2->getSlug(), $content[1]['slug']);
$entries = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findAllByTagId($this->user->getId(), $tag->getId());
$this->assertCount(0, $entries);
$entries = $this->client->getContainer()
->get('doctrine.orm.entity_manager')
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->findAllByTagId($this->user->getId(), $tag2->getId());

View File

@ -2,6 +2,7 @@
namespace Tests\Wallabag\ApiBundle\Controller;
use Craue\ConfigBundle\Util\Config;
use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
class UserRestControllerTest extends WallabagApiTestCase
@ -45,7 +46,7 @@ class UserRestControllerTest extends WallabagApiTestCase
public function testCreateNewUser()
{
$this->client->getContainer()->get('craue_config')->set('api_user_registration', 1);
$this->client->getContainer()->get(Config::class)->set('api_user_registration', 1);
$this->client->request('PUT', '/api/user.json', [
'username' => 'google',
'password' => 'googlegoogle',
@ -73,14 +74,14 @@ class UserRestControllerTest extends WallabagApiTestCase
$this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
$this->client->getContainer()->get('craue_config')->set('api_user_registration', 0);
$this->client->getContainer()->get(Config::class)->set('api_user_registration', 0);
}
public function testCreateNewUserWithoutAuthentication()
{
// create a new client instead of using $this->client to be sure client isn't authenticated
$client = static::createClient();
$client->getContainer()->get('craue_config')->set('api_user_registration', 1);
$client->getContainer()->get(Config::class)->set('api_user_registration', 1);
$client->request('PUT', '/api/user.json', [
'username' => 'google',
'password' => 'googlegoogle',
@ -109,13 +110,13 @@ class UserRestControllerTest extends WallabagApiTestCase
$this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type'));
$client->getContainer()->get('craue_config')->set('api_user_registration', 0);
$client->getContainer()->get(Config::class)->set('api_user_registration', 0);
}
public function testCreateNewUserWithExistingEmail()
{
$client = static::createClient();
$client->getContainer()->get('craue_config')->set('api_user_registration', 1);
$client->getContainer()->get(Config::class)->set('api_user_registration', 1);
$client->request('PUT', '/api/user.json', [
'username' => 'admin',
'password' => 'googlegoogle',
@ -138,13 +139,13 @@ class UserRestControllerTest extends WallabagApiTestCase
$this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type'));
$client->getContainer()->get('craue_config')->set('api_user_registration', 0);
$client->getContainer()->get(Config::class)->set('api_user_registration', 0);
}
public function testCreateNewUserWithTooShortPassword()
{
$client = static::createClient();
$client->getContainer()->get('craue_config')->set('api_user_registration', 1);
$client->getContainer()->get(Config::class)->set('api_user_registration', 1);
$client->request('PUT', '/api/user.json', [
'username' => 'facebook',
'password' => 'face',
@ -162,7 +163,7 @@ class UserRestControllerTest extends WallabagApiTestCase
$this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type'));
$client->getContainer()->get('craue_config')->set('api_user_registration', 0);
$client->getContainer()->get(Config::class)->set('api_user_registration', 0);
}
public function testCreateNewUserWhenRegistrationIsDisabled()