Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace App\Tests\Repository;
|
||||
|
||||
use App\Entity\InvoiceDocument;
|
||||
use App\Model\InvoiceDocument;
|
||||
use App\Repository\InvoiceDocumentRepository;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -18,28 +18,34 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
class InvoiceDocumentRepositoryTest extends TestCase
|
||||
{
|
||||
protected static $defaultDirectories = [
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
private static array $defaultDirectories = [
|
||||
'templates/invoice/renderer'
|
||||
];
|
||||
|
||||
protected static $testDocuments = [
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
private static array $testDocuments = [
|
||||
'company.docx',
|
||||
'spreadsheet.xsls',
|
||||
'open-spreadsheet.ods',
|
||||
'default.pdf.twig',
|
||||
];
|
||||
|
||||
protected static $defaultDocuments = [
|
||||
'company.docx',
|
||||
'default.html.twig',
|
||||
'default-pdf.pdf.twig',
|
||||
'freelancer.pdf.twig',
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
private static array $defaultDocuments = [
|
||||
'invoice.html.twig',
|
||||
'default.pdf.twig',
|
||||
'service-date.pdf.twig',
|
||||
'timesheet.html.twig',
|
||||
'text.txt.twig',
|
||||
'javascript.json.twig',
|
||||
'xml.xml.twig',
|
||||
];
|
||||
|
||||
public function testDirectories()
|
||||
public function testDirectories(): void
|
||||
{
|
||||
$sut = new InvoiceDocumentRepository([]);
|
||||
self::assertEmpty($sut->findAll());
|
||||
@@ -78,14 +84,14 @@ class InvoiceDocumentRepositoryTest extends TestCase
|
||||
self::assertEquals($path, $sut->getUploadDirectory());
|
||||
}
|
||||
|
||||
public function testDefaultTemplatesExists()
|
||||
public function testDefaultTemplatesExists(): void
|
||||
{
|
||||
$sut = new InvoiceDocumentRepository(self::$defaultDirectories);
|
||||
$all = $sut->findAll();
|
||||
$this->assertCount(\count(self::$defaultDocuments), $all);
|
||||
|
||||
foreach ($all as $document) {
|
||||
$this->assertTrue(\in_array($document->getName(), self::$defaultDocuments));
|
||||
$this->assertTrue(\in_array($document->getName(), self::$defaultDocuments), 'Missing template: ' . $document->getName());
|
||||
}
|
||||
|
||||
foreach (self::$defaultDocuments as $filename) {
|
||||
|
||||
@@ -14,7 +14,6 @@ use App\Repository\Loader\ActivityLoader;
|
||||
|
||||
/**
|
||||
* @covers \App\Repository\Loader\ActivityLoader
|
||||
* @covers \App\Repository\Loader\ActivityIdLoader
|
||||
*/
|
||||
class ActivityLoaderTest extends AbstractLoaderTest
|
||||
{
|
||||
|
||||
@@ -14,7 +14,6 @@ use App\Repository\Loader\CustomerLoader;
|
||||
|
||||
/**
|
||||
* @covers \App\Repository\Loader\CustomerLoader
|
||||
* @covers \App\Repository\Loader\CustomerIdLoader
|
||||
*/
|
||||
class CustomerLoaderTest extends AbstractLoaderTest
|
||||
{
|
||||
@@ -27,6 +26,6 @@ class CustomerLoaderTest extends AbstractLoaderTest
|
||||
$entity = $this->createMock(Customer::class);
|
||||
$entity->expects($this->once())->method('getId')->willReturn(1);
|
||||
|
||||
$sut->loadResults([$entity]);
|
||||
$sut->loadResults([$entity, 4711]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ use App\Repository\Loader\InvoiceLoader;
|
||||
|
||||
/**
|
||||
* @covers \App\Repository\Loader\InvoiceLoader
|
||||
* @covers \App\Repository\Loader\InvoiceIdLoader
|
||||
*/
|
||||
class InvoiceLoaderTest extends AbstractLoaderTest
|
||||
{
|
||||
|
||||
@@ -15,7 +15,6 @@ use App\Repository\Loader\ProjectLoader;
|
||||
|
||||
/**
|
||||
* @covers \App\Repository\Loader\ProjectLoader
|
||||
* @covers \App\Repository\Loader\ProjectIdLoader
|
||||
*/
|
||||
class ProjectLoaderTest extends AbstractLoaderTest
|
||||
{
|
||||
@@ -33,7 +32,6 @@ class ProjectLoaderTest extends AbstractLoaderTest
|
||||
$em = $this->getEntityManagerMock(4, $results);
|
||||
|
||||
$sut = new ProjectLoader($em);
|
||||
|
||||
$sut->loadResults([$entity]);
|
||||
$sut->loadResults([$entity, 4711]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ use App\Repository\Loader\TeamLoader;
|
||||
|
||||
/**
|
||||
* @covers \App\Repository\Loader\TeamLoader
|
||||
* @covers \App\Repository\Loader\TeamIdLoader
|
||||
*/
|
||||
class TeamLoaderTest extends AbstractLoaderTest
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ use App\Repository\Query\ActivityFormTypeQuery;
|
||||
*/
|
||||
class ActivityFormTypeQueryTest extends BaseFormTypeQueryTest
|
||||
{
|
||||
public function testQuery()
|
||||
public function testQuery(): void
|
||||
{
|
||||
$sut = new ActivityFormTypeQuery();
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ use App\Repository\Query\VisibilityInterface;
|
||||
*/
|
||||
class ActivityQueryTest extends BaseQueryTest
|
||||
{
|
||||
public function testQuery()
|
||||
public function testQuery(): void
|
||||
{
|
||||
$sut = new ActivityQuery();
|
||||
|
||||
|
||||
@@ -43,36 +43,26 @@ abstract class BaseFormTypeQueryTest extends TestCase
|
||||
{
|
||||
self::assertEmpty($sut->getTeams());
|
||||
|
||||
self::assertInstanceOf(BaseFormTypeQuery::class, $sut->addTeam(new Team()));
|
||||
self::assertInstanceOf(BaseFormTypeQuery::class, $sut->addTeam(new Team('foo')));
|
||||
self::assertCount(1, $sut->getTeams());
|
||||
|
||||
$team = new Team();
|
||||
$team = new Team('foo');
|
||||
self::assertInstanceOf(BaseFormTypeQuery::class, $sut->addTeam($team));
|
||||
self::assertCount(1, $sut->getTeams());
|
||||
/* @phpstan-ignore-next-line */
|
||||
self::assertSame($team, $sut->getTeams()[0]);
|
||||
|
||||
self::assertInstanceOf(BaseFormTypeQuery::class, $sut->setTeams([]));
|
||||
$sut->setTeams([]);
|
||||
self::assertEmpty($sut->getTeams());
|
||||
self::assertInstanceOf(BaseFormTypeQuery::class, $sut->setTeams([new Team(), new Team()]));
|
||||
$sut->setTeams([new Team('foo'), new Team('foo')]);
|
||||
self::assertCount(2, $sut->getTeams());
|
||||
}
|
||||
|
||||
protected function assertActivity(BaseFormTypeQuery $sut)
|
||||
{
|
||||
$this->assertNull($sut->getActivity());
|
||||
$this->assertEquals([], $sut->getActivities());
|
||||
$this->assertFalse($sut->hasActivities());
|
||||
|
||||
$expected = new Activity();
|
||||
$expected->setName('foo-bar');
|
||||
|
||||
$sut->setActivity($expected);
|
||||
$this->assertEquals($expected, $sut->getActivity());
|
||||
|
||||
$sut->setActivities([]);
|
||||
$this->assertEquals([], $sut->getActivities());
|
||||
|
||||
$sut->addActivity($expected);
|
||||
$this->assertEquals([$expected], $sut->getActivities());
|
||||
$this->assertTrue($sut->hasActivities());
|
||||
@@ -83,66 +73,38 @@ abstract class BaseFormTypeQueryTest extends TestCase
|
||||
$sut->addActivity($expected2);
|
||||
$this->assertEquals([$expected, $expected2], $sut->getActivities());
|
||||
|
||||
$sut->setActivity(null);
|
||||
$this->assertNull($sut->getActivity());
|
||||
$sut->setActivities([]);
|
||||
$this->assertEquals([], $sut->getActivities());
|
||||
$this->assertEquals([], $sut->getActivities());
|
||||
$this->assertFalse($sut->hasActivities());
|
||||
$this->assertFalse($sut->hasActivities());
|
||||
|
||||
// make sure int is allowed as well
|
||||
$sut->setActivities([99]);
|
||||
$this->assertEquals(99, $sut->getActivity());
|
||||
$this->assertEquals([99], $sut->getActivities());
|
||||
}
|
||||
|
||||
protected function assertCustomer(BaseFormTypeQuery $sut)
|
||||
{
|
||||
$this->assertNull($sut->getCustomer());
|
||||
$this->assertEquals([], $sut->getCustomers());
|
||||
$this->assertFalse($sut->hasCustomers());
|
||||
|
||||
$expected = new Customer();
|
||||
$expected->setName('foo-bar');
|
||||
|
||||
$sut->setCustomer($expected);
|
||||
$this->assertEquals($expected, $sut->getCustomer());
|
||||
|
||||
$sut->setCustomers([]);
|
||||
$this->assertEquals([], $sut->getCustomers());
|
||||
$expected = new Customer('foo-bar');
|
||||
|
||||
$sut->addCustomer($expected);
|
||||
$this->assertEquals([$expected], $sut->getCustomers());
|
||||
$this->assertTrue($sut->hasCustomers());
|
||||
|
||||
$expected2 = new Customer();
|
||||
$expected2->setName('foo-bar2');
|
||||
$expected2 = new Customer('foo-bar2');
|
||||
|
||||
$sut->addCustomer($expected2);
|
||||
$this->assertEquals([$expected, $expected2], $sut->getCustomers());
|
||||
|
||||
$sut->setCustomer(null);
|
||||
$this->assertNull($sut->getCustomer());
|
||||
$sut->setCustomers([]);
|
||||
$this->assertEquals([], $sut->getCustomers());
|
||||
$this->assertEquals([], $sut->getCustomers());
|
||||
$this->assertFalse($sut->hasCustomers());
|
||||
$this->assertFalse($sut->hasCustomers());
|
||||
|
||||
// make sure int is allowed as well
|
||||
$sut->setCustomers([99]);
|
||||
$this->assertEquals(99, $sut->getCustomer());
|
||||
$this->assertEquals([99], $sut->getCustomers());
|
||||
}
|
||||
|
||||
protected function assertProject(BaseFormTypeQuery $sut)
|
||||
{
|
||||
$this->assertNull($sut->getProject());
|
||||
$this->assertEquals([], $sut->getProjects());
|
||||
$this->assertFalse($sut->hasProjects());
|
||||
|
||||
$expected = new Project();
|
||||
$expected->setName('foo-bar');
|
||||
|
||||
$sut->setProject($expected);
|
||||
$this->assertEquals($expected, $sut->getProject());
|
||||
|
||||
$sut->setProjects([]);
|
||||
$this->assertEquals([], $sut->getProjects());
|
||||
|
||||
$sut->addProject($expected);
|
||||
$this->assertEquals([$expected], $sut->getProjects());
|
||||
$this->assertTrue($sut->hasProjects());
|
||||
@@ -153,13 +115,14 @@ abstract class BaseFormTypeQueryTest extends TestCase
|
||||
$sut->addProject($expected2);
|
||||
$this->assertEquals([$expected, $expected2], $sut->getProjects());
|
||||
|
||||
$sut->setProject(null);
|
||||
$this->assertNull($sut->getProject());
|
||||
$sut->setProjects([]);
|
||||
$this->assertEquals([], $sut->getProjects());
|
||||
$this->assertEquals([], $sut->getProjects());
|
||||
$this->assertFalse($sut->hasProjects());
|
||||
$this->assertFalse($sut->hasProjects());
|
||||
|
||||
// make sure int is allowed as well
|
||||
$sut->setProjects([99]);
|
||||
$this->assertEquals(99, $sut->getProject());
|
||||
$this->assertEquals([99], $sut->getProjects());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,24 +32,14 @@ use Symfony\Component\Form\FormFactoryInterface;
|
||||
*/
|
||||
class BaseQueryTest extends TestCase
|
||||
{
|
||||
public function testQuery()
|
||||
public function testQuery(): void
|
||||
{
|
||||
$this->assertBaseQuery(new BaseQuery());
|
||||
$this->assertResetByFormError(new BaseQuery());
|
||||
$this->assertFilter(new BaseQuery());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedDeprecation BaseQuery::getResultType() is deprecated and will be removed with 2.0
|
||||
* @group legacy
|
||||
*/
|
||||
public function testDeprecations()
|
||||
{
|
||||
$sut = new BaseQuery();
|
||||
$sut->getResultType();
|
||||
}
|
||||
|
||||
protected function assertResetByFormError(BaseQuery $sut, $orderBy = 'id', $order = 'ASC')
|
||||
protected function assertResetByFormError(BaseQuery $sut, $orderBy = 'id', $order = 'ASC'): void
|
||||
{
|
||||
$sut->setOrder('ASK');
|
||||
$sut->setOrderBy('foo');
|
||||
@@ -66,7 +56,7 @@ class BaseQueryTest extends TestCase
|
||||
self::assertNull($sut->getSearchTerm());
|
||||
}
|
||||
|
||||
protected function assertBaseQuery(BaseQuery $sut, $orderBy = 'id', $order = BaseQuery::ORDER_ASC)
|
||||
protected function assertBaseQuery(BaseQuery $sut, $orderBy = 'id', $order = BaseQuery::ORDER_ASC): void
|
||||
{
|
||||
$this->assertPage($sut);
|
||||
$this->assertPageSize($sut);
|
||||
@@ -76,12 +66,12 @@ class BaseQueryTest extends TestCase
|
||||
$this->assertBookmark($sut);
|
||||
}
|
||||
|
||||
private function getFormBuilder(string $name)
|
||||
private function getFormBuilder(string $name): FormBuilder
|
||||
{
|
||||
return new FormBuilder($name, null, new EventDispatcher(), $this->createMock(FormFactoryInterface::class), []);
|
||||
}
|
||||
|
||||
protected function resetByFormError(BaseQuery $sut, array $invalidFields)
|
||||
protected function resetByFormError(BaseQuery $sut, array $invalidFields): void
|
||||
{
|
||||
$formBuilder = $this->getFormBuilder('form');
|
||||
$formBuilder->setCompound(true);
|
||||
@@ -104,11 +94,11 @@ class BaseQueryTest extends TestCase
|
||||
$sut->resetByFormError($formErrors);
|
||||
}
|
||||
|
||||
protected function assertTeams(BaseQuery $sut)
|
||||
protected function assertTeams(BaseQuery $sut): void
|
||||
{
|
||||
self::assertEmpty($sut->getTeams());
|
||||
|
||||
self::assertInstanceOf(BaseQuery::class, $sut->addTeam(new Team()));
|
||||
self::assertInstanceOf(BaseQuery::class, $sut->addTeam(new Team('foo')));
|
||||
self::assertEquals(1, \count($sut->getTeams()));
|
||||
|
||||
$sut->setTeams(null);
|
||||
@@ -116,14 +106,14 @@ class BaseQueryTest extends TestCase
|
||||
$sut->setTeams([]);
|
||||
self::assertEmpty($sut->getTeams());
|
||||
|
||||
$team = new Team();
|
||||
$team = new Team('foo');
|
||||
self::assertInstanceOf(BaseQuery::class, $sut->setTeams([$team]));
|
||||
self::assertEquals(1, \count($sut->getTeams()));
|
||||
/* @phpstan-ignore-next-line */
|
||||
self::assertSame($team, $sut->getTeams()[0]);
|
||||
}
|
||||
|
||||
protected function assertFilter(BaseQuery $sut)
|
||||
protected function assertFilter(BaseQuery $sut): void
|
||||
{
|
||||
self::assertEquals(0, $sut->countFilter());
|
||||
$sut->setSearchTerm(new SearchTerm('sdfsdf'));
|
||||
@@ -153,7 +143,7 @@ class BaseQueryTest extends TestCase
|
||||
self::assertFalse($sut->isDefaultFilter('foo'));
|
||||
}
|
||||
|
||||
protected function assertBookmark(BaseQuery $sut)
|
||||
protected function assertBookmark(BaseQuery $sut): void
|
||||
{
|
||||
$bookmark = new Bookmark();
|
||||
self::assertNull($sut->getBookmark());
|
||||
@@ -166,7 +156,7 @@ class BaseQueryTest extends TestCase
|
||||
self::assertTrue($sut->isBookmarkSearch());
|
||||
}
|
||||
|
||||
protected function assertPage(BaseQuery $sut)
|
||||
protected function assertPage(BaseQuery $sut): void
|
||||
{
|
||||
self::assertEquals(1, $sut->getPage());
|
||||
|
||||
@@ -174,7 +164,7 @@ class BaseQueryTest extends TestCase
|
||||
self::assertEquals(42, $sut->getPage());
|
||||
}
|
||||
|
||||
protected function assertPageSize(BaseQuery $sut)
|
||||
protected function assertPageSize(BaseQuery $sut): void
|
||||
{
|
||||
self::assertEquals(BaseQuery::DEFAULT_PAGESIZE, $sut->getPageSize());
|
||||
|
||||
@@ -182,7 +172,7 @@ class BaseQueryTest extends TestCase
|
||||
self::assertEquals(100, $sut->getPageSize());
|
||||
}
|
||||
|
||||
protected function assertOrderBy(BaseQuery $sut, $column = 'id')
|
||||
protected function assertOrderBy(BaseQuery $sut, $column = 'id'): void
|
||||
{
|
||||
self::assertEquals($column, $sut->getOrderBy());
|
||||
|
||||
@@ -190,7 +180,7 @@ class BaseQueryTest extends TestCase
|
||||
self::assertEquals('foo', $sut->getOrderBy());
|
||||
}
|
||||
|
||||
protected function assertOrder(BaseQuery $sut, $order = BaseQuery::ORDER_ASC)
|
||||
protected function assertOrder(BaseQuery $sut, $order = BaseQuery::ORDER_ASC): void
|
||||
{
|
||||
self::assertEquals($order, $sut->getOrder());
|
||||
|
||||
@@ -204,7 +194,7 @@ class BaseQueryTest extends TestCase
|
||||
self::assertEquals(BaseQuery::ORDER_DESC, $sut->getOrder());
|
||||
}
|
||||
|
||||
protected function assertSearchTerm(BaseQuery $sut)
|
||||
protected function assertSearchTerm(BaseQuery $sut): void
|
||||
{
|
||||
self::assertNull($sut->getSearchTerm());
|
||||
|
||||
@@ -219,21 +209,14 @@ class BaseQueryTest extends TestCase
|
||||
self::assertSame($term, $sut->getSearchTerm());
|
||||
}
|
||||
|
||||
protected function assertActivity(TimesheetQuery $sut)
|
||||
protected function assertActivity(TimesheetQuery $sut): void
|
||||
{
|
||||
$this->assertNull($sut->getActivity());
|
||||
$this->assertEquals([], $sut->getActivities());
|
||||
$this->assertFalse($sut->hasActivities());
|
||||
|
||||
$expected = new Activity();
|
||||
$expected->setName('foo-bar');
|
||||
|
||||
$sut->setActivity($expected);
|
||||
$this->assertEquals($expected, $sut->getActivity());
|
||||
|
||||
$sut->setActivities([]);
|
||||
$this->assertEquals([], $sut->getActivities());
|
||||
|
||||
$sut->addActivity($expected);
|
||||
$this->assertEquals([$expected], $sut->getActivities());
|
||||
$this->assertTrue($sut->hasActivities());
|
||||
@@ -243,64 +226,79 @@ class BaseQueryTest extends TestCase
|
||||
|
||||
$sut->addActivity($expected2);
|
||||
$this->assertEquals([$expected, $expected2], $sut->getActivities());
|
||||
$this->assertEquals([], $sut->getActivityIds());
|
||||
|
||||
$sut->setActivity(null);
|
||||
$this->assertNull($sut->getActivity());
|
||||
$sut->setActivities([]);
|
||||
$this->assertEquals([], $sut->getActivities());
|
||||
$this->assertFalse($sut->hasActivities());
|
||||
|
||||
// make sure int is allowed as well
|
||||
$sut->setActivities([99]);
|
||||
$this->assertEquals(99, $sut->getActivity());
|
||||
$this->assertEquals([99], $sut->getActivities());
|
||||
$activity = $this->createMock(Activity::class);
|
||||
$activity->method('getId')->willReturn(13);
|
||||
$sut->addActivity($activity);
|
||||
|
||||
$activity = $this->createMock(Activity::class);
|
||||
$activity->method('getId')->willReturn(27);
|
||||
$sut->addActivity($activity);
|
||||
|
||||
$activity = $this->createMock(Activity::class);
|
||||
$activity->method('getId')->willReturn(null);
|
||||
$sut->addActivity($activity);
|
||||
|
||||
$activity = $this->createMock(Activity::class);
|
||||
$activity->method('getId')->willReturn(27);
|
||||
$sut->addActivity($activity);
|
||||
|
||||
$this->assertEquals([13, 27], $sut->getActivityIds());
|
||||
}
|
||||
|
||||
protected function assertCustomer(ProjectQuery $sut)
|
||||
protected function assertCustomer(ProjectQuery $sut): void
|
||||
{
|
||||
$this->assertNull($sut->getCustomer());
|
||||
$this->assertEquals([], $sut->getCustomers());
|
||||
$this->assertFalse($sut->hasCustomers());
|
||||
|
||||
$expected = new Customer();
|
||||
$expected->setName('foo-bar');
|
||||
|
||||
$sut->setCustomer($expected);
|
||||
$this->assertEquals($expected, $sut->getCustomer());
|
||||
|
||||
$sut->setCustomers([]);
|
||||
$this->assertEquals([], $sut->getCustomers());
|
||||
$expected = new Customer('foo-bar');
|
||||
|
||||
$sut->addCustomer($expected);
|
||||
$this->assertEquals([$expected], $sut->getCustomers());
|
||||
$this->assertTrue($sut->hasCustomers());
|
||||
|
||||
$expected2 = new Customer();
|
||||
$expected2->setName('foo-bar2');
|
||||
$expected2 = new Customer('foo-bar2');
|
||||
|
||||
$sut->addCustomer($expected2);
|
||||
$this->assertEquals([$expected, $expected2], $sut->getCustomers());
|
||||
$this->assertEquals([], $sut->getCustomerIds());
|
||||
|
||||
$sut->setCustomer(null);
|
||||
$this->assertNull($sut->getCustomer());
|
||||
$sut->setCustomers([]);
|
||||
$this->assertEquals([], $sut->getCustomers());
|
||||
$this->assertFalse($sut->hasCustomers());
|
||||
|
||||
// make sure int is allowed as well
|
||||
$sut->setCustomers([99]);
|
||||
$this->assertEquals(99, $sut->getCustomer());
|
||||
$this->assertEquals([99], $sut->getCustomers());
|
||||
$customer = $this->createMock(Customer::class);
|
||||
$customer->method('getId')->willReturn(13);
|
||||
$sut->addCustomer($customer);
|
||||
|
||||
$customer = $this->createMock(Customer::class);
|
||||
$customer->method('getId')->willReturn(27);
|
||||
$sut->addCustomer($customer);
|
||||
|
||||
$customer = $this->createMock(Customer::class);
|
||||
$customer->method('getId')->willReturn(null);
|
||||
$sut->addCustomer($customer);
|
||||
|
||||
$customer = $this->createMock(Customer::class);
|
||||
$customer->method('getId')->willReturn(27);
|
||||
$sut->addCustomer($customer);
|
||||
|
||||
$this->assertEquals([13, 27], $sut->getCustomerIds());
|
||||
}
|
||||
|
||||
protected function assertProject(ActivityQuery $sut)
|
||||
protected function assertProject(ActivityQuery $sut): void
|
||||
{
|
||||
$this->assertNull($sut->getProject());
|
||||
$this->assertEquals([], $sut->getProjects());
|
||||
$this->assertFalse($sut->hasProjects());
|
||||
|
||||
$expected = new Project();
|
||||
$expected->setName('foo-bar');
|
||||
|
||||
$sut->setProject($expected);
|
||||
$this->assertEquals($expected, $sut->getProject());
|
||||
|
||||
$sut->setProjects([]);
|
||||
$this->assertEquals([], $sut->getProjects());
|
||||
|
||||
@@ -313,18 +311,31 @@ class BaseQueryTest extends TestCase
|
||||
|
||||
$sut->addProject($expected2);
|
||||
$this->assertEquals([$expected, $expected2], $sut->getProjects());
|
||||
$this->assertEquals([], $sut->getProjectIds());
|
||||
|
||||
$sut->setProject(null);
|
||||
$this->assertNull($sut->getProject());
|
||||
$sut->setProjects([]);
|
||||
$this->assertFalse($sut->hasProjects());
|
||||
|
||||
// make sure int is allowed as well
|
||||
$sut->setProjects([99]);
|
||||
$this->assertEquals(99, $sut->getProject());
|
||||
$this->assertEquals([99], $sut->getProjects());
|
||||
$project = $this->createMock(Project::class);
|
||||
$project->method('getId')->willReturn(13);
|
||||
$sut->addProject($project);
|
||||
|
||||
$project = $this->createMock(Project::class);
|
||||
$project->method('getId')->willReturn(27);
|
||||
$sut->addProject($project);
|
||||
|
||||
$project = $this->createMock(Project::class);
|
||||
$project->method('getId')->willReturn(null);
|
||||
$sut->addProject($project);
|
||||
|
||||
$project = $this->createMock(Project::class);
|
||||
$project->method('getId')->willReturn(27);
|
||||
$sut->addProject($project);
|
||||
|
||||
$this->assertEquals([13, 27], $sut->getProjectIds());
|
||||
}
|
||||
|
||||
protected function assertDateRangeTrait($sut)
|
||||
protected function assertDateRangeTrait($sut): void
|
||||
{
|
||||
self::assertNull($sut->getBegin());
|
||||
self::assertNull($sut->getEnd());
|
||||
|
||||
@@ -18,13 +18,13 @@ use App\Repository\Query\CustomerFormTypeQuery;
|
||||
*/
|
||||
class CustomerFormTypeQueryTest extends BaseFormTypeQueryTest
|
||||
{
|
||||
public function testQuery()
|
||||
public function testQuery(): void
|
||||
{
|
||||
$sut = new CustomerFormTypeQuery();
|
||||
|
||||
$this->assertBaseQuery($sut);
|
||||
|
||||
$customer = new Customer();
|
||||
$customer = new Customer('foo');
|
||||
self::assertFalse($sut->isAllowCustomerPreselect());
|
||||
$sut->setAllowCustomerPreselect(true);
|
||||
self::assertTrue($sut->isAllowCustomerPreselect());
|
||||
|
||||
@@ -17,7 +17,7 @@ use App\Repository\Query\VisibilityInterface;
|
||||
*/
|
||||
class CustomerQueryTest extends BaseQueryTest
|
||||
{
|
||||
public function testQuery()
|
||||
public function testQuery(): void
|
||||
{
|
||||
$sut = new CustomerQuery();
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ use App\Repository\Query\ExportQuery;
|
||||
*/
|
||||
class ExportQueryTest extends TimesheetQueryTest
|
||||
{
|
||||
public function testQuery()
|
||||
public function testQuery(): void
|
||||
{
|
||||
$sut = new ExportQuery();
|
||||
|
||||
@@ -38,10 +38,10 @@ class ExportQueryTest extends TimesheetQueryTest
|
||||
|
||||
protected function assertMarkAsExported(ExportQuery $sut)
|
||||
{
|
||||
$this->assertFalse($sut->isMarkAsExported());
|
||||
|
||||
$sut->setMarkAsExported(true);
|
||||
$this->assertTrue($sut->isMarkAsExported());
|
||||
|
||||
$sut->setMarkAsExported(false);
|
||||
$this->assertFalse($sut->isMarkAsExported());
|
||||
}
|
||||
|
||||
protected function assertRenderer(ExportQuery $sut)
|
||||
|
||||
@@ -19,7 +19,7 @@ use App\Repository\Query\InvoiceArchiveQuery;
|
||||
*/
|
||||
class InvoiceArchiveQueryTest extends BaseQueryTest
|
||||
{
|
||||
public function testQuery()
|
||||
public function testQuery(): void
|
||||
{
|
||||
$sut = new InvoiceArchiveQuery();
|
||||
self::assertFalse($sut->hasStatus());
|
||||
@@ -30,8 +30,8 @@ class InvoiceArchiveQueryTest extends BaseQueryTest
|
||||
$this->assertEmpty($sut->getCustomers());
|
||||
self::assertFalse($sut->hasCustomers());
|
||||
|
||||
$sut->addCustomer(new Customer());
|
||||
$sut->setCustomers([new Customer()]);
|
||||
$sut->addCustomer(new Customer('foo'));
|
||||
$sut->setCustomers([new Customer('foo')]);
|
||||
self::assertCount(2, $sut->getCustomers());
|
||||
self::assertTrue($sut->hasCustomers());
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ use App\Repository\Query\InvoiceQuery;
|
||||
*/
|
||||
class InvoiceQueryTest extends TimesheetQueryTest
|
||||
{
|
||||
public function testQuery()
|
||||
public function testQuery(): void
|
||||
{
|
||||
$sut = new InvoiceQuery();
|
||||
|
||||
@@ -36,7 +36,6 @@ class InvoiceQueryTest extends TimesheetQueryTest
|
||||
self::assertTrue($sut->isStopped());
|
||||
|
||||
$this->assertExportedWith($sut, InvoiceQuery::STATE_NOT_EXPORTED);
|
||||
$this->assertMarkAsExported($sut);
|
||||
$this->assertModifiedAfter($sut);
|
||||
|
||||
self::assertTrue($sut->getBillable());
|
||||
@@ -48,12 +47,4 @@ class InvoiceQueryTest extends TimesheetQueryTest
|
||||
self::assertFalse($sut->isNotBillable());
|
||||
$this->assertBillable($sut);
|
||||
}
|
||||
|
||||
protected function assertMarkAsExported(InvoiceQuery $sut)
|
||||
{
|
||||
self::assertTrue($sut->isMarkAsExported());
|
||||
|
||||
$sut->setMarkAsExported(false);
|
||||
self::assertFalse($sut->isMarkAsExported());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ use App\Repository\Query\ProjectFormTypeQuery;
|
||||
*/
|
||||
class ProjectFormTypeQueryTest extends BaseFormTypeQueryTest
|
||||
{
|
||||
public function testQuery()
|
||||
public function testQuery(): void
|
||||
{
|
||||
$sut = new ProjectFormTypeQuery();
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ use App\Repository\Query\VisibilityInterface;
|
||||
*/
|
||||
class ProjectQueryTest extends BaseQueryTest
|
||||
{
|
||||
public function testQuery()
|
||||
public function testQuery(): void
|
||||
{
|
||||
$sut = new ProjectQuery();
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ use App\Repository\Query\TagFormTypeQuery;
|
||||
*/
|
||||
class TagFormTypeQueryTest extends BaseFormTypeQueryTest
|
||||
{
|
||||
public function testQuery()
|
||||
public function testQuery(): void
|
||||
{
|
||||
$sut = new TagFormTypeQuery();
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ use App\Repository\Query\TagQuery;
|
||||
*/
|
||||
class TagQueryTest extends BaseQueryTest
|
||||
{
|
||||
public function testQuery()
|
||||
public function testQuery(): void
|
||||
{
|
||||
$sut = new TagQuery();
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ use App\Repository\Query\TeamQuery;
|
||||
*/
|
||||
class TeamQueryTest extends BaseQueryTest
|
||||
{
|
||||
public function testQuery()
|
||||
public function testQuery(): void
|
||||
{
|
||||
$sut = new TeamQuery();
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ use App\Repository\Query\TimesheetQuery;
|
||||
*/
|
||||
class TimesheetQueryTest extends BaseQueryTest
|
||||
{
|
||||
public function testQuery()
|
||||
public function testQuery(): void
|
||||
{
|
||||
$sut = new TimesheetQuery();
|
||||
|
||||
@@ -51,24 +51,24 @@ class TimesheetQueryTest extends BaseQueryTest
|
||||
$this->assertResetByFormError(new TimesheetQuery(), 'begin', 'DESC');
|
||||
}
|
||||
|
||||
protected function assertMaxResults(TimesheetQuery $sut)
|
||||
protected function assertMaxResults(TimesheetQuery $sut): void
|
||||
{
|
||||
self::assertNull($sut->getMaxResults());
|
||||
$sut->setMaxResults(999);
|
||||
self::assertEquals(999, $sut->getMaxResults());
|
||||
}
|
||||
|
||||
protected function assertUser(TimesheetQuery $sut)
|
||||
protected function assertUser(TimesheetQuery $sut): void
|
||||
{
|
||||
self::assertNull($sut->getUser());
|
||||
|
||||
$expected = new User();
|
||||
$expected->setUsername('foo-bar');
|
||||
self::assertInstanceOf(TimesheetQuery::class, $sut->setUser($expected));
|
||||
$expected->setUserIdentifier('foo-bar');
|
||||
$sut->setUser($expected);
|
||||
self::assertEquals($expected, $sut->getUser());
|
||||
}
|
||||
|
||||
protected function assertUsers(TimesheetQuery $sut)
|
||||
protected function assertUsers(TimesheetQuery $sut): void
|
||||
{
|
||||
self::assertEmpty($sut->getUsers());
|
||||
|
||||
@@ -92,7 +92,7 @@ class TimesheetQueryTest extends BaseQueryTest
|
||||
self::assertCount(2, $sut->getUsers());
|
||||
}
|
||||
|
||||
protected function assertState(TimesheetQuery $sut)
|
||||
protected function assertState(TimesheetQuery $sut): void
|
||||
{
|
||||
self::assertEquals(TimesheetQuery::STATE_ALL, $sut->getState());
|
||||
self::assertFalse($sut->isRunning());
|
||||
@@ -101,7 +101,7 @@ class TimesheetQueryTest extends BaseQueryTest
|
||||
$this->assertStateWith($sut, TimesheetQuery::STATE_ALL);
|
||||
}
|
||||
|
||||
protected function assertStateWith(TimesheetQuery $sut, int $defaultState)
|
||||
protected function assertStateWith(TimesheetQuery $sut, int $defaultState): void
|
||||
{
|
||||
self::assertInstanceOf(TimesheetQuery::class, $sut->setState(PHP_INT_MAX));
|
||||
self::assertEquals($defaultState, $sut->getState());
|
||||
@@ -120,7 +120,7 @@ class TimesheetQueryTest extends BaseQueryTest
|
||||
self::assertEquals(TimesheetQuery::STATE_ALL, $sut->getState());
|
||||
}
|
||||
|
||||
protected function assertExported(TimesheetQuery $sut)
|
||||
protected function assertExported(TimesheetQuery $sut): void
|
||||
{
|
||||
self::assertEquals(TimesheetQuery::STATE_ALL, $sut->getExported());
|
||||
self::assertFalse($sut->isExported());
|
||||
@@ -129,9 +129,8 @@ class TimesheetQueryTest extends BaseQueryTest
|
||||
$this->assertExportedWith($sut, TimesheetQuery::STATE_ALL);
|
||||
}
|
||||
|
||||
protected function assertExportedWith(TimesheetQuery $sut, int $defaultState)
|
||||
protected function assertExportedWith(TimesheetQuery $sut, int $defaultState): void
|
||||
{
|
||||
self::assertInstanceOf(TimesheetQuery::class, $sut->setExported(PHP_INT_MAX));
|
||||
self::assertEquals($defaultState, $sut->getExported());
|
||||
|
||||
$sut->setExported(TimesheetQuery::STATE_EXPORTED);
|
||||
@@ -147,11 +146,18 @@ class TimesheetQueryTest extends BaseQueryTest
|
||||
$sut->setExported(TimesheetQuery::STATE_ALL);
|
||||
self::assertEquals(TimesheetQuery::STATE_ALL, $sut->getExported());
|
||||
|
||||
$sut->setExported(2);
|
||||
self::assertEquals(TimesheetQuery::STATE_ALL, $sut->getExported());
|
||||
$catched = false;
|
||||
try {
|
||||
$sut->setExported(2);
|
||||
} catch (\InvalidArgumentException $exception) {
|
||||
$catched = true;
|
||||
$this->assertEquals('Unknown export state given', $exception->getMessage());
|
||||
}
|
||||
|
||||
self::assertTrue($catched);
|
||||
}
|
||||
|
||||
protected function assertModifiedAfter(TimesheetQuery $sut)
|
||||
protected function assertModifiedAfter(TimesheetQuery $sut): void
|
||||
{
|
||||
self::assertNull($sut->getModifiedAfter());
|
||||
$date = new \DateTime('-3 hours');
|
||||
@@ -161,7 +167,7 @@ class TimesheetQueryTest extends BaseQueryTest
|
||||
self::assertSame($date, $sut->getModifiedAfter());
|
||||
}
|
||||
|
||||
protected function assertBillable(TimesheetQuery $sut)
|
||||
protected function assertBillable(TimesheetQuery $sut): void
|
||||
{
|
||||
$sut->setBillable(null);
|
||||
self::assertNull($sut->getBillable());
|
||||
|
||||
@@ -18,7 +18,7 @@ use App\Repository\Query\UserFormTypeQuery;
|
||||
*/
|
||||
class UserFormTypeQueryTest extends BaseFormTypeQueryTest
|
||||
{
|
||||
public function testQuery()
|
||||
public function testQuery(): void
|
||||
{
|
||||
$sut = new UserFormTypeQuery();
|
||||
|
||||
@@ -29,10 +29,13 @@ class UserFormTypeQueryTest extends BaseFormTypeQueryTest
|
||||
{
|
||||
$sut = new UserFormTypeQuery();
|
||||
|
||||
$users = [(new User())->setUsername('foo'), new User(), new User()];
|
||||
$user = new User();
|
||||
$user->setUserIdentifier('foo');
|
||||
|
||||
$users = [$user, new User(), new User()];
|
||||
|
||||
self::assertEquals([], $sut->getUsersAlwaysIncluded());
|
||||
self::assertInstanceOf(UserFormTypeQuery::class, $sut->setUsersAlwaysIncluded($users));
|
||||
$sut->setUsersAlwaysIncluded($users);
|
||||
self::assertSame($users, $sut->getUsersAlwaysIncluded());
|
||||
|
||||
self::assertEquals([], $sut->getUsersToIgnore());
|
||||
|
||||
@@ -18,15 +18,15 @@ use App\Repository\Query\VisibilityInterface;
|
||||
*/
|
||||
class UserQueryTest extends BaseQueryTest
|
||||
{
|
||||
public function testQuery()
|
||||
public function testQuery(): void
|
||||
{
|
||||
$sut = new UserQuery();
|
||||
$this->assertBaseQuery($sut, 'username');
|
||||
$this->assertBaseQuery($sut, 'user');
|
||||
$this->assertInstanceOf(VisibilityInterface::class, $sut);
|
||||
$this->assertRole($sut);
|
||||
$this->assertSearchTeam($sut);
|
||||
|
||||
$this->assertResetByFormError(new UserQuery(), 'username');
|
||||
$this->assertResetByFormError(new UserQuery(), 'user');
|
||||
}
|
||||
|
||||
protected function assertRole(UserQuery $sut)
|
||||
@@ -38,11 +38,23 @@ class UserQueryTest extends BaseQueryTest
|
||||
|
||||
protected function assertSearchTeam(UserQuery $sut)
|
||||
{
|
||||
$team = new Team();
|
||||
$team = new Team('foo');
|
||||
$this->assertIsArray($sut->getSearchTeams());
|
||||
$this->assertEmpty($sut->getSearchTeams());
|
||||
$sut->setSearchTeams([$team, new Team()]);
|
||||
$sut->setSearchTeams([$team, new Team('foo')]);
|
||||
$this->assertCount(2, $sut->getSearchTeams());
|
||||
$this->assertSame($team, $sut->getSearchTeams()[0]);
|
||||
}
|
||||
|
||||
public function testSystemAccount()
|
||||
{
|
||||
$sut = new UserQuery();
|
||||
self::assertNull($sut->getSystemAccount());
|
||||
$sut->setSystemAccount(false);
|
||||
self::assertFalse($sut->getSystemAccount());
|
||||
$sut->setSystemAccount(true);
|
||||
self::assertTrue($sut->getSystemAccount());
|
||||
$sut->setSystemAccount(null);
|
||||
self::assertNull($sut->getSystemAccount());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
<?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\Query;
|
||||
|
||||
use App\Repository\Query\VisibilityInterface;
|
||||
use App\Repository\Query\VisibilityQuery;
|
||||
use App\Repository\Query\VisibilityTrait;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Repository\Query\VisibilityQuery
|
||||
* @covers \App\Repository\Query\VisibilityTrait
|
||||
*/
|
||||
class VisibilityQueryTest extends TestCase
|
||||
{
|
||||
public function testVisibilityQuery()
|
||||
{
|
||||
$sut = new VisibilityQuery();
|
||||
|
||||
$this->assertEquals(VisibilityQuery::SHOW_VISIBLE, $sut->getVisibility());
|
||||
self::assertTrue($sut->isShowVisible());
|
||||
self::assertFalse($sut->isShowHidden());
|
||||
self::assertFalse($sut->isShowBoth());
|
||||
|
||||
/* @phpstan-ignore-next-line */
|
||||
$sut->setVisibility('foo-bar');
|
||||
$this->assertEquals(VisibilityQuery::SHOW_VISIBLE, $sut->getVisibility());
|
||||
|
||||
/* @phpstan-ignore-next-line */
|
||||
$sut->setVisibility('2'); // cast to integer
|
||||
$this->assertEquals(VisibilityQuery::SHOW_HIDDEN, $sut->getVisibility());
|
||||
self::assertFalse($sut->isShowVisible());
|
||||
self::assertTrue($sut->isShowHidden());
|
||||
self::assertFalse($sut->isShowBoth());
|
||||
|
||||
/* @phpstan-ignore-next-line */
|
||||
$sut->setVisibility('0'); // keep the value that was previously set
|
||||
$this->assertEquals(VisibilityQuery::SHOW_HIDDEN, $sut->getVisibility());
|
||||
|
||||
$sut->setVisibility(VisibilityQuery::SHOW_BOTH);
|
||||
$this->assertEquals(VisibilityQuery::SHOW_BOTH, $sut->getVisibility());
|
||||
self::assertFalse($sut->isShowVisible());
|
||||
self::assertFalse($sut->isShowHidden());
|
||||
self::assertTrue($sut->isShowBoth());
|
||||
|
||||
$sut->setVisibility(VisibilityQuery::SHOW_HIDDEN);
|
||||
$this->assertEquals(VisibilityQuery::SHOW_HIDDEN, $sut->getVisibility());
|
||||
|
||||
$sut->setVisibility(VisibilityQuery::SHOW_VISIBLE);
|
||||
$this->assertEquals(VisibilityQuery::SHOW_VISIBLE, $sut->getVisibility());
|
||||
}
|
||||
|
||||
public function testVisibilityTrait()
|
||||
{
|
||||
$sut = new VisibilityTraitImpl();
|
||||
|
||||
$this->assertEquals(VisibilityInterface::SHOW_VISIBLE, $sut->getVisibility());
|
||||
self::assertTrue($sut->isShowVisible());
|
||||
self::assertFalse($sut->isShowHidden());
|
||||
self::assertFalse($sut->isShowBoth());
|
||||
|
||||
/* @phpstan-ignore-next-line */
|
||||
$sut->setVisibility('foo-bar');
|
||||
$this->assertEquals(VisibilityInterface::SHOW_VISIBLE, $sut->getVisibility());
|
||||
|
||||
/* @phpstan-ignore-next-line */
|
||||
$sut->setVisibility('2');
|
||||
$this->assertEquals(VisibilityInterface::SHOW_HIDDEN, $sut->getVisibility());
|
||||
self::assertFalse($sut->isShowVisible());
|
||||
self::assertTrue($sut->isShowHidden());
|
||||
self::assertFalse($sut->isShowBoth());
|
||||
|
||||
/* @phpstan-ignore-next-line */
|
||||
$sut->setVisibility('0'); // keep the value that was previously set
|
||||
$this->assertEquals(VisibilityInterface::SHOW_HIDDEN, $sut->getVisibility());
|
||||
|
||||
$sut->setVisibility(VisibilityInterface::SHOW_BOTH);
|
||||
$this->assertEquals(VisibilityInterface::SHOW_BOTH, $sut->getVisibility());
|
||||
self::assertFalse($sut->isShowVisible());
|
||||
self::assertFalse($sut->isShowHidden());
|
||||
self::assertTrue($sut->isShowBoth());
|
||||
|
||||
$sut->setVisibility(VisibilityInterface::SHOW_HIDDEN);
|
||||
$this->assertEquals(VisibilityInterface::SHOW_HIDDEN, $sut->getVisibility());
|
||||
|
||||
$sut->setVisibility(VisibilityInterface::SHOW_VISIBLE);
|
||||
$this->assertEquals(VisibilityInterface::SHOW_VISIBLE, $sut->getVisibility());
|
||||
}
|
||||
}
|
||||
|
||||
class VisibilityTraitImpl implements VisibilityInterface
|
||||
{
|
||||
use VisibilityTrait;
|
||||
}
|
||||
@@ -31,10 +31,9 @@ class TimesheetInvoiceItemRepositoryTest extends TestCase
|
||||
|
||||
$sut = new TimesheetInvoiceItemRepository($repository);
|
||||
|
||||
/* @phpstan-ignore-next-line */
|
||||
$sut->setExported([new Timesheet(), null, new \stdClass(), new Timesheet(), new Activity()]);
|
||||
// test else for empty array
|
||||
/* @phpstan-ignore-next-line */
|
||||
$sut->setExported([new Customer(), new Project()]);
|
||||
$sut->setExported([new Customer('foo'), new Project()]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,7 @@ use App\Entity\User;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Repository\Query\TimesheetQuery;
|
||||
use App\Repository\RepositoryException;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Tests\DataFixtures\TimesheetFixtures;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
|
||||
/**
|
||||
@@ -43,63 +41,6 @@ class TimesheetRepositoryTest extends AbstractRepositoryTest
|
||||
$this->assertIsArray($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testStoppedEntriesCannotBeStoppedAgain()
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$user = $this->getUserByRole(User::ROLE_USER);
|
||||
/** @var TimesheetRepository $repository */
|
||||
$repository = $em->getRepository(Timesheet::class);
|
||||
|
||||
$fixtures = new TimesheetFixtures();
|
||||
$fixtures->setUser($user);
|
||||
$fixtures->setAmount(1);
|
||||
|
||||
$this->importFixture($fixtures);
|
||||
|
||||
$query = new TimesheetQuery();
|
||||
$query->setUser($user);
|
||||
$query->setState(TimesheetQuery::STATE_STOPPED);
|
||||
|
||||
/** @var array $entities */
|
||||
$entities = $repository->getTimesheetsForQuery($query);
|
||||
|
||||
$this->assertCount(1, $entities);
|
||||
$this->assertInstanceOf(Timesheet::class, $entities[0]);
|
||||
|
||||
$this->expectException(RepositoryException::class);
|
||||
$this->expectExceptionMessage('Timesheet entry already stopped');
|
||||
|
||||
$repository->stopRecording($entities[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testStopRecording()
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$user = $this->getUserByRole(User::ROLE_USER);
|
||||
/** @var TimesheetRepository $repository */
|
||||
$repository = $em->getRepository(Timesheet::class);
|
||||
|
||||
$fixture = new TimesheetFixtures();
|
||||
$fixture->setUser($user);
|
||||
$fixture->setAmountRunning(1);
|
||||
$timesheets = $this->importFixture($fixture);
|
||||
|
||||
$timesheet = $timesheets[0];
|
||||
$this->assertInstanceOf(Timesheet::class, $timesheet);
|
||||
$this->assertNull($timesheet->getEnd());
|
||||
|
||||
$result = $repository->stopRecording($timesheet);
|
||||
$this->assertTrue($result);
|
||||
/* @phpstan-ignore-next-line */
|
||||
$this->assertInstanceOf(\DateTime::class, $timesheet->getEnd());
|
||||
}
|
||||
|
||||
public function testSave()
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
<?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\Repository\TimesheetRepository;
|
||||
use App\Repository\WidgetRepository;
|
||||
use App\Widget\Type\CompoundChart;
|
||||
use App\Widget\Type\Counter;
|
||||
use App\Widget\WidgetException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Repository\WidgetRepository
|
||||
*/
|
||||
class WidgetRepositoryTest extends TestCase
|
||||
{
|
||||
public function testHasWidget()
|
||||
{
|
||||
$repoMock = $this->createMock(TimesheetRepository::class);
|
||||
|
||||
$sut = new WidgetRepository($repoMock, ['test' => []]);
|
||||
|
||||
$this->assertFalse($sut->has('foo'));
|
||||
$this->assertTrue($sut->has('test'));
|
||||
}
|
||||
|
||||
public function testGetWidgetThrowsExceptionOnNonExistingWidget()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Cannot find widget "foo".');
|
||||
|
||||
$repoMock = $this->createMock(TimesheetRepository::class);
|
||||
|
||||
$sut = new WidgetRepository($repoMock, ['test' => []]);
|
||||
$sut->get('foo');
|
||||
}
|
||||
|
||||
public function testGetWidgetThrowsExceptionOnInvalidType()
|
||||
{
|
||||
$this->expectException(WidgetException::class);
|
||||
$this->expectExceptionMessage('Unknown widget type "FooBar"');
|
||||
|
||||
$repoMock = $this->createMock(TimesheetRepository::class);
|
||||
|
||||
$sut = new WidgetRepository($repoMock, ['test' => ['type' => 'FooBar', 'user' => false]]);
|
||||
$sut->get('test');
|
||||
}
|
||||
|
||||
public function testGetWidgetTriggersExceptionOnWrongClass()
|
||||
{
|
||||
$this->expectException(WidgetException::class);
|
||||
$this->expectExceptionMessage('Widget type "App\Widget\Type\CompoundChart" is not an instance of "App\Widget\Type\SimpleStatisticChart"');
|
||||
|
||||
$repoMock = $this->createMock(TimesheetRepository::class);
|
||||
|
||||
$sut = new WidgetRepository($repoMock, ['test' => ['type' => CompoundChart::class, 'user' => false]]);
|
||||
$sut->get('test');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getWidgetData
|
||||
*/
|
||||
public function testGetWidget($data, $query, $dataType)
|
||||
{
|
||||
$repoMock = $this->createMock(TimesheetRepository::class);
|
||||
$repoMock->method('getStatistic')->willReturn($data);
|
||||
|
||||
$widget = [
|
||||
'color' => 'sunny',
|
||||
'icon' => 'far fa-test',
|
||||
'user' => false,
|
||||
'begin' => null,
|
||||
'end' => null,
|
||||
'query' => $query,
|
||||
'title' => 'Test widget',
|
||||
'type' => Counter::class,
|
||||
];
|
||||
|
||||
$sut = new WidgetRepository($repoMock, ['test' => $widget]);
|
||||
$widget = $sut->get('test');
|
||||
|
||||
$options = $widget->getOptions();
|
||||
$this->assertEquals('Test widget', $widget->getTitle());
|
||||
$this->assertEquals($data, $widget->getData());
|
||||
$this->assertEquals('sunny', $options['color']);
|
||||
$this->assertEquals('far fa-test', $options['icon']);
|
||||
$this->assertEquals($dataType, $options['dataType']);
|
||||
}
|
||||
|
||||
public function getWidgetData()
|
||||
{
|
||||
return [
|
||||
[12, TimesheetRepository::STATS_QUERY_DURATION, 'duration'],
|
||||
[112233, TimesheetRepository::STATS_QUERY_AMOUNT, 'int'],
|
||||
[37, TimesheetRepository::STATS_QUERY_ACTIVE, 'int'],
|
||||
[375, TimesheetRepository::STATS_QUERY_RATE, 'money'],
|
||||
[['test' => 'foo'], TimesheetRepository::STATS_QUERY_USER, 'int'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user