allow empty invoice template terms #188 (#189)

This commit is contained in:
Kevin Papst
2018-06-29 19:49:01 +02:00
committed by GitHub
parent b05d416e80
commit 0eb8ae5117
4 changed files with 111 additions and 43 deletions

View File

@@ -7,21 +7,18 @@
* file that was distributed with this source code.
*/
namespace App\Tests\Twig;
namespace App\Tests\Entity;
use App\Entity\Activity;
use App\Entity\Customer;
use App\Entity\Project;
use App\Entity\Timesheet;
use App\Entity\User;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\ConstraintViolationInterface;
use Symfony\Component\Validator\Validation;
/**
* @covers \App\Entity\Timesheet
*/
class TimesheetTest extends TestCase
class TimesheetTest extends AbstractEntityTest
{
protected function getEntity()
{
@@ -85,41 +82,4 @@ class TimesheetTest extends TestCase
$this->assertHasViolationForField($entity, []);
}
/**
* @param $value
* @param array|string $fieldNames
*/
protected function assertHasViolationForField($value, $fieldNames)
{
$validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
$validations = $validator->validate($value);
if (!is_array($fieldNames)) {
$fieldNames = [$fieldNames];
}
$violatedFields = [];
/** @var ConstraintViolationInterface $validation */
foreach ($validations as $validation) {
$violatedFields[] = $validation->getPropertyPath();
}
foreach ($fieldNames as $id => $propertyPath) {
$foundField = false;
if (in_array($propertyPath, $violatedFields)) {
$foundField = true;
unset($violatedFields[$id]);
}
$this->assertTrue($foundField, 'Failed finding violation for field: ' . $propertyPath);
}
$this->assertEmpty($violatedFields, sprintf('Unexpected violations found: %s', implode(', ', $violatedFields)));
$expected = count($fieldNames);
$actual = $validations->count();
$this->assertEquals($expected, $actual, sprintf('Expected %s violations, found %s.', $expected, $actual));
}
}