1. Go to this page and download the library: Download yapro/doctrine-ext library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use YaPro\DoctrineExt\ReloadDatabaseTrait;
class ExampleClassTest extends KernelTestCase
{
use ReloadDatabaseTrait;
protected static EntityManagerInterface $entityManager;
public static function setUpBeforeClass()
{
self::$entityManager = self::$container->get(EntityManagerInterface::class);
}
public function myTest()
{
$this->truncateClass('My\User');
$this->truncateTable('user_orders');
$this->truncateAllTables();
// ... some useful actions
}
}
namespace App\Entity;
class MyEntity
{
#[ORM\Column(type: Types::BIGINT)]
private int $mybigint = 0;
$items = $this->getEntityManager()->getConnection()->fetchAll("
SELECT
id,
title,
createdAt
FROM Article
WHERE isShow = 1
ORDER BY createdAt DESC
LIMIT 20, 10
");
// get the total number of items like: SELECT COUNT(*) FROM Article WHERE isShow = 1
echo $this->getEntityManager()->getConnection()->fetchColumn(DBALConnectionWrapper::SELECT_FOUND_ROWS);
// if you use TotalItemsTrait you can call:
echo $this->getTotalItems();