Skip to content

Commit

Permalink
Fix laminas#3
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Richer [email protected] <[email protected]>
  • Loading branch information
visto9259 committed Sep 12, 2024
1 parent a8de7f8 commit 7e02347
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/PHPUnit/Controller/AbstractControllerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -817,11 +817,15 @@ public function assertNotTemplateName($templateName)
*/
protected function searchTemplates($viewModel, $templateName)
{
$found = false;

Check failure on line 820 in src/PHPUnit/Controller/AbstractControllerTestCase.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

UnusedVariable

src/PHPUnit/Controller/AbstractControllerTestCase.php:820:9: UnusedVariable: $found is never referenced or the value is not used (see https://psalm.dev/077)
if ($viewModel->getTemplate($templateName) === $templateName) {
return true;
}
foreach ($viewModel->getChildren() as $child) {
return $this->searchTemplates($child, $templateName);
$found = $this->searchTemplates($child, $templateName);
if ($found) {
return $found;
}
}

return false;
Expand Down
40 changes: 40 additions & 0 deletions test/PHPUnit/Controller/TemplateNameTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace LaminasTest\Test\PHPUnit\Controller;

use LaminasTest\Test\PHPUnit\Controller\AbstractHttpControllerTestCaseTest;

class TemplateNameTest extends AbstractHttpControllerTestCaseTest
{
public function setUp(): void
{
$this->setApplicationConfig(
include __DIR__ . '/../../_files/application.config.php'
);
parent::setUp();
}

/**
* Test case for a controller returning a view with 2 children
* View hierarchy:
* layout/layout -> baz/index/childview -> child1
* -> child2
*/
public function testAssertTemplateWithMultipleChildren(): void
{
$this->dispatch('/childview');

// Check that the rendered content
$this->assertQueryContentContains('p', 'Parent');
$this->assertQueryContentContains('p', 'Child 1');
$this->assertQueryContentContains('p', 'Child 2');

$this->assertTemplateName('layout/layout');
$this->assertTemplateName('baz/index/childview');
$this->assertTemplateName('child1');
$this->assertTemplateName('child2');
$this->assertNotTemplateName('foo');
}
}
16 changes: 14 additions & 2 deletions test/_files/Baz/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@
],
],
],
'childview' => [
'type' => 'literal',
'options' => [
'route' => '/childview',
'defaults' => [
'controller' => 'baz_index',
'action' => 'childview',
],
],
],
],
],
'controllers' => [
Expand All @@ -117,8 +127,10 @@
],
'view_manager' => [
'template_map' => [
'404' => __DIR__ . '/../view/baz/error/404.phtml',
'error' => __DIR__ . '/../view/baz/error/error.phtml',
'404' => __DIR__ . '/../view/baz/error/404.phtml',
'error' => __DIR__ . '/../view/baz/error/error.phtml',
'child1' => __DIR__ . '/../view/baz/index/child1.phtml',
'child2' => __DIR__ . '/../view/baz/index/child2.phtml',
],
'template_path_stack' => [
__DIR__ . '/../view',
Expand Down
13 changes: 13 additions & 0 deletions test/_files/Baz/src/Baz/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Laminas\Http\Response;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\ViewModel;
use RuntimeException;

class IndexController extends AbstractActionController
Expand Down Expand Up @@ -61,4 +62,16 @@ public function customResponseAction()
public function registerxpathnamespaceAction()
{
}

public function childViewAction(): ViewModel
{
$child1 = new ViewModel();
$child1->setTemplate('child1');
$child2 = new ViewModel();
$child2->setTemplate('child2');
$view = new ViewModel();
$view->addChild($child1, 'child1');
$view->addChild($child2, 'child2');
return $view;
}
}
1 change: 1 addition & 0 deletions test/_files/Baz/view/baz/index/child1.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Child 1</p>
1 change: 1 addition & 0 deletions test/_files/Baz/view/baz/index/child2.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Child 2</p>
3 changes: 3 additions & 0 deletions test/_files/Baz/view/baz/index/childview.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>Parent</p>
<?php echo $this->child1; ?>
<?php echo $this->child2; ?>

0 comments on commit 7e02347

Please sign in to comment.