Closed roelsadza closed 7 years ago
Mock the associated table for this behavior?
What do you mean by associated table?
Currently I have the users table, which has the Upload behavior for the avatar field.
When I use getMockForModel('Users')
I get this error.
You will struggle to mock these, as you'll mock the table, then the schema, then you'll need a mock connection as well, and so on.
Better to just use an actual instance, to save on code imho.
Hello,
I've encountered an error while adding a test case in which I mock a model that has the UploadBehavior in CakePHP 3.3.
When using getMockForModel, the testcase initializes the model. Then line 40 of UploadBehavior.php (UploadBehavior::initialize) tries to access the _table property.
$schema = $this->_table->schema();
It tries to access the table schema, which is not available for the mocked model.
The error is:
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test.mock__users_table_b4e' doesn't exist
The stack trace:
For now I have worked around this by also mocking the
addBehavior
method, so that the uploadbehavior is not loaded in this test. However, this means that also other behaviors are not loaded such as timestamp behavior, etc.