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

test: fix BaseConfigTest #8095

Merged
merged 4 commits into from
Oct 26, 2023
Merged

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Oct 25, 2023

Description
Closes #8094
Follow-up #8036

  • add BaseConfig::reset() for testing
  • reset state after testing
$ ./phpunit tests/system/Config/
PHPUnit 9.6.13 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.1.24
Configuration: /.../CodeIgniter4/phpunit.xml

................................................................................................................................. 129 / 140 ( 92%)
...........                                                                                                                       140 / 140 (100%)

Time: 00:05.899, Memory: 22.00 MB

OK (140 tests, 241 assertions)

Checklist:

  • Securely signed commits
  • [] Component(s) with PHPDoc blocks, only if necessary or adds value
  • [] Unit testing, with >80% coverage
  • [] User guide updated
  • Conforms to style guide

Mocks should be removed.
@kenjis kenjis added the testing Pull requests that changes tests only label Oct 25, 2023
@kenjis kenjis force-pushed the test-fix-BaseConfigTest branch from 35044a8 to bfecd50 Compare October 25, 2023 22:27
$config = new RegistrarConfig();

$this->assertSame([], $config::$registrars);

// Reset Modules Config.
RegistrarConfig::setModules(new Modules());
Copy link
Member

Choose a reason for hiding this comment

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

this is already done in setUp

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but if the test method moves to the last, the mock object remains.
Since we are using static properties, we have to reset them again and again.

Copy link
Member

Choose a reason for hiding this comment

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

Then it should be added in tearDown also so if the test fails, resetting will still be done.

Copy link
Member Author

@kenjis kenjis Oct 26, 2023

Choose a reason for hiding this comment

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

Added tearDown() and so on.

It would be much easier without static properties.

@kenjis kenjis merged commit 6c788de into codeigniter4:develop Oct 26, 2023
@kenjis kenjis deleted the test-fix-BaseConfigTest branch October 26, 2023 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Pull requests that changes tests only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dev: FactoriesTest fails in develop after v4.4.2
2 participants