repository = $this->createMock(ScontainersRepository::class); $this->languagesRepository = $this->createMock(LanguagesRepository::class); $this->controller = new ScontainersController($this->repository, $this->languagesRepository); } public function testConstructorAcceptsDependencies(): void { $controller = new ScontainersController($this->repository, $this->languagesRepository); $this->assertInstanceOf(ScontainersController::class, $controller); } public function testHasMainActionMethods(): void { $this->assertTrue(method_exists($this->controller, 'list')); $this->assertTrue(method_exists($this->controller, 'view_list')); $this->assertTrue(method_exists($this->controller, 'edit')); $this->assertTrue(method_exists($this->controller, 'save')); $this->assertTrue(method_exists($this->controller, 'delete')); } public function testActionMethodReturnTypes(): void { $reflection = new \ReflectionClass($this->controller); $this->assertEquals('string', (string)$reflection->getMethod('list')->getReturnType()); $this->assertEquals('string', (string)$reflection->getMethod('view_list')->getReturnType()); $this->assertEquals('string', (string)$reflection->getMethod('edit')->getReturnType()); $this->assertEquals('void', (string)$reflection->getMethod('save')->getReturnType()); $this->assertEquals('void', (string)$reflection->getMethod('delete')->getReturnType()); } public function testConstructorRequiresRepositoryAndLanguagesRepository(): void { $reflection = new \ReflectionClass(ScontainersController::class); $constructor = $reflection->getConstructor(); $params = $constructor->getParameters(); $this->assertCount(2, $params); $this->assertEquals('Domain\Scontainers\ScontainersRepository', $params[0]->getType()->getName()); $this->assertEquals('Domain\Languages\LanguagesRepository', $params[1]->getType()->getName()); } public function testBuildFormViewModelStoresIdInHiddenFieldsForEdit(): void { $reflection = new \ReflectionClass(ScontainersController::class); $method = $reflection->getMethod('buildFormViewModel'); $method->setAccessible(true); $container = [ 'id' => 9, 'status' => 1, 'show_title' => 1, 'languages' => [], ]; $form = $method->invoke($this->controller, $container, [], null); $this->assertArrayHasKey('id', $form->hiddenFields); $this->assertSame(9, (int)$form->hiddenFields['id']); $this->assertSame('/admin/scontainers/save/id=9', $form->action); } public function testBuildFormViewModelKeepsCreateFlowWithZeroId(): void { $reflection = new \ReflectionClass(ScontainersController::class); $method = $reflection->getMethod('buildFormViewModel'); $method->setAccessible(true); $form = $method->invoke($this->controller, [], [], null); $this->assertArrayHasKey('id', $form->hiddenFields); $this->assertSame(0, (int)$form->hiddenFields['id']); $this->assertSame('/admin/scontainers/save/', $form->action); } }