[TESTS] Expand test coverage for App\Util\Forms\ArrayTransformer, App\Util\Notification and App\Twig\Runtime
This commit is contained in:
parent
6591d78a9c
commit
fbe0f36a53
|
@ -32,6 +32,9 @@ namespace App\Util\Notification;
|
||||||
|
|
||||||
use function App\Core\I18n\_m;
|
use function App\Core\I18n\_m;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
abstract class AbstractTransport
|
abstract class AbstractTransport
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
namespace App\Util\Notification;
|
namespace App\Util\Notification;
|
||||||
|
|
||||||
use App\Entity\Profile;
|
use App\Entity\Gsactor;
|
||||||
|
|
||||||
class Notification
|
class Notification
|
||||||
{
|
{
|
||||||
|
@ -50,11 +50,11 @@ class Notification
|
||||||
/**
|
/**
|
||||||
* Who caused this notification
|
* Who caused this notification
|
||||||
*/
|
*/
|
||||||
private Profile $profile;
|
private GSActor $gsactor;
|
||||||
|
|
||||||
public function __construct(int $type, Profile $profile)
|
public function __construct(int $type, GSActor $gsactor)
|
||||||
{
|
{
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
$this->profile = $profile;
|
$this->gsactor = $gsactor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,10 +33,13 @@
|
||||||
|
|
||||||
namespace App\Tests\Twig;
|
namespace App\Tests\Twig;
|
||||||
|
|
||||||
|
use App\Core\DB\DB;
|
||||||
|
use App\Core\Event;
|
||||||
use App\Twig\Extension;
|
use App\Twig\Extension;
|
||||||
use App\Twig\Runtime;
|
use App\Twig\Runtime;
|
||||||
use DirectoryIterator;
|
use DirectoryIterator;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
class ExtensionTest extends KernelTestCase
|
class ExtensionTest extends KernelTestCase
|
||||||
|
@ -89,4 +92,19 @@ class ExtensionTest extends KernelTestCase
|
||||||
static::assertSame('active', $runtime->isCurrentRouteActive('current_route'));
|
static::assertSame('active', $runtime->isCurrentRouteActive('current_route'));
|
||||||
static::assertSame('', $runtime->isCurrentRouteActive('some_route', 'some_other_route'));
|
static::assertSame('', $runtime->isCurrentRouteActive('some_route', 'some_other_route'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
static::assertSame([], $runtime->getNoteActions(DB::dql('select n from note n where n.content = \'some content\'')[0]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,19 +20,25 @@
|
||||||
namespace App\Tests\Util\Form;
|
namespace App\Tests\Util\Form;
|
||||||
|
|
||||||
use App\Util\Form\ArrayTransformer;
|
use App\Util\Form\ArrayTransformer;
|
||||||
|
use Jchook\AssertThrows\AssertThrows;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||||
|
|
||||||
class ArrayTransformerTest extends WebTestCase
|
class ArrayTransformerTest extends WebTestCase
|
||||||
{
|
{
|
||||||
|
use AssertThrows;
|
||||||
|
|
||||||
public function testTransform()
|
public function testTransform()
|
||||||
{
|
{
|
||||||
static::assertSame('', (new ArrayTransformer)->transform([]));
|
static::assertSame('', (new ArrayTransformer)->transform([]));
|
||||||
static::assertSame('foo bar quux', (new ArrayTransformer)->transform(['foo', 'bar', 'quux']));
|
static::assertSame('foo bar quux', (new ArrayTransformer)->transform(['foo', 'bar', 'quux']));
|
||||||
|
static::assertThrows(TransformationFailedException::class, fn () => (new ArrayTransformer)->transform(''));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReverseTransform()
|
public function testReverseTransform()
|
||||||
{
|
{
|
||||||
static::assertSame([], (new ArrayTransformer)->reverseTransform(''));
|
static::assertSame([], (new ArrayTransformer)->reverseTransform(''));
|
||||||
static::assertSame(['foo', 'bar', 'quux'], (new ArrayTransformer)->reverseTransform('foo bar quux'));
|
static::assertSame(['foo', 'bar', 'quux'], (new ArrayTransformer)->reverseTransform('foo bar quux'));
|
||||||
|
static::assertThrows(TransformationFailedException::class, fn () => (new ArrayTransformer)->reverseTransform(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
35
tests/Util/Notification/NotificationTest.php
Normal file
35
tests/Util/Notification/NotificationTest.php
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// {{{ License
|
||||||
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||||
|
//
|
||||||
|
// GNU social is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// GNU social is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
namespace App\Tests\Util\Notification;
|
||||||
|
|
||||||
|
use App\Entity\GSActor;
|
||||||
|
use App\Util\Notification\Notification;
|
||||||
|
use Jchook\AssertThrows\AssertThrows;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class NotificationTest extends TestCase
|
||||||
|
{
|
||||||
|
use AssertThrows;
|
||||||
|
|
||||||
|
public function testNotificationBitmap()
|
||||||
|
{
|
||||||
|
static::assertTrue((new Notification(Notification::DM, new GSActor())) instanceof Notification);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user