feat(monorepo): migrate to typescript monorepo
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Behat\Context;
|
||||
|
||||
use Basango\SharedKernel\Application\Messaging\CommandBus;
|
||||
use Basango\SharedKernel\Application\Messaging\QueryBus;
|
||||
use Behat\Behat\Context\Context;
|
||||
use Symfony\Contracts\Service\ServiceMethodsSubscriberTrait;
|
||||
use Symfony\Contracts\Service\ServiceSubscriberInterface;
|
||||
use Tests\Behat\State\SharedStorage;
|
||||
|
||||
/**
|
||||
* Class AbstractContext.
|
||||
*
|
||||
* @author bernard-ng <bernard@devscast.tech>
|
||||
*/
|
||||
final class AbstractContext implements Context, ServiceSubscriberInterface
|
||||
{
|
||||
use ServiceMethodsSubscriberTrait;
|
||||
|
||||
#[\Override]
|
||||
public static function getSubscribedServices(): array
|
||||
{
|
||||
return [CommandBus::class, QueryBus::class, SharedStorage::class];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Behat\Hook;
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use Behat\Hook\BeforeScenario;
|
||||
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
final readonly class DatabasePurger implements Context
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $entityManager
|
||||
) {
|
||||
}
|
||||
|
||||
#[BeforeScenario]
|
||||
public function purge(): void
|
||||
{
|
||||
$this->entityManager->getConnection()
|
||||
->getConfiguration()
|
||||
->setMiddlewares([]);
|
||||
|
||||
$purger = new ORMPurger($this->entityManager);
|
||||
$purger->purge();
|
||||
|
||||
$this->entityManager->clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Behat\State;
|
||||
|
||||
/**
|
||||
* Class SharedStorage.
|
||||
*
|
||||
* @author bernard-ng <bernard@devscast.tech>
|
||||
*/
|
||||
final class SharedStorage
|
||||
{
|
||||
private array $storage = [];
|
||||
|
||||
public function get(string $key): mixed
|
||||
{
|
||||
return $this->storage[$key] ?? null;
|
||||
}
|
||||
|
||||
public function set(string $key, mixed $value): void
|
||||
{
|
||||
$this->storage[$key] = $value;
|
||||
}
|
||||
|
||||
public function has(string $key): bool
|
||||
{
|
||||
return isset($this->storage[$key]);
|
||||
}
|
||||
|
||||
public function remove(string $key): void
|
||||
{
|
||||
if ($this->has($key)) {
|
||||
unset($this->storage[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\SharedKernel\Domain\Model\ValueObject;
|
||||
|
||||
use Basango\SharedKernel\Domain\Exception\InvalidArgument;
|
||||
use Basango\SharedKernel\Domain\Model\ValueObject\DateRange;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class DateRangeTest.
|
||||
*
|
||||
* @author bernard-ng <bernard@devscast.tech>
|
||||
*/
|
||||
final class DateRangeTest extends TestCase
|
||||
{
|
||||
public function testItShouldCreateDateRange(): void
|
||||
{
|
||||
$dateRange = DateRange::from(
|
||||
'2021-10-01 00:00:00--2021-10-10 00:00:00',
|
||||
'Y-m-d H:i:s',
|
||||
'--'
|
||||
);
|
||||
|
||||
$this->assertEquals(1633046400, $dateRange->start);
|
||||
$this->assertEquals(1633824000, $dateRange->end);
|
||||
}
|
||||
|
||||
public function testEndShouldBeGreaterThanStart(): void
|
||||
{
|
||||
$this->expectException(InvalidArgument::class);
|
||||
DateRange::from('2021-10-10:2021-10-01');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Dotenv\Dotenv;
|
||||
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
if (file_exists(dirname(__DIR__) . '/config/bootstrap.php')) {
|
||||
require dirname(__DIR__) . '/config/bootstrap.php';
|
||||
} elseif (method_exists(Dotenv::class, 'bootEnv')) {
|
||||
new Dotenv()->bootEnv(dirname(__DIR__) . '/.env');
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Basango\SharedKernel\Infrastructure\Framework\Symfony\Kernel;
|
||||
use Symfony\Component\Dotenv\Dotenv;
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
new Dotenv()->bootEnv(__DIR__ . '/../.env');
|
||||
|
||||
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
|
||||
$kernel->boot();
|
||||
|
||||
/** @var Doctrine\Bundle\DoctrineBundle\Registry $doctrine */
|
||||
$doctrine = $kernel->getContainer()->get('doctrine');
|
||||
|
||||
return $doctrine->getManager();
|
||||
Reference in New Issue
Block a user