Files
kimai/tests/Repository/TimesheetRepositoryTest.php
Kevin Papst 677f8d776c [3.0] Update Symfony to 7.4 and dependencies, removed deprecated code, removed API password (#5622)
* deactivate deprecated auto-mapping
* use native month-picker with fallback on old browser
* bump dependencies to new major versions
* replace deprecated ARRAY column type with JSON
* named arguments
* nullable arguments
* native lazy ghosts
* update routes to use php config
* disable PHP < 8.4
* use static RTL configuration
* new qr code package
* clear out env file
* recipe updates
* fix deprecations
* preset new env variable if not existing
* bump maria db version examples
* remove deprecated api-token support
* fix validator deprecations
* remove timesheet category column
* fix broken validator autoconfiguration
* stabilize tests
* fix migration syntax compatibility
* fix doctrine deprecation
* fix datetime format
* remove constructor dependency
* only include visible preferences in invoice templates
* fix test container dependency
* removed ProjectConstraint multi-constraint logic
* allow to disable plugins in certain environments
* refactor TimesheetConstraint to non-service
* activate new interface methods
* prevent update issues with .env
* improved customer fixture
* removed $user->isExportDecimal()
2026-01-04 15:04:25 +01:00

116 lines
4.0 KiB
PHP

<?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\Repository;
use App\Entity\Activity;
use App\Entity\Project;
use App\Entity\Tag;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Repository\ActivityRepository;
use App\Repository\ProjectRepository;
use App\Repository\Query\TimesheetQuery;
use App\Repository\Query\TimesheetQueryHint;
use App\Repository\TimesheetRepository;
use App\Utils\Pagination;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
#[CoversClass(TimesheetRepository::class)]
#[Group('integration')]
class TimesheetRepositoryTest extends AbstractRepositoryTestCase
{
public function testResultTypeForQueryState(): void
{
$em = $this->getEntityManager();
/** @var TimesheetRepository $repository */
$repository = $em->getRepository(Timesheet::class);
$query = new TimesheetQuery();
$result = $repository->getPagerfantaForQuery($query);
self::assertInstanceOf(Pagination::class, $result);
self::assertFalse($query->hasQueryHint(TimesheetQueryHint::CUSTOMER_META_FIELDS));
self::assertFalse($query->hasQueryHint(TimesheetQueryHint::PROJECT_META_FIELDS));
self::assertFalse($query->hasQueryHint(TimesheetQueryHint::ACTIVITY_META_FIELDS));
}
public function testSave(): void
{
$em = $this->getEntityManager();
/** @var ActivityRepository $activityRepository */
$activityRepository = $em->getRepository(Activity::class);
$activity = $activityRepository->find(1);
/** @var ProjectRepository $projectRepository */
$projectRepository = $em->getRepository(Project::class);
$project = $projectRepository->find(1);
$user = $this->getUserByRole(User::ROLE_USER);
/** @var TimesheetRepository $repository */
$repository = $em->getRepository(Timesheet::class);
$timesheet = new Timesheet();
$timesheet
->setBegin(new \DateTime())
->setEnd(new \DateTime())
->setDescription('foo')
->setUser($user)
->setActivity($activity)
->setProject($project);
self::assertNull($timesheet->getId());
$repository->save($timesheet);
self::assertNotNull($timesheet->getId());
}
public function testSaveWithTags(): void
{
$em = $this->getEntityManager();
/** @var ActivityRepository $activityRepository */
$activityRepository = $em->getRepository(Activity::class);
$activity = $activityRepository->find(1);
/** @var ProjectRepository $projectRepository */
$projectRepository = $em->getRepository(Project::class);
$project = $projectRepository->find(1);
$user = $this->getUserByRole(User::ROLE_USER);
/** @var TimesheetRepository $repository */
$repository = $em->getRepository(Timesheet::class);
$tagOne = new Tag();
$tagOne->setName('Travel');
$tagTwo = new Tag();
$tagTwo->setName('Picture');
$timesheet = new Timesheet();
$timesheet
->setBegin(new \DateTime())
->setEnd(new \DateTime())
->setDescription('foo')
->setUser($user)
->setActivity($activity)
->setProject($project)
->addTag($tagOne)
->addTag($tagTwo);
self::assertNull($timesheet->getId());
$repository->save($timesheet);
self::assertNotNull($timesheet->getId());
self::assertEquals(2, $timesheet->getTags()->count());
$tag = $timesheet->getTags()->get(0);
self::assertInstanceOf(Tag::class, $tag);
self::assertEquals('Travel', $tag->getName());
self::assertNotNull($tag->getId());
$tag = $timesheet->getTags()->get(1);
self::assertInstanceOf(Tag::class, $tag);
self::assertEquals('Picture', $tag->getName());
self::assertNotNull($tag->getId());
}
}