From cbbbc80326e17ab816f5bbf7bd210cc9e28049df Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Sat, 2 May 2026 21:27:55 +0300 Subject: [PATCH] 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. --- tests/Unit/Node/UseCases/BulkCreateNodesTest.php | 11 ++++++++++- tests/Unit/Node/UseCases/CreateNodeTest.php | 12 +++++++++++- tests/Unit/Plan/UseCases/CreatePlanTest.php | 7 +++++-- .../UseCases/CreateScheduledNodeTest.php | 15 ++++++++------- .../UseCases/GetTodaysScheduleTest.php | 16 +++++++++------- .../BulkCreateNodesControllerTest.php | 14 +++++++++++++- tests/e2e/Controllers/NodeControllerTest.php | 11 ++++++++++- tests/e2e/Controllers/PlanControllerTest.php | 5 ++++- .../Controllers/ScheduledNodeControllerTest.php | 2 +- 9 files changed, 71 insertions(+), 22 deletions(-) diff --git a/tests/Unit/Node/UseCases/BulkCreateNodesTest.php b/tests/Unit/Node/UseCases/BulkCreateNodesTest.php index 3fd3452..5faaa2b 100644 --- a/tests/Unit/Node/UseCases/BulkCreateNodesTest.php +++ b/tests/Unit/Node/UseCases/BulkCreateNodesTest.php @@ -8,10 +8,13 @@ use App\Node\Node; use App\Node\UseCases\BulkCreateNodes; use App\Node\UseCases\BulkCreateNodesRequest; use App\Text\CreateTextDto; +use App\User\UseCases\CreateUserDto; +use App\ValueObjects\EmailAddress; use DomainException; use PHPUnit\Framework\TestCase; use Tests\Fakes\FakeNodeRepository; use Tests\Fakes\FakeTextRepository; +use Tests\Fakes\FakeUserRepository; class BulkCreateNodesTest extends TestCase { @@ -22,8 +25,14 @@ class BulkCreateNodesTest extends TestCase 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->create(new CreateTextDto(name: 'text')); + $this->textRepo->create(new CreateTextDto(name: 'text', user: $user)); $this->nodeRepo = new FakeNodeRepository(); $text = $this->textRepo->find(0); diff --git a/tests/Unit/Node/UseCases/CreateNodeTest.php b/tests/Unit/Node/UseCases/CreateNodeTest.php index 5b9226e..7e47ea5 100644 --- a/tests/Unit/Node/UseCases/CreateNodeTest.php +++ b/tests/Unit/Node/UseCases/CreateNodeTest.php @@ -9,10 +9,13 @@ use App\Node\UseCases\CreateNode; use App\Node\UseCases\CreateNodeRequest; use App\Text\CreateTextDto; use App\Text\Text; +use App\User\UseCases\CreateUserDto; +use App\ValueObjects\EmailAddress; use DomainException; use PHPUnit\Framework\TestCase; use Tests\Fakes\FakeNodeRepository; use Tests\Fakes\FakeTextRepository; +use Tests\Fakes\FakeUserRepository; class CreateNodeTest extends TestCase { @@ -22,9 +25,16 @@ class CreateNodeTest extends TestCase 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->create(new CreateTextDto( - name: 'text' + name: 'text', + user: $user, )); $this->nodeRepo = new FakeNodeRepository(); $this->useCase = new CreateNode( diff --git a/tests/Unit/Plan/UseCases/CreatePlanTest.php b/tests/Unit/Plan/UseCases/CreatePlanTest.php index fbdfc60..a08da10 100644 --- a/tests/Unit/Plan/UseCases/CreatePlanTest.php +++ b/tests/Unit/Plan/UseCases/CreatePlanTest.php @@ -37,7 +37,7 @@ class CreatePlanTest extends TestCase $this->textRepo = new FakeTextRepository(); $this->nodeRepo = new FakeNodeRepository(); $this->scheduledNodeRepo = new FakeScheduledNodeRepository(); - $this->userRepo->create(new CreateUserDto( + $user = $this->userRepo->create(new CreateUserDto( email: new EmailAddress('test@test.com'), passwordHash: '', isAdmin: false, @@ -47,7 +47,10 @@ class CreatePlanTest extends TestCase planRepo: $this->planRepo, nodeRepo: $this->nodeRepo, ); - $this->textRepo->create(new CreateTextDto('testname')); + $this->textRepo->create(new CreateTextDto( + name: 'testname', + user: $user, + )); $this->useCase = new CreatePlan( $this->planRepo, $this->userRepo, diff --git a/tests/Unit/ScheduledNode/UseCases/CreateScheduledNodeTest.php b/tests/Unit/ScheduledNode/UseCases/CreateScheduledNodeTest.php index 8c866fe..200b71a 100644 --- a/tests/Unit/ScheduledNode/UseCases/CreateScheduledNodeTest.php +++ b/tests/Unit/ScheduledNode/UseCases/CreateScheduledNodeTest.php @@ -35,19 +35,20 @@ class CreateScheduledNodeTest extends TestCase $this->scheduledNodeRepo = new FakeScheduledNodeRepository(); $this->planRepo = new FakePlanRepository(); $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( - text: new Text(0, 'text name'), + text: new Text(0, 'text name', $user), title: 'test node', parentNode: null, )); $this->planRepo->create(new CreatePlanDto( name: 'testplan', - user: new User( - id: 0, - email: new EmailAddress('test@test.com'), - passwordHash: 'hashed:password1', - isAdmin: false, - ), + user: $user, )); $this->useCase = new CreateScheduledNode( $this->scheduledNodeRepo, diff --git a/tests/Unit/ScheduledNode/UseCases/GetTodaysScheduleTest.php b/tests/Unit/ScheduledNode/UseCases/GetTodaysScheduleTest.php index 359b632..5a2afc6 100644 --- a/tests/Unit/ScheduledNode/UseCases/GetTodaysScheduleTest.php +++ b/tests/Unit/ScheduledNode/UseCases/GetTodaysScheduleTest.php @@ -29,19 +29,21 @@ class GetTodaysScheduleTest extends TestCase private GetTodaysSchedule $useCase; + private \App\User\User $user; + protected function setUp(): void { $this->userRepo = new FakeUserRepository(); $this->scheduledNodeRepo = new FakeScheduledNodeRepository(); $this->planRepo = new FakePlanRepository(); - $user = $this->userRepo->create(new CreateUserDto( + $this->user = $this->userRepo->create(new CreateUserDto( email: new EmailAddress('email@email.com'), passwordHash: 'hash', isAdmin: false, )); $plan = $this->planRepo->create(new CreatePlanDto( name: 'test plan', - user: $user, + user: $this->user, )); $this->scheduledNodeRepo->create(new CreateScheduledNodeDto( date: new DateTimeImmutable('2025-01-02'), @@ -49,7 +51,7 @@ class GetTodaysScheduleTest extends TestCase node: new Node( id: 0, title: 'test node', - text: new Text(id: 0, name: 'test text'), + text: new Text(id: 0, name: 'test text', user: $this->user), parentNode: null, ), )); @@ -79,7 +81,7 @@ class GetTodaysScheduleTest extends TestCase node: new Node( id: 0, title: 'test node', - text: new Text(id: 0, name: 'test text'), + text: new Text(id: 0, name: 'test text', user: $this->user), parentNode: null, ), )); @@ -99,7 +101,7 @@ class GetTodaysScheduleTest extends TestCase node: new Node( id: 0, title: 'test node', - text: new Text(id: 0, name: 'test text'), + text: new Text(id: 0, name: 'test text', user: $this->user), parentNode: null, ), ) @@ -172,7 +174,7 @@ class GetTodaysScheduleTest extends TestCase node: new Node( id: 0, title: 'future node', - text: new Text(id: 0, name: 'test text'), + text: new Text(id: 0, name: 'test text', user: $this->user), parentNode: null, ), )); @@ -202,7 +204,7 @@ class GetTodaysScheduleTest extends TestCase node: new Node( id: 0, title: 'other node', - text: new Text(id: 0, name: 'test text'), + text: new Text(id: 0, name: 'test text', user: $otherUser), parentNode: null, ), )); diff --git a/tests/e2e/Controllers/BulkCreateNodesControllerTest.php b/tests/e2e/Controllers/BulkCreateNodesControllerTest.php index 8dfcb25..660217e 100644 --- a/tests/e2e/Controllers/BulkCreateNodesControllerTest.php +++ b/tests/e2e/Controllers/BulkCreateNodesControllerTest.php @@ -6,6 +6,8 @@ use App\Node\CreateNodeDto; use App\Node\NodeController; use App\Node\UseCases\BulkCreateNodes; use App\Text\CreateTextDto; +use App\User\UseCases\CreateUserDto; +use App\ValueObjects\EmailAddress; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ServerRequestInterface; use Slim\Psr7\Factory\ServerRequestFactory; @@ -13,6 +15,7 @@ use Slim\Psr7\Factory\StreamFactory; use Slim\Psr7\Response; use Tests\Fakes\FakeNodeRepository; use Tests\Fakes\FakeTextRepository; +use Tests\Fakes\FakeUserRepository; class BulkCreateNodesControllerTest extends TestCase { @@ -23,8 +26,17 @@ class BulkCreateNodesControllerTest extends TestCase 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(); - $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->create(new CreateNodeDto( diff --git a/tests/e2e/Controllers/NodeControllerTest.php b/tests/e2e/Controllers/NodeControllerTest.php index fffb89f..c99b609 100644 --- a/tests/e2e/Controllers/NodeControllerTest.php +++ b/tests/e2e/Controllers/NodeControllerTest.php @@ -6,12 +6,15 @@ use App\Node\CreateNodeDto; use App\Node\NodeController; use App\Node\UseCases\CreateNode; use App\Text\CreateTextDto; +use App\User\UseCases\CreateUserDto; +use App\ValueObjects\EmailAddress; use PHPUnit\Framework\TestCase; use Slim\Psr7\Factory\ServerRequestFactory; use Slim\Psr7\Factory\StreamFactory; use Slim\Psr7\Response; use Tests\Fakes\FakeNodeRepository; use Tests\Fakes\FakeTextRepository; +use Tests\Fakes\FakeUserRepository; class NodeControllerTest extends TestCase { @@ -21,8 +24,14 @@ class NodeControllerTest extends TestCase 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->create(new CreateTextDto(name: 'test text')); + $this->textRepo->create(new CreateTextDto(name: 'test text', user: $user)); $this->nodeRepo = new FakeNodeRepository(); diff --git a/tests/e2e/Controllers/PlanControllerTest.php b/tests/e2e/Controllers/PlanControllerTest.php index 818651c..08e42d8 100644 --- a/tests/e2e/Controllers/PlanControllerTest.php +++ b/tests/e2e/Controllers/PlanControllerTest.php @@ -45,7 +45,10 @@ class PlanControllerTest extends TestCase passwordHash: '', 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( text: $text, title: 'Root Node', diff --git a/tests/e2e/Controllers/ScheduledNodeControllerTest.php b/tests/e2e/Controllers/ScheduledNodeControllerTest.php index 0a7c57e..69b3975 100644 --- a/tests/e2e/Controllers/ScheduledNodeControllerTest.php +++ b/tests/e2e/Controllers/ScheduledNodeControllerTest.php @@ -82,7 +82,7 @@ class ScheduledNodeControllerTest extends TestCase node: new Node( id: 0, title: $nodeTitle, - text: new Text(id: 0, name: 'test text'), + text: new Text(id: 0, name: 'test text', user: $user), parentNode: null, ), ));