update downstream tests for text user requirement

Text now requires a User on construction. seed a user in
each test setUp that creates a Text directly or through the
fake repository so the suite remains green.
This commit is contained in:
Yisroel Baum 2026-05-02 21:27:55 +03:00
parent 40fdf25da2
commit cbbbc80326
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
9 changed files with 71 additions and 22 deletions

View file

@ -8,10 +8,13 @@ use App\Node\Node;
use App\Node\UseCases\BulkCreateNodes; use App\Node\UseCases\BulkCreateNodes;
use App\Node\UseCases\BulkCreateNodesRequest; use App\Node\UseCases\BulkCreateNodesRequest;
use App\Text\CreateTextDto; use App\Text\CreateTextDto;
use App\User\UseCases\CreateUserDto;
use App\ValueObjects\EmailAddress;
use DomainException; use DomainException;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Tests\Fakes\FakeNodeRepository; use Tests\Fakes\FakeNodeRepository;
use Tests\Fakes\FakeTextRepository; use Tests\Fakes\FakeTextRepository;
use Tests\Fakes\FakeUserRepository;
class BulkCreateNodesTest extends TestCase class BulkCreateNodesTest extends TestCase
{ {
@ -22,8 +25,14 @@ class BulkCreateNodesTest extends TestCase
public function setUp(): void public function setUp(): void
{ {
$userRepo = new FakeUserRepository();
$user = $userRepo->create(new CreateUserDto(
email: new EmailAddress('a@b.com'),
passwordHash: '',
isAdmin: false,
));
$this->textRepo = new FakeTextRepository(); $this->textRepo = new FakeTextRepository();
$this->textRepo->create(new CreateTextDto(name: 'text')); $this->textRepo->create(new CreateTextDto(name: 'text', user: $user));
$this->nodeRepo = new FakeNodeRepository(); $this->nodeRepo = new FakeNodeRepository();
$text = $this->textRepo->find(0); $text = $this->textRepo->find(0);

View file

@ -9,10 +9,13 @@ use App\Node\UseCases\CreateNode;
use App\Node\UseCases\CreateNodeRequest; use App\Node\UseCases\CreateNodeRequest;
use App\Text\CreateTextDto; use App\Text\CreateTextDto;
use App\Text\Text; use App\Text\Text;
use App\User\UseCases\CreateUserDto;
use App\ValueObjects\EmailAddress;
use DomainException; use DomainException;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Tests\Fakes\FakeNodeRepository; use Tests\Fakes\FakeNodeRepository;
use Tests\Fakes\FakeTextRepository; use Tests\Fakes\FakeTextRepository;
use Tests\Fakes\FakeUserRepository;
class CreateNodeTest extends TestCase class CreateNodeTest extends TestCase
{ {
@ -22,9 +25,16 @@ class CreateNodeTest extends TestCase
public function setUp(): void public function setUp(): void
{ {
$userRepo = new FakeUserRepository();
$user = $userRepo->create(new CreateUserDto(
email: new EmailAddress('a@b.com'),
passwordHash: '',
isAdmin: false,
));
$this->textRepo = new FakeTextRepository(); $this->textRepo = new FakeTextRepository();
$this->textRepo->create(new CreateTextDto( $this->textRepo->create(new CreateTextDto(
name: 'text' name: 'text',
user: $user,
)); ));
$this->nodeRepo = new FakeNodeRepository(); $this->nodeRepo = new FakeNodeRepository();
$this->useCase = new CreateNode( $this->useCase = new CreateNode(

View file

@ -37,7 +37,7 @@ class CreatePlanTest extends TestCase
$this->textRepo = new FakeTextRepository(); $this->textRepo = new FakeTextRepository();
$this->nodeRepo = new FakeNodeRepository(); $this->nodeRepo = new FakeNodeRepository();
$this->scheduledNodeRepo = new FakeScheduledNodeRepository(); $this->scheduledNodeRepo = new FakeScheduledNodeRepository();
$this->userRepo->create(new CreateUserDto( $user = $this->userRepo->create(new CreateUserDto(
email: new EmailAddress('test@test.com'), email: new EmailAddress('test@test.com'),
passwordHash: '', passwordHash: '',
isAdmin: false, isAdmin: false,
@ -47,7 +47,10 @@ class CreatePlanTest extends TestCase
planRepo: $this->planRepo, planRepo: $this->planRepo,
nodeRepo: $this->nodeRepo, nodeRepo: $this->nodeRepo,
); );
$this->textRepo->create(new CreateTextDto('testname')); $this->textRepo->create(new CreateTextDto(
name: 'testname',
user: $user,
));
$this->useCase = new CreatePlan( $this->useCase = new CreatePlan(
$this->planRepo, $this->planRepo,
$this->userRepo, $this->userRepo,

View file

@ -35,19 +35,20 @@ class CreateScheduledNodeTest extends TestCase
$this->scheduledNodeRepo = new FakeScheduledNodeRepository(); $this->scheduledNodeRepo = new FakeScheduledNodeRepository();
$this->planRepo = new FakePlanRepository(); $this->planRepo = new FakePlanRepository();
$this->nodeRepo = new FakeNodeRepository(); $this->nodeRepo = new FakeNodeRepository();
$user = new User(
id: 0,
email: new EmailAddress('test@test.com'),
passwordHash: 'hashed:password1',
isAdmin: false,
);
$this->nodeRepo->create(new CreateNodeDto( $this->nodeRepo->create(new CreateNodeDto(
text: new Text(0, 'text name'), text: new Text(0, 'text name', $user),
title: 'test node', title: 'test node',
parentNode: null, parentNode: null,
)); ));
$this->planRepo->create(new CreatePlanDto( $this->planRepo->create(new CreatePlanDto(
name: 'testplan', name: 'testplan',
user: new User( user: $user,
id: 0,
email: new EmailAddress('test@test.com'),
passwordHash: 'hashed:password1',
isAdmin: false,
),
)); ));
$this->useCase = new CreateScheduledNode( $this->useCase = new CreateScheduledNode(
$this->scheduledNodeRepo, $this->scheduledNodeRepo,

View file

@ -29,19 +29,21 @@ class GetTodaysScheduleTest extends TestCase
private GetTodaysSchedule $useCase; private GetTodaysSchedule $useCase;
private \App\User\User $user;
protected function setUp(): void protected function setUp(): void
{ {
$this->userRepo = new FakeUserRepository(); $this->userRepo = new FakeUserRepository();
$this->scheduledNodeRepo = new FakeScheduledNodeRepository(); $this->scheduledNodeRepo = new FakeScheduledNodeRepository();
$this->planRepo = new FakePlanRepository(); $this->planRepo = new FakePlanRepository();
$user = $this->userRepo->create(new CreateUserDto( $this->user = $this->userRepo->create(new CreateUserDto(
email: new EmailAddress('email@email.com'), email: new EmailAddress('email@email.com'),
passwordHash: 'hash', passwordHash: 'hash',
isAdmin: false, isAdmin: false,
)); ));
$plan = $this->planRepo->create(new CreatePlanDto( $plan = $this->planRepo->create(new CreatePlanDto(
name: 'test plan', name: 'test plan',
user: $user, user: $this->user,
)); ));
$this->scheduledNodeRepo->create(new CreateScheduledNodeDto( $this->scheduledNodeRepo->create(new CreateScheduledNodeDto(
date: new DateTimeImmutable('2025-01-02'), date: new DateTimeImmutable('2025-01-02'),
@ -49,7 +51,7 @@ class GetTodaysScheduleTest extends TestCase
node: new Node( node: new Node(
id: 0, id: 0,
title: 'test node', title: 'test node',
text: new Text(id: 0, name: 'test text'), text: new Text(id: 0, name: 'test text', user: $this->user),
parentNode: null, parentNode: null,
), ),
)); ));
@ -79,7 +81,7 @@ class GetTodaysScheduleTest extends TestCase
node: new Node( node: new Node(
id: 0, id: 0,
title: 'test node', title: 'test node',
text: new Text(id: 0, name: 'test text'), text: new Text(id: 0, name: 'test text', user: $this->user),
parentNode: null, parentNode: null,
), ),
)); ));
@ -99,7 +101,7 @@ class GetTodaysScheduleTest extends TestCase
node: new Node( node: new Node(
id: 0, id: 0,
title: 'test node', title: 'test node',
text: new Text(id: 0, name: 'test text'), text: new Text(id: 0, name: 'test text', user: $this->user),
parentNode: null, parentNode: null,
), ),
) )
@ -172,7 +174,7 @@ class GetTodaysScheduleTest extends TestCase
node: new Node( node: new Node(
id: 0, id: 0,
title: 'future node', title: 'future node',
text: new Text(id: 0, name: 'test text'), text: new Text(id: 0, name: 'test text', user: $this->user),
parentNode: null, parentNode: null,
), ),
)); ));
@ -202,7 +204,7 @@ class GetTodaysScheduleTest extends TestCase
node: new Node( node: new Node(
id: 0, id: 0,
title: 'other node', title: 'other node',
text: new Text(id: 0, name: 'test text'), text: new Text(id: 0, name: 'test text', user: $otherUser),
parentNode: null, parentNode: null,
), ),
)); ));

View file

@ -6,6 +6,8 @@ use App\Node\CreateNodeDto;
use App\Node\NodeController; use App\Node\NodeController;
use App\Node\UseCases\BulkCreateNodes; use App\Node\UseCases\BulkCreateNodes;
use App\Text\CreateTextDto; use App\Text\CreateTextDto;
use App\User\UseCases\CreateUserDto;
use App\ValueObjects\EmailAddress;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Slim\Psr7\Factory\ServerRequestFactory; use Slim\Psr7\Factory\ServerRequestFactory;
@ -13,6 +15,7 @@ use Slim\Psr7\Factory\StreamFactory;
use Slim\Psr7\Response; use Slim\Psr7\Response;
use Tests\Fakes\FakeNodeRepository; use Tests\Fakes\FakeNodeRepository;
use Tests\Fakes\FakeTextRepository; use Tests\Fakes\FakeTextRepository;
use Tests\Fakes\FakeUserRepository;
class BulkCreateNodesControllerTest extends TestCase class BulkCreateNodesControllerTest extends TestCase
{ {
@ -23,8 +26,17 @@ class BulkCreateNodesControllerTest extends TestCase
public function setUp(): void public function setUp(): void
{ {
$userRepo = new FakeUserRepository();
$user = $userRepo->create(new CreateUserDto(
email: new EmailAddress('a@b.com'),
passwordHash: '',
isAdmin: false,
));
$this->textRepo = new FakeTextRepository(); $this->textRepo = new FakeTextRepository();
$text = $this->textRepo->create(new CreateTextDto(name: 'test text')); $text = $this->textRepo->create(new CreateTextDto(
name: 'test text',
user: $user,
));
$this->nodeRepo = new FakeNodeRepository(); $this->nodeRepo = new FakeNodeRepository();
$this->nodeRepo->create(new CreateNodeDto( $this->nodeRepo->create(new CreateNodeDto(

View file

@ -6,12 +6,15 @@ use App\Node\CreateNodeDto;
use App\Node\NodeController; use App\Node\NodeController;
use App\Node\UseCases\CreateNode; use App\Node\UseCases\CreateNode;
use App\Text\CreateTextDto; use App\Text\CreateTextDto;
use App\User\UseCases\CreateUserDto;
use App\ValueObjects\EmailAddress;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Slim\Psr7\Factory\ServerRequestFactory; use Slim\Psr7\Factory\ServerRequestFactory;
use Slim\Psr7\Factory\StreamFactory; use Slim\Psr7\Factory\StreamFactory;
use Slim\Psr7\Response; use Slim\Psr7\Response;
use Tests\Fakes\FakeNodeRepository; use Tests\Fakes\FakeNodeRepository;
use Tests\Fakes\FakeTextRepository; use Tests\Fakes\FakeTextRepository;
use Tests\Fakes\FakeUserRepository;
class NodeControllerTest extends TestCase class NodeControllerTest extends TestCase
{ {
@ -21,8 +24,14 @@ class NodeControllerTest extends TestCase
public function setUp(): void public function setUp(): void
{ {
$userRepo = new FakeUserRepository();
$user = $userRepo->create(new CreateUserDto(
email: new EmailAddress('a@b.com'),
passwordHash: '',
isAdmin: false,
));
$this->textRepo = new FakeTextRepository(); $this->textRepo = new FakeTextRepository();
$this->textRepo->create(new CreateTextDto(name: 'test text')); $this->textRepo->create(new CreateTextDto(name: 'test text', user: $user));
$this->nodeRepo = new FakeNodeRepository(); $this->nodeRepo = new FakeNodeRepository();

View file

@ -45,7 +45,10 @@ class PlanControllerTest extends TestCase
passwordHash: '', passwordHash: '',
isAdmin: false, isAdmin: false,
)); ));
$text = $this->textRepo->create(new CreateTextDto('testname')); $text = $this->textRepo->create(new CreateTextDto(
name: 'testname',
user: $this->user,
));
$this->nodeRepo->create(new CreateNodeDto( $this->nodeRepo->create(new CreateNodeDto(
text: $text, text: $text,
title: 'Root Node', title: 'Root Node',

View file

@ -82,7 +82,7 @@ class ScheduledNodeControllerTest extends TestCase
node: new Node( node: new Node(
id: 0, id: 0,
title: $nodeTitle, title: $nodeTitle,
text: new Text(id: 0, name: 'test text'), text: new Text(id: 0, name: 'test text', user: $user),
parentNode: null, parentNode: null,
), ),
)); ));