Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
entity system
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
10 Mar 2015 at 16:45 UTC
Updated:
28 Mar 2015 at 00:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
tstoecklerComment #2
banviktor commentedI agree it doesn't match the documentation.
Added link for documentation in the issue summary.
Comment #3
banviktor commentedComment #4
banviktor commentedI have uploaded a patch for the issue
Comment #5
tstoecklerAwesome that you wrote a test, thanks!
I looked at how the rest of the tests in that class are implemented and I noticed that we can simplify the test I think.
ContentEntityBaseUnitTestalready has a$this->entitywhich gets prepared insetUp()which you can use directly.So the test could be written as
or similar.
Comment #6
banviktor commentedI've tried that way, but set() calls get() first which needs a lot of things that isn't valid in $this->entity, and results in error. I could use $this->entity but can't avoid creating a mocked FieldItemInterface for mocking the get()'s return value.
Should I rewrite the test so that it uses $this->entity instead of $mock_base?
Comment #7
banviktor commentedI have to update it anyway cause the version I uploaded don't even need the mock for ContentEntityBase's getTranslatedField.
Comment #8
banviktor commentedI've fixed the getTranslatedField issue, but not sure how I could use $this->entity. It's created with getMockForAbstractClass() and I can't mock get() afterwards as it's not an abstract method.
Comment #9
tstoecklerYes, you are completely right. Sorry, I thought I had seen some existing usage of
$this->entity->set()but that was in a different test class. Sorry, stupid me.ContentEntityBaseUnitTestis already pretty weird in that it's more of an integration test, but I still think it makes sense to align this more with the current code. I.e. in theory I think your code is preferred (because it's an actual unit test) but it's not inline with the rest of the class.So I played around a bit and the following seems to work:
Add
in
setUp()where$this->fieldTypePluginManageris being set up.Then my above sample code should work (but for the fact that I forgot the second required argument).
Can you try that @banviktor?
Removing the Novice tag, this is getting a bit convoluted... :-)
Comment #10
banviktor commentedGreat idea!
Implemented, tested, uploaded.
Comment #11
tstoecklerAwesome, this looks great to me.
@banvikor: Our coding standards dictate that there's an empty space between the "//" and the begining of the sentence.
I'm hoping that can be fixed on commit, so marking RTBC.
Comment #12
alexpottThis issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed 5a58ba9 and pushed to 8.0.x. Thanks!
Comment #14
tstoecklerAwesome work @banviktor, welcome to the team! :-)