Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes wrong assertions in the controller test class #77

Merged
merged 3 commits into from
Nov 27, 2023

Conversation

Tyrsson
Copy link
Contributor

@Tyrsson Tyrsson commented Jun 18, 2023

Q A
Documentation no
Bugfix yes
BC Break no
New Feature no
RFC no
QA yes

Description

class from layout.phtml
.container

class from index.phtml
.card

For this test to work as intended it must be passed a class from BOTH files.

Please note the entire test methods name is relevant.
"Index Action View Model Template Rendered Within Layout"

fix:
current

    public function testIndexActionViewModelTemplateRenderedWithinLayout(): void
    {
        $this->dispatch('/', 'GET');
        $this->assertQuery('.container .jumbotron');
    }

changed to:

    public function testIndexActionViewModelTemplateRenderedWithinLayout(): void
    {
        $this->dispatch('/', 'GET');
        $this->assertQuery('body h1');
    }

Signed-off-by: Joey Smith <jsmith@webinertia.net>

Signed-off-by: Joey Smith <jsmith@webinertia.net>
@@ -39,7 +39,7 @@ public function testIndexActionCanBeAccessed(): void
public function testIndexActionViewModelTemplateRenderedWithinLayout(): void
{
$this->dispatch('/', 'GET');
$this->assertQuery('.container .jumbotron');
$this->assertQuery('.col .card');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the test is named "rendered within layout" then this should be tested and this can be done independent from the frontend framework. So my suggestion is to check the title element which is a part of the layout:

<?= $this->headTitle('Laminas MVC Skeleton')->setSeparator(' - ')->setAutoEscape(false) ?>

Copy link
Contributor Author

@Tyrsson Tyrsson Jun 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually,

What the test is doing (and I corrected in my last commit).

It is checking that .container (which is a class from the layout) and .card which is a class rendered in the /index/index.phtml file are both rendered.

Your suggested change will only test that the layout is rendered. This test is intended to test that both the layout.phtml file is rendered and that the actions view file is rendered within it. Which is why the assertQuery() needs to be passed a class from each file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the original comment as well to clarify :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is intended to test that both the layout.phtml file is rendered and that the actions view file is rendered within it.

And this can be done independently of the frontend framework:

  • html h1
  • html h2
  • body h1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely. Its now:

body h1

Signed-off-by: Joey Smith <jsmith@webinertia.net>

Signed-off-by: Joey Smith <jsmith@webinertia.net>
@@ -39,7 +39,7 @@ public function testIndexActionCanBeAccessed(): void
public function testIndexActionViewModelTemplateRenderedWithinLayout(): void
{
$this->dispatch('/', 'GET');
$this->assertQuery('.container .card');
$this->assertQuery('body h1');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just commenting here so that you know it has been resolved.

@froschdesign froschdesign changed the title fixes failing test Fixes wrong assertions in the controller test class Jul 20, 2023
@froschdesign froschdesign added the Bug Something isn't working label Jul 20, 2023
@froschdesign froschdesign changed the base branch from 2.3.x to 2.2.x July 20, 2023 14:56
@froschdesign froschdesign added this to the 2.2.1 milestone Jul 20, 2023
@Xerkus Xerkus changed the base branch from 2.2.x to 2.3.x November 27, 2023 23:29
@Xerkus Xerkus modified the milestones: 2.2.1, 2.3.0 Nov 27, 2023
@Xerkus Xerkus merged commit 5dd0786 into laminas:2.3.x Nov 27, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants