From d49541629d685e7ea185f384998044c5967b5e8c Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Thu, 6 May 2021 21:56:28 +0000 Subject: [PATCH] [TESTS] Change relevant tests to use GNUsocialTestCase, so they can access all the needed features --- tests/Twig/ExtensionTest.php | 11 ++--------- tests/Util/CommonTest.php | 16 ++-------------- tests/Util/NicknameTest.php | 9 ++------- 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/tests/Twig/ExtensionTest.php b/tests/Twig/ExtensionTest.php index 1faa58945b..3f2349a9ca 100644 --- a/tests/Twig/ExtensionTest.php +++ b/tests/Twig/ExtensionTest.php @@ -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); diff --git a/tests/Util/CommonTest.php b/tests/Util/CommonTest.php index 61661d230b..9eb8766611 100644 --- a/tests/Util/CommonTest.php +++ b/tests/Util/CommonTest.php @@ -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')); } diff --git a/tests/Util/NicknameTest.php b/tests/Util/NicknameTest.php index f34f1e5d5f..7f779c02db 100644 --- a/tests/Util/NicknameTest.php +++ b/tests/Util/NicknameTest.php @@ -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);