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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ jobs:
run: |
composer install --prefer-dist --no-progress --no-suggest

# - name: Run tests
# run: |
# ./vendor/bin/phpunit
- name: Run tests
run: |
./vendor/bin/phpunit

- name: Run PHPStan
run: vendor/bin/phpstan analyse src
run: ./vendor/bin/phpstan analyse src
48 changes: 48 additions & 0 deletions tests/Functional/IpTagged/IpTaggedEntityTest.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\IpTagged;

use Rami\EntityKitBundle\Tests\Util\App\BaseKernel;
use Rami\EntityKitBundle\Tests\Util\Entity\IpTagged\Product;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

class IpTaggedEntityTest extends BaseKernel
{
public function testIpTaggedEntity(): void
{
$request = new Request();
$request->server->set('REMOTE_ADDR', '123.123.123.123');

$requestStack = $this->container->get(RequestStack::class);
$requestStack->push($request);

$product = new Product();
$product->setTitle('Awesome Product');
$this->entityManager->persist($product);
$this->entityManager->flush();

$this->assertInstanceOf(Product::class, $product);
$this->assertNotNull($product->getCreatedFromIp());

$request->server->set('REMOTE_ADDR', '123.123.123.10');

$requestStack = $this->container->get(RequestStack::class);
$requestStack->push($request);

$product->setTitle('new title');

$this->entityManager->flush();

$this->assertEquals('123.123.123.10', $product->getUpdatedFromIp());
}
}
2 changes: 0 additions & 2 deletions tests/Functional/TimeStamped/TimeStampedEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,5 @@ public function testTimeStampedEntity(): void
$this->assertInstanceOf(\DateTimeImmutable::class, $blog->getCreatedAt());
$this->assertInstanceOf(\DateTimeImmutable::class, $blog->getUpdatedAt());

$filesystem = new Filesystem();
$filesystem->remove('var/database.db3');
}
}
3 changes: 0 additions & 3 deletions tests/Functional/Uuid/UuidEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ public function testUuid() : void

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

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

}
9 changes: 9 additions & 0 deletions tests/Util/App/BaseKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\Filesystem\Filesystem;

class BaseKernel extends KernelTestCase
{
Expand All @@ -33,4 +34,12 @@ public function setUp(): void
$schemaTool = new SchemaTool($this->entityManager);
$schemaTool->updateSchema($metaData);
}

public function tearDown(): void
{
parent::tearDown();

$filesystem = new Filesystem();
$filesystem->remove('var/database.db3');
}
}
58 changes: 58 additions & 0 deletions tests/Util/Entity/IpTagged/Product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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\Entity\IpTagged;

use Doctrine\ORM\Mapping as ORM;
use Rami\EntityKitBundle\Common\Interfaces\IpTagged\IpTaggedInterface;
use Rami\EntityKitBundle\Entity\Traits\IpTaggedTrait;
use Rami\EntityKitBundle\Entity\Traits\MappedIpTaggedTrait;

#[ORM\Entity]
class Product implements IpTaggedInterface
{
use MappedIpTaggedTrait;

#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
public ?int $id = null;

#[ORM\Column(type: 'string', length: 255)]
public ?string $title = null;

/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}

/**
* @return string|null
*/
public function getTitle(): ?string
{
return $this->title;
}

/**
* @param string|null $title
* @return Product
*/
public function setTitle(?string $title): Product
{
$this->title = $title;
return $this;
}

}
Loading