Drop SQLite support (#2405)
This commit is contained in:
@@ -11,14 +11,13 @@ namespace App\Tests\DataFixtures;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Project;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Faker\Factory;
|
||||
|
||||
/**
|
||||
* Defines the sample data to load in during controller tests.
|
||||
*/
|
||||
final class ActivityFixtures extends Fixture
|
||||
final class ActivityFixtures implements TestFixture
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
@@ -95,10 +94,13 @@ final class ActivityFixtures extends Fixture
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @param ObjectManager $manager
|
||||
* @return Activity[]
|
||||
*/
|
||||
public function load(ObjectManager $manager)
|
||||
public function load(ObjectManager $manager): array
|
||||
{
|
||||
$created = [];
|
||||
|
||||
$projects = $this->projects;
|
||||
if (empty($projects)) {
|
||||
$projects = $this->getAllProjects($manager);
|
||||
@@ -126,16 +128,20 @@ final class ActivityFixtures extends Fixture
|
||||
\call_user_func($this->callback, $activity);
|
||||
}
|
||||
$manager->persist($activity);
|
||||
|
||||
$created[] = $activity;
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
|
||||
return $created;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ObjectManager $manager
|
||||
* @return array<int|string, Project>
|
||||
*/
|
||||
protected function getAllProjects(ObjectManager $manager): array
|
||||
private function getAllProjects(ObjectManager $manager): array
|
||||
{
|
||||
$all = [];
|
||||
/** @var Project[] $entries */
|
||||
|
||||
@@ -10,14 +10,13 @@
|
||||
namespace App\Tests\DataFixtures;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Faker\Factory;
|
||||
|
||||
/**
|
||||
* Defines the sample data to load in during controller tests.
|
||||
*/
|
||||
final class CustomerFixtures extends Fixture
|
||||
final class CustomerFixtures implements TestFixture
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
@@ -65,10 +64,13 @@ final class CustomerFixtures extends Fixture
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @param ObjectManager $manager
|
||||
* @return Customer[]
|
||||
*/
|
||||
public function load(ObjectManager $manager)
|
||||
public function load(ObjectManager $manager): array
|
||||
{
|
||||
$created = [];
|
||||
|
||||
$faker = Factory::create();
|
||||
|
||||
for ($i = 0; $i < $this->amount; $i++) {
|
||||
@@ -92,8 +94,11 @@ final class CustomerFixtures extends Fixture
|
||||
\call_user_func($this->callback, $customer);
|
||||
}
|
||||
$manager->persist($customer);
|
||||
$created[] = $customer;
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
|
||||
return $created;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,28 +10,22 @@
|
||||
namespace App\Tests\DataFixtures;
|
||||
|
||||
use App\Entity\InvoiceTemplate;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Faker\Factory;
|
||||
|
||||
/**
|
||||
* Defines the sample data to load in during controller tests.
|
||||
*/
|
||||
class InvoiceFixtures extends Fixture
|
||||
class InvoiceTemplateFixtures implements TestFixture
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$this->loadInvoiceTemplates($manager);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ObjectManager $manager
|
||||
* @return InvoiceTemplate[]
|
||||
*/
|
||||
private function loadInvoiceTemplates(ObjectManager $manager)
|
||||
public function load(ObjectManager $manager): array
|
||||
{
|
||||
$created = [];
|
||||
|
||||
$faker = Factory::create();
|
||||
|
||||
$template = new InvoiceTemplate();
|
||||
@@ -58,5 +52,9 @@ class InvoiceFixtures extends Fixture
|
||||
|
||||
$manager->persist($template);
|
||||
$manager->flush();
|
||||
|
||||
$created[] = $template;
|
||||
|
||||
return $created;
|
||||
}
|
||||
}
|
||||
@@ -11,14 +11,13 @@ namespace App\Tests\DataFixtures;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Faker\Factory;
|
||||
|
||||
/**
|
||||
* Defines the sample data to load in during controller tests.
|
||||
*/
|
||||
final class ProjectFixtures extends Fixture
|
||||
final class ProjectFixtures implements TestFixture
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
@@ -81,10 +80,12 @@ final class ProjectFixtures extends Fixture
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @param ObjectManager $manager
|
||||
* @return Project[]
|
||||
*/
|
||||
public function load(ObjectManager $manager)
|
||||
public function load(ObjectManager $manager): array
|
||||
{
|
||||
$created = [];
|
||||
$customers = $this->customers;
|
||||
if (empty($customers)) {
|
||||
$customers = $this->getAllCustomers($manager);
|
||||
@@ -109,16 +110,19 @@ final class ProjectFixtures extends Fixture
|
||||
\call_user_func($this->callback, $project);
|
||||
}
|
||||
$manager->persist($project);
|
||||
$created[] = $project;
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
|
||||
return $created;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ObjectManager $manager
|
||||
* @return array<int|string, Customer>
|
||||
*/
|
||||
protected function getAllCustomers(ObjectManager $manager): array
|
||||
private function getAllCustomers(ObjectManager $manager): array
|
||||
{
|
||||
$all = [];
|
||||
/** @var Customer[] $entries */
|
||||
|
||||
@@ -10,13 +10,12 @@
|
||||
namespace App\Tests\DataFixtures;
|
||||
|
||||
use App\Entity\Tag;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
|
||||
/**
|
||||
* Defines the sample data to load in during controller tests.
|
||||
*/
|
||||
final class TagFixtures extends Fixture
|
||||
final class TagFixtures implements TestFixture
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
@@ -60,10 +59,13 @@ final class TagFixtures extends Fixture
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @param ObjectManager $manager
|
||||
* @return Tag[]
|
||||
*/
|
||||
public function load(ObjectManager $manager)
|
||||
public function load(ObjectManager $manager): array
|
||||
{
|
||||
$created = [];
|
||||
|
||||
foreach ($this->getTagArray() as $tagName) {
|
||||
$tag = $this->createTagEntry($tagName);
|
||||
|
||||
@@ -71,8 +73,11 @@ final class TagFixtures extends Fixture
|
||||
\call_user_func($this->callback, $tag);
|
||||
}
|
||||
$manager->persist($tag);
|
||||
$created[] = $tag;
|
||||
}
|
||||
$manager->flush();
|
||||
|
||||
return $created;
|
||||
}
|
||||
|
||||
private function createTagEntry(string $tagName): Tag
|
||||
|
||||
@@ -12,14 +12,13 @@ namespace App\Tests\DataFixtures;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Team;
|
||||
use App\Entity\User;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Faker\Factory;
|
||||
|
||||
/**
|
||||
* Defines the sample data to load in during controller tests.
|
||||
*/
|
||||
final class TeamFixtures extends Fixture
|
||||
final class TeamFixtures implements TestFixture
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
@@ -89,10 +88,13 @@ final class TeamFixtures extends Fixture
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @param ObjectManager $manager
|
||||
* @return Team[]
|
||||
*/
|
||||
public function load(ObjectManager $manager)
|
||||
public function load(ObjectManager $manager): array
|
||||
{
|
||||
$created = [];
|
||||
|
||||
$faker = Factory::create();
|
||||
$user = $this->getAllUsers($manager);
|
||||
$customer = $this->getAllCustomers($manager);
|
||||
@@ -131,9 +133,12 @@ final class TeamFixtures extends Fixture
|
||||
\call_user_func($this->callback, $team);
|
||||
}
|
||||
$manager->persist($team);
|
||||
$created[] = $team;
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
|
||||
return $created;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
23
tests/DataFixtures/TestFixture.php
Normal file
23
tests/DataFixtures/TestFixture.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\DataFixtures;
|
||||
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
|
||||
/**
|
||||
* Defines the sample data to load in during controller tests.
|
||||
*/
|
||||
interface TestFixture
|
||||
{
|
||||
/**
|
||||
* Load data fixtures with the passed EntityManager and returns the created objects.
|
||||
*/
|
||||
public function load(ObjectManager $manager): array;
|
||||
}
|
||||
@@ -16,14 +16,13 @@ use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Entity\UserPreference;
|
||||
use App\Timesheet\Util;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Faker\Factory;
|
||||
|
||||
/**
|
||||
* Defines the sample data to load in during controller tests.
|
||||
*/
|
||||
final class TimesheetFixtures extends Fixture
|
||||
final class TimesheetFixtures implements TestFixture
|
||||
{
|
||||
/**
|
||||
* @var User
|
||||
@@ -205,10 +204,13 @@ final class TimesheetFixtures extends Fixture
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @param ObjectManager $manager
|
||||
* @return Timesheet[]
|
||||
*/
|
||||
public function load(ObjectManager $manager)
|
||||
public function load(ObjectManager $manager): array
|
||||
{
|
||||
$created = [];
|
||||
|
||||
$activities = $this->activities;
|
||||
if (empty($activities)) {
|
||||
$activities = $this->getAllActivities($manager);
|
||||
@@ -222,6 +224,12 @@ final class TimesheetFixtures extends Fixture
|
||||
$faker = Factory::create();
|
||||
$user = $this->user;
|
||||
|
||||
$tags = $this->getTagObjectList();
|
||||
foreach ($tags as $tag) {
|
||||
$manager->persist($tag);
|
||||
}
|
||||
$manager->flush();
|
||||
|
||||
for ($i = 0; $i < $this->amount; $i++) {
|
||||
$description = $faker->text;
|
||||
if ($this->allowEmptyDescriptions) {
|
||||
@@ -239,8 +247,6 @@ final class TimesheetFixtures extends Fixture
|
||||
$project = $projects[array_rand($projects)];
|
||||
}
|
||||
|
||||
$tags = $this->getTagObjectList($i);
|
||||
|
||||
$timesheet = $this->createTimesheetEntry(
|
||||
$user,
|
||||
$activity,
|
||||
@@ -254,6 +260,7 @@ final class TimesheetFixtures extends Fixture
|
||||
\call_user_func($this->callback, $timesheet);
|
||||
}
|
||||
$manager->persist($timesheet);
|
||||
$created[] = $timesheet;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $this->running; $i++) {
|
||||
@@ -264,8 +271,6 @@ final class TimesheetFixtures extends Fixture
|
||||
$project = $projects[array_rand($projects)];
|
||||
}
|
||||
|
||||
$tags = $this->getTagObjectList($i);
|
||||
|
||||
$timesheet = $this->createTimesheetEntry(
|
||||
$user,
|
||||
$activity,
|
||||
@@ -280,24 +285,32 @@ final class TimesheetFixtures extends Fixture
|
||||
\call_user_func($this->callback, $timesheet);
|
||||
}
|
||||
$manager->persist($timesheet);
|
||||
$created[] = $timesheet;
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
|
||||
return $created;
|
||||
}
|
||||
|
||||
protected function getTagObjectList(int $cnt): array
|
||||
private function getTagObjectList(): array
|
||||
{
|
||||
if (true === $this->useTags) {
|
||||
$tagObject = new Tag();
|
||||
$tagObject->setName($this->tags[($cnt % \count($this->tags))]);
|
||||
$all = [];
|
||||
foreach ($this->tags as $tagName) {
|
||||
$tagObject = new Tag();
|
||||
$tagObject->setName($tagName);
|
||||
|
||||
return [$tagObject];
|
||||
$all[] = $tagObject;
|
||||
}
|
||||
|
||||
return $all;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function getDateTime(int $i): \DateTime
|
||||
private function getDateTime(int $i): \DateTime
|
||||
{
|
||||
$start = \DateTime::createFromFormat('Y-m-d', $this->startDate);
|
||||
$start->modify("+ $i days");
|
||||
@@ -310,7 +323,7 @@ final class TimesheetFixtures extends Fixture
|
||||
* @param ObjectManager $manager
|
||||
* @return array<int|string, Activity>
|
||||
*/
|
||||
protected function getAllActivities(ObjectManager $manager): array
|
||||
private function getAllActivities(ObjectManager $manager): array
|
||||
{
|
||||
$all = [];
|
||||
/** @var Activity[] $entries */
|
||||
@@ -326,7 +339,7 @@ final class TimesheetFixtures extends Fixture
|
||||
* @param ObjectManager $manager
|
||||
* @return array<int|string, Project>
|
||||
*/
|
||||
protected function getAllProjects(ObjectManager $manager): array
|
||||
private function getAllProjects(ObjectManager $manager): array
|
||||
{
|
||||
$all = [];
|
||||
/** @var Project[] $entries */
|
||||
|
||||
Reference in New Issue
Block a user