mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-08-03 17:55:03 +02:00
Refactored TwigExtensions Part 1
This commit is contained in:
parent
8e6300079a
commit
b078389381
21 changed files with 301 additions and 89 deletions
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