Skip to content

Fix controller test baking when the table alias differs - #1110

Open
dereuromark wants to merge 3 commits into
2.xfrom
fix-test-controller-alias-2.x
Open

dereuromark wants to merge 3 commits into
2.xfrom
fix-test-controller-alias-2.x

Conversation

@dereuromark

Copy link
Copy Markdown
Member

bake test controller crashes when the controller's default table uses an alias that differs from the controller's table name, for example a table calling setAlias() in initialize():

TypeError: Bake\Command\TestCommand::_processModel(): Argument #1 ($subject) must be of type Cake\ORM\Table, null given

_processController() already has the table from loadModel(), but then looked it up again as a controller property named after the alias. That property only exists when alias and table name match, so the lookup returned null.

The table instance is now passed on directly.

Baking a controller test resolved the default table, then read it back
from the controller as a property named after the table's alias. That
only works while the alias equals the controller's table name. With a
custom alias the property lookup returned null and the command died
with a TypeError in _processModel().

Use the table instance that was already resolved.
loadModel() is typed as RepositoryInterface, while _processModel()
only accepts a Table. Return early for other repository types so the
call is type-safe.
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.

1 participant