fix(task): task creation broke on save - task_kind could reach the database as null
A new Task's taskKind property defaulted to null (the 0.18.x task rework), while the task_kind column is NOT NULL: Doctrine writes every column explicitly, so the column's own default never applied and any save whose form field did not map failed with "1048 Column 'task_kind' cannot be null". - Task::$taskKind now defaults to TaskKind::Task, like $status: the property is never null anymore and the getter is straight - setTaskKind()/setStatus() accept null as "keep the current kind/status", so a missing form field can neither throw at mapping time nor wipe the value - TaskType defaults an absent or empty taskKind to a regular task on PRE_SUBMIT - regression tests: Tests/Unit/Entity/TaskTest.php
This commit is contained in:
1 parent
d6b3488cad
commit
603e564037
3 files changed
+110
-14
No files matched your search
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\MT3SMarketingProgramBundle\Tests\Unit\Entity;
|
||||
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Entity\Task;
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Entity\TaskKind;
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Entity\TaskStatus;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* The task kind must never be null: the task_kind column is NOT NULL and Doctrine writes
|
||||
* every column explicitly, so the database default never applies (0.18.1 regression).
|
||||
*/
|
||||
final class TaskTest extends TestCase
|
||||
{
|
||||
public function testNewTaskDefaultsToRegularKind(): void
|
||||
{
|
||||
$task = new Task();
|
||||
|
||||
self::assertSame(TaskKind::Task, $task->getTaskKind());
|
||||
}
|
||||
|
||||
public function testNullKindNeverWipesTheKind(): void
|
||||
{
|
||||
$task = new Task();
|
||||
$task->setTaskKind(TaskKind::Milestone);
|
||||
|
||||
$task->setTaskKind(null);
|
||||
|
||||
self::assertSame(TaskKind::Milestone, $task->getTaskKind());
|
||||
}
|
||||
|
||||
public function testSettingTheSameKindChangesNothing(): void
|
||||
{
|
||||
$task = new Task();
|
||||
|
||||
$task->setTaskKind(TaskKind::Task);
|
||||
|
||||
self::assertSame(TaskKind::Task, $task->getTaskKind());
|
||||
}
|
||||
|
||||
public function testNullStatusNeverWipesTheStatus(): void
|
||||
{
|
||||
$task = new Task();
|
||||
$task->setStatus(TaskStatus::Done);
|
||||
|
||||
$task->setStatus(null);
|
||||
|
||||
self::assertSame(TaskStatus::Done, $task->getStatus());
|
||||
}
|
||||
|
||||
public function testMilestoneKindEnslavesTheEndDate(): void
|
||||
{
|
||||
$task = new Task();
|
||||
$start = new \DateTime('2026-01-10');
|
||||
$task->setStartDate($start);
|
||||
$task->setEndDate(new \DateTime('2027-05-20'));
|
||||
|
||||
$task->setTaskKind(TaskKind::Milestone);
|
||||
|
||||
self::assertSame('2026-01-10', $task->getEndDate()->format('Y-m-d'));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user