Part-DB-server/tests/Twig/TwigCoreExtensionTest.php

57 lines
1.6 KiB
PHP
Raw Normal View History

2022-09-18 16:45:12 +02:00
<?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);
}
}