Hey,
Constructing entities from their serialization in tests has long been discouraged. A few weeks back we removed support for this on the master branch of DataModel. In going though the remaining occurrences, I find myself surprised that some got introduced as little as two weeks ago, and merged in by a member of the Wikidata team.
What to not do:
$item = new Item( array( .... ) );
What to do instead (as has been done in most places for quite some time):
$item = Item::newEmpty(); $item->setStuff();
Cheers
-- Jeroen De Dauw - http://www.bn2vs.com Software craftsmanship advocate Evil software architect at Wikimedia Germany ~=[,,_,,]:3
Why this is better? Am 06.06.2014 06:08 schrieb "Jeroen De Dauw" jeroendedauw@gmail.com:
Hey,
Constructing entities from their serialization in tests has long been discouraged. A few weeks back we removed support for this on the master branch of DataModel. In going though the remaining occurrences, I find myself surprised that some got introduced as little as two weeks ago, and merged in by a member of the Wikidata team.
What to not do:
$item = new Item( array( .... ) );
What to do instead (as has been done in most places for quite some time):
$item = Item::newEmpty(); $item->setStuff();
Cheers
-- Jeroen De Dauw - http://www.bn2vs.com Software craftsmanship advocate Evil software architect at Wikimedia Germany ~=[,,_,,]:3
Wikidata-tech mailing list Wikidata-tech@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikidata-tech
Hey,
Why this is better?
Because it does not force knowledge of a specific serialization format onto the entity object and does not prevent constructing it from its composited-in parts.
Note that this is about the PHP codebase of Wikibase. It has no impact on the users of the software, such as Wikidata.org.
Cheers
-- Jeroen De Dauw - http://www.bn2vs.com Software craftsmanship advocate Evil software architect at Wikimedia Germany ~=[,,_,,]:3
Am 06.06.2014 06:07, schrieb Jeroen De Dauw:
$item = new Item( array( .... ) );
Some tests I touched recently use this, and I didn't change it, just moved things around.
I agree that knowing about a specific serialization format in tests is bad.
On the other hand, it's nice to be able to construct an entity in a single statement, instead of building it iteratively.
Also, some test cases take the array data as input, and only construct the entity when running the test. This is convenient in cases when the data provider does not know the concrete type of entity under test. I guess that's why this was introduced. I'm moving tests away from that, though.
-- daniel
Hey,
I'm moving tests away from that, though.
Thanks. Any help with this is much appreciated.
Cheers
-- Jeroen De Dauw - http://www.bn2vs.com Software craftsmanship advocate Evil software architect at Wikimedia Germany ~=[,,_,,]:3
wikidata-tech@lists.wikimedia.org