Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/.idea
/vendor
/composer.lock
/composer.lock
/var
/.phpunit.result.cache
15 changes: 12 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,28 @@
"symfony/property-access": "^6.4 || ^7.0",
"symfony/string": "^6.4 || ^7.0",
"symfony/security-bundle": "^6.4 || ^7.0",
"symfony/doctrine-bridge": "^7.2",
"symfony/uid": "^6.4 || ^7.0"
"symfony/doctrine-bridge": "^6.4 || ^7.0",
"symfony/uid": "^6.4 || ^7.0",
"doctrine/doctrine-bundle": "^2.14"
},
"require-dev": {
"phpstan/phpstan": "*",
"symfony/phpunit-bridge": "^6.4 || ^7.0"
"symfony/phpunit-bridge": "^6.4 || ^7.0",
"symfony/test-pack": "^1.1",
"symfony/framework-bundle": "^6.4 || ^7.0",
"symfony/yaml": "^6.4 || ^7.0"
},
"license": "MIT",
"autoload": {
"psr-4": {
"Rami\\EntityKitBundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Rami\\EntityKitBundle\\Tests\\": "tests/"
}
},
"authors": [
{
"name": "Abdellah Ramadan",
Expand Down
16 changes: 16 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<php>
<server name="KERNEL_CLASS" value="Rami\EntityKitBundle\Tests\Util\App\Kernel" />
</php>

<testsuites>
<testsuite name="test">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
8 changes: 6 additions & 2 deletions src/EventListener/Authored/AuthoredListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\User\UserInterface;

readonly class AuthoredListener
class AuthoredListener
{
public function __construct(
private TokenStorageInterface $tokenStorage,
private ?TokenStorageInterface $tokenStorage = null,
) {}
public function prePersist(PrePersistEventArgs $args): void
{
Expand Down Expand Up @@ -54,6 +54,10 @@ public function preUpdate(PreUpdateEventArgs $args): void

private function getCurrentUserIdentifier(): string|null
{
if (null === $this->tokenStorage) {
return null;
}

$user = $this->tokenStorage->getToken()->getUser();

if (!$user instanceof UserInterface) {
Expand Down
1 change: 0 additions & 1 deletion src/EventListener/Uuid/UuidListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Doctrine\ORM\Event\PrePersistEventArgs;
use Rami\EntityKitBundle\Common\Interfaces\Uuid\UuidInterface;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\Uid\UuidV4;

class UuidListener
{
Expand Down
48 changes: 48 additions & 0 deletions tests/Functional/TimeStamped/TimeStampedEntityTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/*
* Copyright (c) 2025.
*
* This file is part of the Entity Kit Bundle project
* @author Abdellah Ramadan <ramadanabdel24@gmail.com>
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code.
*/

namespace Rami\EntityKitBundle\Tests\Functional\TimeStamped;

use Rami\EntityKitBundle\Tests\Util\App\BaseKernel;
use Rami\EntityKitBundle\Tests\Util\Entity\TimeStamped\Article;
use Symfony\Component\Filesystem\Filesystem;

class TimeStampedEntityTest extends BaseKernel
{
public function setUp(): void
{
parent::setUp();
}

public function testTimeStampedEntity(): void
{
$blog = new Article();

$blog->setTitle('Blog title');
$blog->setContent('Blog content');

$this->entityManager->persist($blog);
$this->entityManager->flush();

$this->assertNotNull($blog->getId());
$this->assertEquals('Blog title', $blog->getTitle());
$this->assertEquals('Blog content', $blog->getContent());

$this->assertNotNull($blog->getCreatedAt());
$this->assertNotNull($blog->getUpdatedAt());

$this->assertInstanceOf(\DateTimeImmutable::class, $blog->getCreatedAt());
$this->assertInstanceOf(\DateTimeImmutable::class, $blog->getUpdatedAt());

$filesystem = new Filesystem();
$filesystem->remove('var/database.db3');
}
}
44 changes: 44 additions & 0 deletions tests/Functional/Uuid/UuidEntityTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/*
* Copyright (c) 2025.
*
* This file is part of the Entity Kit Bundle project
* @author Abdellah Ramadan <ramadanabdel24@gmail.com>
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code.
*/

namespace Rami\EntityKitBundle\Tests\Functional\Uuid;

use Rami\EntityKitBundle\Tests\Util\App\BaseKernel;
use Rami\EntityKitBundle\Tests\Util\Entity\Uuid\User;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Uid\Uuid;

class UuidEntityTest extends BaseKernel
{

public function setUp(): void
{
parent::setUp();
}

public function testUuid() : void
{
$user = new User();

$this->entityManager->persist($user);
$this->entityManager->flush();

$this->assertNotNull($user->getId());
$this->assertNotNull($user->getUuid());

$this->assertInstanceOf(User::class, $user);
$this->assertInstanceOf(Uuid::class, $user->getUuid());

$filesystem = new Filesystem();
$filesystem->remove('var/database.db3');
}

}
22 changes: 22 additions & 0 deletions tests/Unit/UnitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/*
* Copyright (c) 2025.
*
* This file is part of the Entity Kit Bundle project
* @author Abdellah Ramadan <ramadanabdel24@gmail.com>
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code.
*/

namespace Rami\EntityKitBundle\Tests\Unit;

use PHPUnit\Framework\TestCase;

class UnitTest extends TestCase
{
public function testSomething()
{
$this->assertEquals('PersistenceBundleTest', 'PersistenceBundleTest');
}
}
36 changes: 36 additions & 0 deletions tests/Util/App/BaseKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/*
* Copyright (c) 2025.
*
* This file is part of the Entity Kit Bundle project
* @author Abdellah Ramadan <ramadanabdel24@gmail.com>
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code.
*/

namespace Rami\EntityKitBundle\Tests\Util\App;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\SchemaTool;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\DependencyInjection\Container;

class BaseKernel extends KernelTestCase
{
protected Container $container;
protected EntityManager $entityManager;

public function setUp(): void
{
self::bootKernel();
$this->container = static::getContainer();
$doctrine = $this->container->get('doctrine');
$this->entityManager = $doctrine->getManager();
$metaData = $this->entityManager->getMetadataFactory()->getAllMetadata();
$schemaTool = new SchemaTool($this->entityManager);
$schemaTool->updateSchema($metaData);
}
}
55 changes: 55 additions & 0 deletions tests/Util/App/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/*
* Copyright (c) 2025.
*
* This file is part of the Entity Kit Bundle project
* @author Abdellah Ramadan <ramadanabdel24@gmail.com>
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Rami\EntityKitBundle\Tests\Util\App;

use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Rami\EntityKitBundle\EntityKitBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel as HttpKernel;

class Kernel extends HttpKernel
{

public function registerBundles(): iterable
{
return [
new EntityKitBundle(),
new FrameworkBundle(),
new DoctrineBundle(),
new SecurityBundle(),
];
}

public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->load(__DIR__ . '/config/config.yaml');
}

public function getCacheDir(): string
{
return 'var/cache';
}

public function getLogDir(): string
{
return 'var/logs';
}

public function getProjectDir(): string
{
return __DIR__.'/../';
}
}
26 changes: 26 additions & 0 deletions tests/Util/App/config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
framework:
secret: "test"
test: ~

doctrine:
dbal:
driver: "pdo_sqlite"
path: "%kernel.cache_dir%/../database.db3"

orm:
mappings:
Test:
dir: '%kernel.project_dir%/'
prefix: 'Rami\EntityKitBundle\Tests\Util\Entity'

security:
providers:
test_users:
memory: null

firewalls:
test:
pattern: ^/
security: false

access_control: []
Loading