Skip to content

Instantly share code, notes, and snippets.

View asprega's full-sized avatar

Andrea Sprega asprega

View GitHub Profile
@asprega
asprega / FixtureManager.php
Last active January 8, 2022 14:39
Library-less fixtures
<?php
declare(strict_types=1);
namespace App\Test;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Container\ContainerInterface;
/**
@asprega
asprega / FirstLevelRepository.php
Last active December 23, 2021 17:57
PHPStorm issue with @template not inherited from parent classes
<?php
declare(strict_types=1);
/**
* @template TEntity as object
*/
class FirstLevelRepository
{
/**
* @return TEntity
@asprega
asprega / ServiceTest.php
Created October 20, 2021 16:51
[ClockMock article on Medium] Example B - Test with timecop
<?php
declare(strict_types=1);
use DateTimeImmutable;
use Exception;
use PHPUnit\Framework\TestCase;
use App\Service\Service;
class ServiceTest extends TestCase
{
@asprega
asprega / SomeIntegrationTest.php
Created October 20, 2021 16:49
[ClockMock article on Medium] Example A - Test with timecop
<?php
declare(strict_types=1);
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
use App\Entities\Entity;
class SomeIntegrationTest extends TestCase
{
public function test_something_related_to_entity_creation_date()
@asprega
asprega / ServiceTest.php
Last active October 20, 2021 16:43
[ClockMock article on Medium] Example C - Test with timecop
<?php
declare(strict_types=1);
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
use App\Entities\Entity;
use App\Service\Service;
class ServiceTest extends TestCase
{
@asprega
asprega / ServiceTest.php
Last active October 19, 2021 15:58
[ClockMock article on Medium] Example C - Test with ClockMock
<?php
declare(strict_types=1);
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
use App\Entities\Entity;
use App\Service\Service;
use SlopeIt\ClockMock\ClockMock;
class ServiceTest extends TestCase
@asprega
asprega / SomeIntegrationTest.php
Last active October 19, 2021 15:47
[ClockMock article on Medium] Example A - Test with Carbon
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use App\Entities\Entity;
use Carbon\CarbonImmutable;
class SomeIntegrationTest extends TestCase
{
public function test_something_related_to_entity_creation_date()
@asprega
asprega / ServiceTest.php
Last active October 19, 2021 13:22
[ClockMock article on Medium] Example C - Test with Carbon
<?php
declare(strict_types=1);
use Carbon\Carbon;
use PHPUnit\Framework\TestCase;
use App\Entities\Entity;
use App\Service\Service;
class ServiceTest extends TestCase
{
@asprega
asprega / ServiceTest.php
Created October 19, 2021 13:12
[ClockMock article on Medium] Example C - Test with nothing
<?php
declare(strict_types=1);
use DateTimeImmutable;
use Exception;
use PHPUnit\Framework\TestCase;
use App\Service\Service;
class ServiceTest extends TestCase
{
@asprega
asprega / Entity.php
Last active October 19, 2021 13:08
[ClockMock article on Medium] Codebase modified for Carbon
<?php
declare(strict_types=1);
namespace App\Entity;
use Carbon\CarbonImmutable;
class Entity
{
private CarbonImmutable $creationDate;