This commit is contained in:
Kevin Papst
2022-01-01 18:12:57 +01:00
committed by GitHub
parent 0abbba7a56
commit 9731023014
5 changed files with 71 additions and 34 deletions

View File

@@ -0,0 +1,47 @@
<?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\DataFixtures;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
/**
* This fixture makes sure that all data is loaded.
*
* @codeCoverageIgnore
*/
class AllFixtures extends Fixture implements DependentFixtureInterface
{
/**
* @return class-string[]
*/
public function getDependencies()
{
return [
UserFixtures::class,
CustomerFixtures::class,
TagFixtures::class,
TimesheetFixtures::class,
];
}
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
// this is a fake fixture class, it only exists to make developers life easier
// if we use the DependentFixtureInterface on the TimesheetFixture directly,
// we cannot load
// bin/console doctrine:fixtures:load --append --group=timesheet
// without executing all dependent fixtures
}
}

View File

@@ -13,7 +13,6 @@ use App\Entity\Project;
use App\Entity\Team;
use App\Entity\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Faker\Factory;
@@ -26,20 +25,15 @@ use Faker\Factory;
*
* @codeCoverageIgnore
*/
class TeamFixtures extends Fixture implements DependentFixtureInterface
class TeamFixtures extends Fixture
{
public const AMOUNT_TEAMS = 10;
public const MAX_USERS_PER_TEAM = 15;
public const MAX_PROJECTS_PER_TEAM = 5;
/**
* @return string[]
*/
public function getDependencies()
public static function getGroups(): array
{
return [
UserFixtures::class,
];
return ['users', 'team'];
}
/**

View File

@@ -18,7 +18,6 @@ use App\Entity\UserPreference;
use App\Timesheet\Util;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Faker\Factory;
@@ -26,20 +25,20 @@ use Faker\Factory;
* Defines the sample data to load in the database when running the unit and
* functional tests or while development.
*
* Execute this command to load the data:
* Execute this command to load add fixture data:
* bin/console doctrine:fixtures:load
*
* Or simply append it to your running installation:
* bin/console doctrine:fixtures:load --append --group=timesheet
*
* @codeCoverageIgnore
*/
class TimesheetFixtures extends Fixture implements DependentFixtureInterface, FixtureGroupInterface
class TimesheetFixtures extends Fixture implements FixtureGroupInterface
{
public const MIN_TIMESHEETS_PER_USER = 50;
public const MAX_TIMESHEETS_PER_USER = 500;
public const MAX_TIMESHEETS_TOTAL = 5000;
public const MAX_TIMESHEETS_TOTAL = 200;
public const MAX_RUNNING_TIMESHEETS_PER_USER = 1;
public const TIMERANGE_BEGIN_DAYS = 1; // yesterday
public const TIMERANGE_END_DAYS = 1095; // 3 years
public const TIMERANGE_RUNNING = 1047; // in minutes = 17:45 hours
public const MIN_MINUTES_PER_ENTRY = 15;
public const MAX_MINUTES_PER_ENTRY = 840; // 14h
public const MAX_DESCRIPTION_LENGTH = 200;
@@ -49,23 +48,16 @@ class TimesheetFixtures extends Fixture implements DependentFixtureInterface, Fi
public const BATCH_SIZE = 100;
/**
* @return class-string[]
*/
public function getDependencies()
{
return [
UserFixtures::class,
CustomerFixtures::class,
TagFixtures::class,
];
}
public static function getGroups(): array
{
return ['timesheet'];
}
public function getRandomFirstDay(): \DateTime
{
return new \DateTime(rand(-1095, 14) . ' days');
}
/**
* {@inheritdoc}
*/
@@ -218,8 +210,7 @@ class TimesheetFixtures extends Fixture implements DependentFixtureInterface, Fi
private function createTimesheetEntry(User $user, Activity $activity, Project $project, ?string $description, bool $setEndDate)
{
$start = new \DateTime();
$start = $start->modify('- ' . (rand(self::TIMERANGE_BEGIN_DAYS, self::TIMERANGE_END_DAYS)) . ' days');
$start = $this->getRandomFirstDay();
$start = $start->modify('- ' . (rand(1, 86400)) . ' seconds');
$start->setTimezone(new \DateTimeZone($user->getPreferenceValue(UserPreference::TIMEZONE, date_default_timezone_get())));
@@ -246,7 +237,7 @@ class TimesheetFixtures extends Fixture implements DependentFixtureInterface, Fi
} else {
// running entries should be short
$newBegin = clone $entry->getBegin();
$newBegin->setTimestamp(time())->modify('- ' . rand(10, self::TIMERANGE_RUNNING) . ' minutes');
$newBegin->setTimestamp(time())->modify('- ' . rand(self::MIN_MINUTES_PER_ENTRY, self::MAX_MINUTES_PER_ENTRY) . ' minutes');
$entry->setBegin($newBegin);
}

View File

@@ -12,6 +12,7 @@ namespace App\DataFixtures;
use App\Entity\User;
use App\Entity\UserPreference;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
use Doctrine\Persistence\ObjectManager;
use Faker\Factory;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
@@ -25,7 +26,7 @@ use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
*
* @codeCoverageIgnore
*/
class UserFixtures extends Fixture
class UserFixtures extends Fixture implements FixtureGroupInterface
{
public const DEFAULT_PASSWORD = 'kitten';
public const DEFAULT_API_TOKEN = 'api_kitten';
@@ -63,6 +64,11 @@ class UserFixtures extends Fixture
$this->loadTestUsers($manager);
}
public static function getGroups(): array
{
return ['user', 'users'];
}
/**
* Default users for all test cases
*

View File

@@ -76,10 +76,9 @@ final class PaginatedWorkingTimeChart extends SimpleWidget implements UserWidget
$week = $options['week'];
$weekBegin = ($dateTimeFactory->createDateTime())->setISODate($year, $week, 1)->setTime(0, 0, 0);
$weekEnd = ($dateTimeFactory->createDateTime())->setISODate($year, $week, 7)->setTime(23, 59, 59);
$weekBegin = $dateTimeFactory->getStartOfWeek($weekBegin);
$weekEnd = $dateTimeFactory->getEndOfWeek($weekEnd);
$weekEnd = $dateTimeFactory->getEndOfWeek($weekBegin);
$lastWeekInYear = $this->getLastWeekInYear($year);
$lastWeekInLastYear = $this->getLastWeekInYear($year - 1);