Closed (fixed)
Project:
Currency
Version:
8.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
6 May 2015 at 13:39 UTC
Updated:
26 Nov 2019 at 23:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
LKS90 commentedComment #2
xanoThanks! Does this solve a particular problem? Both entity classes already override
::toArray()to build the export array. Currencies definitely need additional logic to export usages. The annotation will not be sufficient to achieve that.Comment #3
LKS90 commentedHey there!
To be honest, I'm not really sure. Some colleagues complained about slow site installs and exporting the config supposedly speeds that up. So they gave me the task to add the config_export array to all contribution modules. Berdir can probably tell you more about it.
Comment #4
berdirIf you have a custom toArray() implementation, then this won't help you much, yes, so feel free to ignore it.
config_export can also be defined as a mapping, so if you want to use some_property in yaml and someProperty in the class, then you can do that with that now.
Question is, why exactly do you need a custom toArray() implementation?
I can see that the loop in Currency is a bit special, but CurrencyLocale doesn't seem to do anything special?
One problem with your implementation is that you also skip default functionality like dependencies, which are important for the config system. You probably don't have any, but the config system might still do something based on having a dependencies key or not..
Comment #5
xanoThe
::toArray()override stems from when we didn't have the mappings or dependencies. We should at least make sure the parent implementation is called.Comment #6
LKS90 commentedThis patch now removes the custom code for the Currency::toArray() method and replaces it with the parent call. After the parent call we add the usages as an array instead of an object with protected fields. The second toArray method could be removed completely after some updates to the yml scheme. Mainly, the configs are now of type config_entity instead of some mapping and removed items like status and uuid which we already inherit from config_entity. I also updated the
scheme to the more consistent
version.
Comment #8
xanoAre you still working on this?
Comment #9
LKS90 commentedUpdated version, expecting a test fail complaining about missing schema for exchangeRates when creating a new currency. Will fix those errors when the testbot confirms my suspicion.
Comment #11
LKS90 commentedFixed the test fails.
I'm adding some stubs for exchangeRates, just to pass tests. If I should split the changes to different issues, just tell me.
One thing that is kind of confusing: Why do I have to explicitly set the exchangeRates in the CurrencyDeleteFormWebTest but none of the other attributes?
Comment #12
xanoWorking with exchange rates should not have been necessary. This is a bug for which I opened #2537510: Remove traces of old historical exchange rates.
Did you see a config error, or something else?
Comment #13
LKS90 commentedDuh, I thought the exchangeRates were new.. :D
It was a schema error, the CurrencyDeleteFormWebTest creates the currency entity with
Currecny::create(['currencyCode' => 'ABC',]);, all the other attributes have a default value that matches the schema, my re-added exchangeRates didn't and caused a schema error. The weird thing is I don't seem to find where the default value for those comes from when creating a currency entity directly.Here is an updated patch that has all the exchangeRates removed, will also provide a patch for the other issue.
Comment #14
LKS90 commentedComment #15
xanoWhy is this removed? We'll still need to convert raw usage data to
Usageobjects, don't we?Same here.
Comment #16
LKS90 commentedI readded the conversion of usages to toArray() and _construct(), but as I mentioned, the unit tests for currency fail now because the parent class (ConfigEntityBase) isn't mocked. Edit: Rebase soon... :D
Comment #18
LKS90 commentedHere is the rebase, completely forgot about the other mini-patch.
Comment #20
xanoThe patch contains some indentation errors (four spaces instead of two).
Parent classes can never be mocked. Methods on SUTs can be mocked, but not if it's the parent of the method you're trying to test. In this case the entity manager and typed config manager need to be mocked, as those are the dependencies
ConfigEntityBase::toArray()tries to locate.Comment #21
toncic commentedCleaning patch and try to fix test failing, but seems that HEAD is failing. I don't providing interdiff because the previous patch was so far and I couldn't apply it.
Comment #22
toncic commentedAnd patch.
Comment #23
xanoThanks! Can you file this as a PR at https://github.com/bartfeenstra/drupal-currency? This project no longer uses drupal.org's testing infrastructure due to its limitations, so we use another CI through Github instead.
Comment #24
berdirRebased.
Comment #25
berdirConverted the two toArray() unit test methods to kernel tests, which made them so much more useful and easier to work with. And the result is the same except that we now also get some standard keys in there.
Comment #26
berdirCommitted, finally.