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

Bug: Model doesn't reset errors in FeatureTestCase #3578

Closed
lefuentes opened this issue Aug 31, 2020 · 7 comments
Closed

Bug: Model doesn't reset errors in FeatureTestCase #3578

lefuentes opened this issue Aug 31, 2020 · 7 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@lefuentes
Copy link
Contributor

lefuentes commented Aug 31, 2020

Describe the bug
When I test with FeatureTestCase class the errors of models don't reset and I receive the last error.
Example:
Test PUT Method with bad validation. It return that I expect. But in the next test if I Test Put Method with success validation I still receive the last errors.
Example

CodeIgniter 4 version
latest.

Context

  • OS: [Linux]
  • PHP version [7.3]
@lefuentes lefuentes added the bug Verified issues on the current code behavior or pull requests that will fix them label Aug 31, 2020
@MGatner
Copy link
Member

MGatner commented Aug 31, 2020

Are your tests using model() or ModelFactory to load your models? If so you are probably getting shared instances of them. You can use ModelFactory::reset() in your test setUp() to make sure shares instances are cleared. This might not be a bad idea to add to the default resets.

@lefuentes
Copy link
Contributor Author

I don't use ModelFactory. I will try with that. But I think it doesn't a clear solution.
I have another bug when I use FeatureTestCase. The filters definied in the routes don't reset when first I test an route with filter and then I test an route without filters.

$routeFilter = $this->tryToRouteIt($routes);

It's beacuse the variable filterInfo has the before value

$this->filterInfo = $this->collection->getFilterForRoute($this->matchedRoute[0]);

If it's necessary I will create another issue.

@MGatner
Copy link
Member

MGatner commented Sep 1, 2020

The Filters issue sounds like this (#3085) resolves July 7. Are you using the latest version of the code?

@lefuentes
Copy link
Contributor Author

I tried this solution but it doesn't work. it's apply after of function tryToRouteIt.
Tomorrow I will upload an example complete about this bug.

@MGatner
Copy link
Member

MGatner commented Sep 1, 2020

Okay, please open a new issue for the filters example, and this can track the validation issue. My guess is that you will need to reset Validation between tests - something we should probably be doing in the core.

@lefuentes
Copy link
Contributor Author

lefuentes commented Sep 1, 2020

It's an example when models doesn't reset de errors.

Test Class:
https://pastebin.pl/view/80e85853

Model Class:
https://pastebin.pl/view/a27191e8

Controller Class:
https://pastebin.pl/view/4586b4b0

If it's necessary I upload more files.

@MGatner
Copy link
Member

MGatner commented May 8, 2021

This is actually expected. CIUnitTestCase does not reset Services by default:

	/**
	 * Methods to run during setUp.
	 *
	 * @var array of methods
	 */
	protected $setUpMethods = [
		'resetFactories',
		'mockCache',
		'mockEmail',
		'mockSession',
	];

If you desire this behavior there is already a resetServices method you can add to that list, or call during your test case's setUp().

@MGatner MGatner closed this as completed May 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

2 participants