In light of #2863704: ConfigDiffer doesn't catch some differences, it would probably be a good idea to add more unit tests to this module.

That issue added a unit test for ConfigDiffer::same(). But it would be good to add tests for the other public methods on the base module's classes:
- [DONE] ConfigDiffer::diff()

- [DONE] ConfigLister::listTypes()
- [DONE] ConfigLister::getType()
- [DONE] ConfigLister::getTypeByPrefix()
- [DONE] ConfigLister::getTypeNameByConfigName()
- [DONE] ConfigLister::listConfig()

(Note that ConfigListerWithProviders extends ConfigLister, only adding new methods not overriding any, so they could be tested together if that is easier.)
- [DONE] ConfigListerWithProviders::listProviders()
- [DONE] ConfigListerWithProviders::getConfigProvider()
- [DONE] ConfigListerWithProviders::providerHasConfig()

- [DONE] ConfigReverter::import()
- [DONE] ConfigReverter::revert()
- [DONE] ConfigReverter::delete()
- [DONE] ConfigReverter::getFromActive()
- [DONE] ConfigReverter::getFromExtension()

We do have some coverage of many of these methods, indirectly in the ConfigUI tests, but unit test coverage would be a good idea anyway. Aside from the ConfigDiffer, however, the tests will probably not be all that easy to create. ConfigReverter and ConfigLister act on config storage, so they'll require some serious mocking/stubs. See
https://phpunit.de/manual/4.8/en/test-doubles.html
for documentation on how to do that. Also the ConfigDiffTest class has a mock already for the TranslationInterface that mocks the t() function, as one simple example.

If no one else takes this on, I will probably get to it in a few months, but probably not before end of May.

Comments

jhodgdon created an issue. See original summary.

mtodor’s picture

Status: Active » Needs review
StatusFileSize
new3.27 KB

Here is proposal for diff() function testing.

Basically -> one single config will be checked with multiple possible diff operations (delete, add, change, copy) -> and it will be validated that it's correct.

jhodgdon’s picture

Issue summary: View changes

This is very nice, thanks! The test passes too, always good. :)

I'm in the middle of working on another issue in this project at the moment, but when I'm done with that and my git repo is clean again, I will commit this. Updating the issue summary now.

jhodgdon’s picture

Status: Needs review » Active

Since the patch above has been committed, but there is more to do here, I'll set the status back to Active.

  • jhodgdon committed bdc68b0 on 8.x-1.x
    Issue #2917165 and #2863853 by jhodgdon, Pasqualle: Wrong export link...
jhodgdon’s picture

Issue summary: View changes

Over on #2917165: Wrong export link for migration_group I added some tests for ConfigLister methods, so updating summary here.

jhodgdon’s picture

jhodgdon’s picture

Status: Active » Needs review
StatusFileSize
new9.43 KB

Here is a patch that adds unit tests for the remaining methods in ConfigLister and ConfigListerWithProviders, and expands the existing tests there for the listConfig() method, to include testing for extensions. Test passes locally...

Status: Needs review » Needs work

The last submitted patch, 9: 2863853-9.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jhodgdon’s picture

Status: Needs work » Needs review
StatusFileSize
new9.46 KB

Oops, I guess you can have only one @covers line in a test class, and there were some coding standards problems... take 2!

jhodgdon’s picture

Issue summary: View changes
Status: Needs review » Active

Good, it passed this time. I fixed the remaining coding standards messages for that run, and committed. Updating summary and setting back to Active.

jhodgdon’s picture

Component: Base module » Tests

Added new issue component for tests...

jhodgdon’s picture

For some reason the last commit didn't show up here... here it is:
https://cgit.drupalcode.org/config_update/commit/?id=dd67747

jhodgdon’s picture

StatusFileSize
new20.63 KB

I was going to add tests for ConfigReverter, and realized I would need a bunch of mocks that were also used in the tests for ConfigLister. So, I refactored the existing unit tests to use a base class. Here's patch; tests passed locally but I'll run them here before committing.

jhodgdon’s picture

Status: Active » Needs review
StatusFileSize
new20.65 KB
new3 KB

Take 2 on refactor: fix some coding standards messages and (oops) make the test base class abstract.

jhodgdon’s picture

Status: Needs review » Active

OK, that version worked better, committing. I'll be working on tests for ConfigReverter sometime soon.

  • jhodgdon committed 25542f5 on 8.x-1.x
    Issue #2863853 by jhodgdon: Refactor unit tests using a base class
    
jhodgdon’s picture

Status: Active » Needs review
StatusFileSize
new13.09 KB

Here are some tests for two methods on ConfigReverter. I also realized that the class didn't specify what should happen in getFromActive() if the config didn't exist, so I made it more consistent with other methods.

Status: Needs review » Needs work

The last submitted patch, 19: 2863853-reverter-tests-19.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jhodgdon’s picture

Status: Needs work » Needs review
StatusFileSize
new14.13 KB
new2.93 KB

Fixed up coding standards and gotchas...

jhodgdon’s picture

Issue summary: View changes
Status: Needs review » Active

That's better. Committing this patch and updating issue summary. 3 methods on ConfigReverter to go, and the mock objects are getting richer...

  • jhodgdon committed 44d6b75 on 8.x-1.x
    Issue #2863853 by jhodgdon: Add unit tests for ConfigReverter methods
    
jhodgdon’s picture

Status: Active » Needs review
StatusFileSize
new12.1 KB

Here's a patch that adds a test for the ConfigReverter::import() method.

  • jhodgdon committed d2cda61 on 8.x-1.x
    Issue #2863853 by jhodgdon: Add unit test for ConfigReverter::import
    
jhodgdon’s picture

Issue summary: View changes

Good, that passed, with a few very minor coding standards fixes, so I committed it. 2 more methods to go!

jhodgdon’s picture

StatusFileSize
new9.85 KB

Here's a patch for the final 2 methods on the reverter...

  • jhodgdon committed 5785588 on 8.x-1.x
    Issue #2863853 by jhodgdon: Add more unit tests in ConfigReverter
    
jhodgdon’s picture

Issue summary: View changes
Status: Needs review » Fixed

OK, this passed, with 2 minor coding standards problems, which I fixed and committed. This is done!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.