69 lines
1.9 KiB
PHP

<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\DocGeneratorBundle\tests\Service\Context;
use Chill\DocGeneratorBundle\Service\Context\BaseContextData;
use Chill\MainBundle\Entity\User;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* @internal
* @coversNothing
*/
final class BaseContextDataTest extends KernelTestCase
{
protected function setUp()
{
parent::setUp();
self::bootKernel();
}
public function testGenerateNoContext()
{
$context = $this->buildBaseContext();
$actual = $context->getData();
$this->assertIsArray($actual);
$this->assertArrayHasKey('creator', $actual);
$this->assertArrayHasKey('createdAt', $actual);
$this->assertArrayHasKey('location', $actual);
}
public function testGenerateWithUser()
{
$security = $this->prophesize(Security::class);
$security->getUser()->willReturn(new User());
$context = $this->buildBaseContext($security->reveal());
$actual = $context->getData();
$this->assertIsArray($actual);
$this->assertArrayHasKey('creator', $actual);
$this->assertArrayHasKey('createdAt', $actual);
$this->assertArrayHasKey('location', $actual);
}
private function buildBaseContext(
?Security $security = null,
?NormalizerInterface $normalizer = null
): BaseContextData {
return new BaseContextData(
$security ?? self::$container->get(Security::class),
$normalizer ?? self::$container->get(NormalizerInterface::class)
);
}
}