166 lines
7.0 KiB
PHP
Executable File
166 lines
7.0 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests;
|
|
|
|
use Doctrine\ODM\MongoDB\DocumentManager;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Hautelook\AliceBundle\PhpUnit\BaseDatabaseTrait;
|
|
use PSC\Shop\ContactBundle\Model\AccountType;
|
|
use PSC\Shop\EntityBundle\Document\Contact;
|
|
use PSC\Shop\EntityBundle\Document\Country;
|
|
use PSC\Shop\EntityBundle\Document\Instance;
|
|
use PSC\Shop\EntityBundle\Document\Order;
|
|
use PSC\Shop\EntityBundle\Document\Position;
|
|
use PSC\Shop\EntityBundle\Document\Shop;
|
|
use PSC\Shop\MediaBundle\Document\Media;
|
|
use PSC\System\PluginBundle\Document\Plugin;
|
|
use Symfony\Component\HttpKernel\KernelInterface;
|
|
|
|
trait RefreshDatabaseTrait
|
|
{
|
|
use BaseDatabaseTrait;
|
|
|
|
protected static bool $dbPopulated = false;
|
|
|
|
protected static function bootKernel(array $options = []): KernelInterface
|
|
{
|
|
static::ensureKernelTestCase();
|
|
$kernel = parent::bootKernel($options);
|
|
|
|
if (!static::$dbPopulated) {
|
|
static::populateDatabase();
|
|
static::$dbPopulated = true;
|
|
}
|
|
|
|
$container = static::$kernel->getContainer();
|
|
|
|
/**
|
|
* @var EntityManagerInterface $doc
|
|
*/
|
|
$em = $container->get('doctrine.orm.entity_manager');
|
|
|
|
/**
|
|
* @var DocumentManager $doc
|
|
*/
|
|
$doc = $container->get('doctrine_mongodb.odm.document_manager');
|
|
|
|
$doc->getSchemaManager()->dropDocumentCollection(Media::class);
|
|
$doc->getSchemaManager()->dropDocumentCollection(Order::class);
|
|
$doc->getSchemaManager()->dropDocumentCollection(Position::class);
|
|
$doc->getSchemaManager()->dropDocumentCollection(Instance::class);
|
|
$doc->getSchemaManager()->dropDocumentCollection(Shop::class);
|
|
|
|
if (!$doc->getRepository(Plugin::class)->findOneBy(['pluginId' => '19ff3fd21de9dbd7452fd0a67c928758'])) {
|
|
$plugin = new Plugin();
|
|
$plugin->setInstalled(true);
|
|
$plugin->setPluginId('19ff3fd21de9dbd7452fd0a67c928758');
|
|
$plugin->setName('XML Kalkulations Produkt');
|
|
$plugin->setNamespace('\Plugin\System\PSC\XmlCalc\Plugin');
|
|
$plugin->setPath('System/PSC/XmlCalc');
|
|
$doc->persist($plugin);
|
|
$doc->flush();
|
|
$doc->clear();
|
|
}
|
|
|
|
if (!$doc->getRepository(Instance::class)->findOneBy(['appId' => '1'])) {
|
|
$instance = new Instance();
|
|
$instance->setAppId("1");
|
|
$instance->setInvoiceNumberStart(1);
|
|
$instance->setOfferNumberStart(1);
|
|
$instance->setCancelationNumberStart(1);
|
|
$instance->setCreditNumberStart(1);
|
|
$instance->setNumberStart(1);
|
|
$instance->setParcelCancelationNumberStart(1);
|
|
$instance->setParcelInvoiceNumberStart(1);
|
|
$instance->setInvoiceNumberPattern('RE-{{ "now"|date("Ym") }}-{{number}}');
|
|
$instance->setNumberPattern('AF-{{ "now"|date("Ym") }}-{{number}}');
|
|
$instance->setOfferNumberPattern('AN-{{ "now"|date("Ym") }}-{{number}}');
|
|
$instance->setCreditNumberPattern('GU-{{ "now"|date("Ym") }}-{{number}}');
|
|
$instance->setCancelationNumberPattern('ST-{{ "now"|date("Ym") }}-{{number}}');
|
|
$instance->setParcelCancelationNumberPattern('TS-{{ "now"|date("Ym") }}-{{number}}');
|
|
$instance->setParcelInvoiceNumberPattern('TR-{{ "now"|date("Ym") }}-{{number}}');
|
|
|
|
$doc->persist($instance);
|
|
$doc->flush();
|
|
$doc->clear();
|
|
}
|
|
|
|
$shopEntity = $em->getRepository(\PSC\Shop\EntityBundle\Entity\Shop::class)->findOneBy(['title' => 'Printchampion']);
|
|
|
|
if (!$doc->getRepository(Shop::class)->findOneBy(['uid' => $shopEntity->getUid()])) {
|
|
$shop = new Shop();
|
|
$shop->setUid($shopEntity->getUid());
|
|
$shop->setInvoiceNumberStart(1);
|
|
$shop->setInvoiceOwnNumber(true);
|
|
$shop->setOfferNumberStart(1);
|
|
$shop->setOfferOwnNumber(true);
|
|
$shop->setCancelationNumberStart(1);
|
|
$shop->setCancelationOwnNumber(true);
|
|
$shop->setCreditNumberStart(1);
|
|
$shop->setCreditOwnNumber(true);
|
|
$shop->setNumberStart(1);
|
|
$shop->setOwnNumber(true);
|
|
$shop->setParcelCancelationNumberStart(1);
|
|
$shop->setParcelCancelationOwnNumber(true);
|
|
$shop->setParcelInvoiceNumberStart(1);
|
|
$shop->setParcelInvoiceOwnNumber(true);
|
|
$shop->setInvoiceNumberPattern('SRE-{{ "now"|date("Ym") }}-{{number}}');
|
|
$shop->setNumberPattern('SAF-{{ "now"|date("Ym") }}-{{number}}');
|
|
$shop->setOfferNumberPattern('SAN-{{ "now"|date("Ym") }}-{{number}}');
|
|
$shop->setCreditNumberPattern('SGU-{{ "now"|date("Ym") }}-{{number}}');
|
|
$shop->setCancelationNumberPattern('SST-{{ "now"|date("Ym") }}-{{number}}');
|
|
$shop->setParcelCancelationNumberPattern('STS-{{ "now"|date("Ym") }}-{{number}}');
|
|
$shop->setParcelInvoiceNumberPattern('STR-{{ "now"|date("Ym") }}-{{number}}');
|
|
$shop->setSenderZip(12345);
|
|
$shop->setSenderCity("ShopMusterOrt");
|
|
$shop->setSenderCompany("ShopMusterCompany");
|
|
$shop->setSenderLId("ShopMusterLeitwegId");
|
|
$shop->setSenderIban("ShopMusterIban");
|
|
$shop->setSenderEmail("ShopMusterEmail");
|
|
$shop->setSenderSteuerId("ShopMusterSteuerId");
|
|
|
|
$doc->persist($shop);
|
|
$doc->flush();
|
|
$doc->clear();
|
|
|
|
}
|
|
|
|
if (!$doc->getRepository(Country::class)->findOneBy(['code' => 'DE'])) {
|
|
$country = new Country();
|
|
$country->setCode('DE');
|
|
$country->setShop($shopEntity->getUid());
|
|
$country->setWithTaxWithoutUstNr(true);
|
|
$country->setWithTaxWithUstNr(true);
|
|
|
|
$doc->persist($country);
|
|
$doc->flush();
|
|
$doc->clear();
|
|
}
|
|
$contactEntity = $em->getRepository(\PSC\Shop\EntityBundle\Entity\Contact::class)->findOneBy(['username' => 'company@shop.de']);
|
|
if (!$doc->getRepository(Contact::class)->findOneBy(['uid' => (string)$contactEntity->getUid()])) {
|
|
$contact = new Contact();
|
|
$contact->setAccountType(AccountType::COMPANY);
|
|
$contact->setUid((string)$contactEntity->getUid());
|
|
$doc->persist($contact);
|
|
$doc->flush();
|
|
$doc->clear();
|
|
}
|
|
$contactEntity = $em->getRepository(\PSC\Shop\EntityBundle\Entity\Contact::class)->findOneBy(['username' => 'association@shop.de']);
|
|
if (!$doc->getRepository(Contact::class)->findOneBy(['uid' => (string)$contactEntity->getUid()])) {
|
|
$contact = new Contact();
|
|
$contact->setAccountType(AccountType::ASSOCIATION);
|
|
$contact->setUid((string)$contactEntity->getUid());
|
|
$doc->persist($contact);
|
|
$doc->flush();
|
|
$doc->clear();
|
|
}
|
|
|
|
|
|
|
|
return $kernel;
|
|
}
|
|
|
|
}
|