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

Soft Delete interferes with PHPUnit Testing #135

Closed
NickBusey opened this issue Feb 5, 2015 · 12 comments
Closed

Soft Delete interferes with PHPUnit Testing #135

NickBusey opened this issue Feb 5, 2015 · 12 comments

Comments

@NickBusey
Copy link

Running my tests, I get the following error:

Missing Database Table
Error: Table device for model Device was not found in datasource test.

Notice: If you want to customize this error message, create app/View/Errors/missing_table.ctp

Stack Trace
CORE/Cake/Model/Model.php line 3640 → Model->setSource(string)
CORE/Cake/Model/Model.php line 1387 → Model->getDataSource()
CORE/Cake/Model/Model.php line 1479 → Model->schema()
APP/Model/Behavior/SoftDeleteBehavior.php line 63 → Model->hasField(string)
CORE/Cake/Model/BehaviorCollection.php line 145 → SoftDeleteBehavior->setup(Device, array)

If I comment out the actsAs => SoftDelete line, it works fine.

Any ideas? Thanks much for all your work.

@dereuromark
Copy link
Owner

Thats normal if u add the behavior
You didnt include the related fixtures then.

@NickBusey
Copy link
Author

Not sure what you mean? I do have fixtures included, and they work without the behavior.

@dereuromark
Copy link
Owner

Did you also add the device fixture as the error warns about?

@NickBusey
Copy link
Author

Yes, as I said if I uncomment the SoftDelete behavior, it works as expected.

@dereuromark
Copy link
Owner

I rather see a mistake in your model or fixture setup. Shoudnt device be plural devices?
Can you maybe bin your test code?

@NickBusey
Copy link
Author

Here's a simplified copy of the model and fixture code.

https://gist.github.com/NickBusey/4b309eb0c066fa8cd805

With actsAs SoftDelete it fails with a Missing Database Table error.

Comment out actsAs SoftDelete and it works.

@dereuromark
Copy link
Owner

I still suspect the inflection to be the root cause of the issue here. Did you try using the conventions "devices" name approach here for the table name?

@NickBusey
Copy link
Author

I changed 'device' to 'devices'. The web end works fine. Running the test, get the same error pointing now at 'devices'.

Missing Database Table
Error: Table devices for model Device was not found in datasource test.

@NickBusey
Copy link
Author

I'm going to assume this is an unknown issue with an unknown timeframe for a fix. I'm going to try and start debugging it. Any ideas or suggestions on where to look first would be appreciated.

@NickBusey
Copy link
Author

Commenting out Line 239 of SoftDeleteBehavior.php seems to fix the issue with the tests. The behavior functionality seems to work without this line: $this->_softDeleteAssociations($model, $active);

@dereuromark
Copy link
Owner

SoftDelete is deprecated and only 2.x needs fixing if someone is filling to provide a PR.

@dereuromark
Copy link
Owner

Closing until PR is open.

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

No branches or pull requests

2 participants