[TESTS] Change relevant tests to use GNUsocialTestCase, so they can access all the needed features

This commit is contained in:
Hugo Sales 2021-05-06 21:56:28 +00:00
parent b9fbed2e3d
commit d49541629d
No known key found for this signature in database
GPG Key ID: 7D0C7EAFC9D835A0
3 changed files with 6 additions and 30 deletions

View File

@ -34,15 +34,13 @@
namespace App\Tests\Twig;
use App\Core\DB\DB;
use App\Core\Event;
use App\Twig\Extension;
use App\Twig\Runtime;
use App\Util\GNUsocialTestCase;
use DirectoryIterator;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
class ExtensionTest extends KernelTestCase
class ExtensionTest extends GNUsocialTestCase
{
public function testIconsExtension()
{
@ -96,12 +94,7 @@ class ExtensionTest extends KernelTestCase
public function testGetNoteActions()
{
static::bootKernel();
DB::setManager(self::$kernel->getContainer()->get('doctrine.orm.entity_manager'));
DB::initTableMap();
$container = self::$kernel->getContainer()->get('test.service_container');
$edi = $container->get(EventDispatcherInterface::class);
Event::setDispatcher($edi);
$req = $this->createMock(Request::class);
$runtime = new Runtime;
$runtime->setRequest($req);

View File

@ -20,24 +20,20 @@
namespace App\Tests\Util;
use App\Core\DB\DB;
use App\Core\Event;
use App\Core\Router\Router;
use App\Core\Security;
use App\Entity\GSActor;
use App\Entity\LocalUser;
use App\Util\Common;
use App\Util\Exception\NoLoggedInUser;
use App\Util\GNUsocialTestCase;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Jchook\AssertThrows\AssertThrows;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Security as SSecurity;
class CommonTest extends WebTestCase
class CommonTest extends GNUsocialTestCase
{
use AssertThrows;
@ -73,8 +69,6 @@ class CommonTest extends WebTestCase
public function testUserAndActorGetters()
{
$client = static::createClient();
$sec = $this->getMockBuilder(SSecurity::class)->setConstructorArgs([self::$kernel->getContainer()])->getMock();
Security::setHelper($sec, null);
static::assertNull(Common::user());
static::assertThrows(NoLoggedInUser::class, fn () => Common::ensureLoggedIn());
static::assertFalse(Common::isLoggedIn());
@ -112,12 +106,6 @@ class CommonTest extends WebTestCase
{
static::bootKernel();
$router = static::$container->get('router');
$url_gen = static::$container->get(UrlGeneratorInterface::class);
$event_dispatcher = static::$container->get(EventDispatcherInterface::class);
Router::setRouter($router, $url_gen);
Event::setDispatcher($event_dispatcher);
static::assertTrue(Common::isSystemPath('login'));
static::assertFalse(Common::isSystemPath('non-existent-path'));
}

View File

@ -19,7 +19,6 @@
namespace App\Tests\Util;
use App\Core\DB\DB;
use App\Entity\GSActor;
use App\Util\Common;
use App\Util\Exception\NicknameEmptyException;
@ -28,12 +27,12 @@ use App\Util\Exception\NicknameReservedException;
use App\Util\Exception\NicknameTakenException;
use App\Util\Exception\NicknameTooLongException;
use App\Util\Exception\NicknameTooShortException;
use App\Util\GNUsocialTestCase;
use App\Util\Nickname;
use Jchook\AssertThrows\AssertThrows;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
class NicknameTest extends WebTestCase
class NicknameTest extends GNUsocialTestCase
{
use AssertThrows;
@ -57,8 +56,6 @@ class NicknameTest extends WebTestCase
static::assertThrows(NicknameReservedException::class, fn () => Nickname::normalize('this_nickname_is_reserved', check_already_used: false));
static::bootKernel();
DB::setManager(self::$kernel->getContainer()->get('doctrine.orm.entity_manager'));
DB::initTableMap();
static::assertSame('foobar', Nickname::normalize('foobar', check_already_used: true));
static::assertThrows(NicknameTakenException::class, fn () => Nickname::normalize('taken_user', check_already_used: true));
}
@ -95,8 +92,6 @@ class NicknameTest extends WebTestCase
public function testCheckTaken()
{
static::bootKernel();
DB::setManager(self::$kernel->getContainer()->get('doctrine.orm.entity_manager'));
DB::initTableMap();
static::assertNull(Nickname::checkTaken('not_taken_user'));
static::assertTrue(Nickname::checkTaken('taken_user') instanceof GSActor);