Skip to content

Add unit tests for Collection home action. - #5661

Open
3pleX-dev wants to merge 2 commits into
vufind-org:devfrom
3pleX-dev:test/add-collection-home-action-unit-tests
Open

Add unit tests for Collection home action.#5661
3pleX-dev wants to merge 2 commits into
vufind-org:devfrom
3pleX-dev:test/add-collection-home-action-unit-tests

Conversation

@3pleX-dev

Copy link
Copy Markdown
Contributor

No description provided.

@demiankatz demiankatz added this to the 12.0 milestone Sep 10, 2026

@demiankatz demiankatz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, @3pleX-dev! See below for a few suggestions.

* @return HomeAction
*/
protected function buildAction(
array $config,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it worth defaulting this to empty array so you don't have to provide it, e.g. in line 138 below?

Suggested change
array $config,
array $config = [],

->withAttribute('route-match', $routeMatch);
$this->setProperty($action, 'request', $request);

return $this->callMethod($action, 'action', [$request, new Response()]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Might this be a case where you could actually use the __invoke method and not have to use reflection to trigger the logic?

I don't mind using reflection if it saves significant complexity in the tests, but it's good to use the public interface where possible to reduce the changes of internal refactoring breaking tests.

I think if invoke works here, then you can also skip the setProperty call for 'request' above.


$driver = $this->createMock(RecordDriver::class);
$driver->method('tryMethod')->with('isCollection')->willReturn(true);
$this->setProperty($action, 'driver', $driver);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it worth considering injecting a mock record loader to return the driver, rather than forcibly inserting it like this? As noted above, if this really greatly simplifies matters, I can live with it, but using the record loader might exercise a little bit more code.

*
* @return void
*/
public function testActionRedirectsToCollectionRouteForCollectionRecord(): void

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This and the following test might be good candidates for simplification into a single test with a data provider that sends in the active sid (or null) and the expected query parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants