mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-08-05 02:35:16 +02:00
Refactored TwigExtensions Part 1
This commit is contained in:
parent
8e6300079a
commit
b078389381
21 changed files with 301 additions and 89 deletions
53
tests/Twig/EntityExtensionTest.php
Normal file
53
tests/Twig/EntityExtensionTest.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tests\Twig;
|
||||
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\Attachments\PartAttachment;
|
||||
use App\Entity\Devices\Device;
|
||||
use App\Entity\LabelSystem\LabelProfile;
|
||||
use App\Entity\Parts\Category;
|
||||
use App\Entity\Parts\Footprint;
|
||||
use App\Entity\Parts\Manufacturer;
|
||||
use App\Entity\Parts\MeasurementUnit;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Entity\Parts\Storelocation;
|
||||
use App\Entity\Parts\Supplier;
|
||||
use App\Entity\PriceInformations\Currency;
|
||||
use App\Entity\UserSystem\Group;
|
||||
use App\Entity\UserSystem\User;
|
||||
use App\Twig\EntityExtension;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class EntityExtensionTest extends WebTestCase
|
||||
{
|
||||
/** @var EntityExtension */
|
||||
protected $service;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
|
||||
//Get an service instance.
|
||||
self::bootKernel();
|
||||
$this->service = self::getContainer()->get(EntityExtension::class);
|
||||
}
|
||||
|
||||
public function testGetEntityType()
|
||||
{
|
||||
$this->assertEquals('part', $this->service->getEntityType(new Part()));
|
||||
$this->assertEquals('footprint', $this->service->getEntityType(new Footprint()));
|
||||
$this->assertEquals('storelocation', $this->service->getEntityType(new Storelocation()));
|
||||
$this->assertEquals('manufacturer', $this->service->getEntityType(new Manufacturer()));
|
||||
$this->assertEquals('category', $this->service->getEntityType(new Category()));
|
||||
$this->assertEquals('device', $this->service->getEntityType(new Device()));
|
||||
$this->assertEquals('attachment', $this->service->getEntityType(new PartAttachment()));
|
||||
$this->assertEquals('supplier', $this->service->getEntityType(new Supplier()));
|
||||
$this->assertEquals('user', $this->service->getEntityType(new User()));
|
||||
$this->assertEquals('group', $this->service->getEntityType(new Group()));
|
||||
$this->assertEquals('currency', $this->service->getEntityType(new Currency()));
|
||||
$this->assertEquals('measurement_unit', $this->service->getEntityType(new MeasurementUnit()));
|
||||
$this->assertEquals('label_profile', $this->service->getEntityType(new LabelProfile()));
|
||||
}
|
||||
|
||||
}
|
56
tests/Twig/TwigCoreExtensionTest.php
Normal file
56
tests/Twig/TwigCoreExtensionTest.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tests\Twig;
|
||||
|
||||
use App\Twig\TwigCoreExtension;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class TwigCoreExtensionTest extends WebTestCase
|
||||
{
|
||||
/** @var TwigCoreExtension */
|
||||
protected $service;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
|
||||
//Get an service instance.
|
||||
self::bootKernel();
|
||||
$this->service = self::getContainer()->get(TwigCoreExtension::class);
|
||||
}
|
||||
|
||||
public function testToArray(): void
|
||||
{
|
||||
//Check for simple arrays
|
||||
$this->assertSame([], $this->service->toArray([]));
|
||||
$this->assertSame([1, 2, 3], $this->service->toArray([1, 2, 3]));
|
||||
|
||||
//Check for simple objects
|
||||
$this->assertSame([], $this->service->toArray(new \stdClass()));
|
||||
$this->assertSame(['test' => 1], $this->service->toArray((object)['test' => 1]));
|
||||
|
||||
//Only test and test4 should be available
|
||||
$obj = new class {
|
||||
public $test = 1;
|
||||
protected $test2 = 3;
|
||||
private $test3 = 5;
|
||||
private $test4 = 7;
|
||||
|
||||
public function getTest4()
|
||||
{
|
||||
return $this->test4;
|
||||
}
|
||||
};
|
||||
|
||||
$this->assertEqualsCanonicalizing(['test' => 1, 'test4' => 7], $this->service->toArray($obj));
|
||||
}
|
||||
|
||||
public function testToArrayException(): void
|
||||
{
|
||||
//When passing a simple scalar value a exception should be thrown.
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
$this->service->toArray(1);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue