Skip to content

Instantly share code, notes, and snippets.

@anvodev
Created May 12, 2020 19:39
Show Gist options
  • Select an option

  • Save anvodev/ba781bbb185bd9cd10a8b3746d9c44c5 to your computer and use it in GitHub Desktop.

Select an option

Save anvodev/ba781bbb185bd9cd10a8b3746d9c44c5 to your computer and use it in GitHub Desktop.
Test custom ID generator logic
<?php
//tests/Doctrine/CustomerIdGeneratorTest.php
namespace App\Tests\Doctrine;
use App\Entity\Customer;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class CustomerIdGeneratorTest extends KernelTestCase
{
public function testGenerator()
{
self::bootKernel();
$customer = new Customer();
/** @var EntityManagerInterface $em */
$em = self::$container->get(EntityManagerInterface::class);
$em->persist($customer);
$this->assertRegExp('/[2-8][0-9]{5}/', $customer->getId());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment