Added filter constraint for manufacturing status.

This commit is contained in:
Jan Böhmer 2022-09-04 00:45:10 +02:00
parent 7b3538a2c7
commit ec5e956e31
11 changed files with 342 additions and 1 deletions

View file

@ -0,0 +1,112 @@
<?php
namespace App\Tests\DataTables\Filters;
use App\DataTables\Filters\CompoundFilterTrait;
use App\DataTables\Filters\FilterInterface;
use Doctrine\ORM\QueryBuilder;
use PHPUnit\Framework\TestCase;
class CompoundFilterTraitTest extends TestCase
{
public function testFindAllChildFiltersEmpty(): void
{
$filter = new class {
use CompoundFilterTrait;
public function _findAllChildFilters()
{
return $this->findAllChildFilters();
}
};
$result = $filter->_findAllChildFilters();
$this->assertIsArray($result);
$this->assertEmpty($result);
}
public function testFindAllChildFilters(): void
{
$f1 = $this->createMock(FilterInterface::class);
$f2 = $this->createMock(FilterInterface::class);
$f3 = $this->createMock(FilterInterface::class);
$filter = new class($f1, $f2, $f3, null) {
use CompoundFilterTrait;
protected $filter1;
private $filter2;
public $filter3;
protected $filter4;
public function __construct($f1, $f2, $f3, $f4) {
$this->filter1 = $f1;
$this->filter2 = $f2;
$this->filter3 = $f3;
$this->filter4 = $f4;
}
public function _findAllChildFilters()
{
return $this->findAllChildFilters();
}
};
$result = $filter->_findAllChildFilters();
$this->assertIsArray($result);
$this->assertContainsOnlyInstancesOf(FilterInterface::class, $result);
$this->assertSame([
'filter1' => $f1,
'filter2' => $f2,
'filter3' => $f3
], $result);
}
public function testApplyAllChildFilters(): void
{
$f1 = $this->createMock(FilterInterface::class);
$f2 = $this->createMock(FilterInterface::class);
$f3 = $this->createMock(FilterInterface::class);
$f1->expects($this->once())
->method('apply')
->with($this->isInstanceOf(QueryBuilder::class));
$f2->expects($this->once())
->method('apply')
->with($this->isInstanceOf(QueryBuilder::class));
$f3->expects($this->once())
->method('apply')
->with($this->isInstanceOf(QueryBuilder::class));
$filter = new class($f1, $f2, $f3, null) {
use CompoundFilterTrait;
protected $filter1;
private $filter2;
public $filter3;
protected $filter4;
public function __construct($f1, $f2, $f3, $f4) {
$this->filter1 = $f1;
$this->filter2 = $f2;
$this->filter3 = $f3;
$this->filter4 = $f4;
}
public function _applyAllChildFilters(QueryBuilder $queryBuilder): void
{
$this->applyAllChildFilters($queryBuilder);
}
};
$qb = $this->createMock(QueryBuilder::class);
$filter->_applyAllChildFilters($qb);
}
}

View file

@ -0,0 +1,40 @@
<?php
namespace App\Tests\DataTables\Filters\Constraints;
use App\DataTables\Filters\Constraints\FilterTrait;
use App\Entity\Parts\MeasurementUnit;
use PHPUnit\Framework\TestCase;
class FilterTraitTest extends TestCase
{
use FilterTrait;
public function testUseHaving(): void
{
$this->assertFalse($this->useHaving);
$this->useHaving();
$this->assertTrue($this->useHaving);
$this->useHaving(false);
$this->assertFalse($this->useHaving);
}
public function isAggregateFunctionStringDataProvider(): iterable
{
yield [false, 'parts.test'];
yield [false, 'attachments.test'];
yield [true, 'COUNT(attachments)'];
yield [true, 'MAX(attachments.value)'];
}
/**
* @dataProvider isAggregateFunctionStringDataProvider
*/
public function testIsAggregateFunctionString(bool $expected, string $input): void
{
$this->assertEquals($expected, $this->isAggregateFunctionString($input));
}
}