Skip to content
This repository has been archived by the owner on Jul 20, 2019. It is now read-only.

Improve testCleanTerms_completelyCleansArray #18

Merged
merged 3 commits into from
May 21, 2019

Conversation

JeroenDeDauw
Copy link
Contributor

The two calls to acquireTermIds seemed to be accidental
complexity so I changed to only one call.

I also removed access to the private field as this is surprising
and breaks automated refactoring. New approach has class define
explicitly what can be accessed.

... Just realized:

Since the tested class is an in memory implementation meant
for tests and implements a package private interface, it is
probably better placed in tests/TestDoubles or similar rather
than src/. Lets clean that up in some follow up.

@lucaswerkmeister lucaswerkmeister force-pushed the clean-inmemory branch 2 times, most recently from 05b3166 to 3acc58e Compare May 15, 2019 16:10
@AlaaSarhan AlaaSarhan changed the base branch from clean-inmemory to master May 16, 2019 13:08
The two calls to acquireTermIds seemed to be accidental
complexity so I changed to only one call.

I also removed access to the private field as this is surprising
and breaks automated refactoring. New approach has class define
explicitly what can be accessed.

... Just realized:

Since the tested class is an in memory implementation meant
for tests and implements a package private interface, it is
probably better placed in tests/TestDoubles or similar rather
than src/. Lets clean that up in some follow up.
@AlaaSarhan
Copy link
Collaborator

Also rebased and improved this based on both suggestions: do not bind to internal implementation, check that terms are empty when there no leaf nodes (term texts) not just that the top array is an empty array.

AlaaSarhan
AlaaSarhan previously approved these changes May 17, 2019
Copy link
Member

@lucaswerkmeister lucaswerkmeister left a comment

Choose a reason for hiding this comment

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

This completely inverts the original intention of the test now. If you absolutely want to do that, sure, but at least rename the test function, because “completely cleans array” is no longer what it tests.

@AlaaSarhan
Copy link
Collaborator

oh I see.. maybe I misunderstood the diiscussion I thought from your comment that you wanted to actually test that the array is empty as in [ 'label' => [ 'en' => [] ] ] is considered empty.

Okay will have a second in-depth look and adjust it acoordingly

@AlaaSarhan
Copy link
Collaborator

Renamed one test to actually tests hasTerms behavior and added another one for the opposite case.

For a test-double, testing its behavior through covering the helper methods only is enough and probably preferred (as doubles usually do tricks internally when pretending to implement the behavior they "mock")

@AlaaSarhan AlaaSarhan dismissed their stale review May 17, 2019 09:12

I've made changes so my approval is irrelevant now

// if there's any leaf element in terms then it's not empty, otherwise we consider
// the terms array empty even if it had some sub-arrays that are also empty by
// this definition
array_walk_recursive(
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 going to walk the whole array all the time :/ But given this is probably only going to be used in tests, I guess that's bearable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah this array isn't expected to contain more than tens of elements for testing purposes (hopefully).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is the old version that used assertEmpty on the terms field broken? This looks like a behavior change to me. I already asked about it on the PR that motivated this change and got no answer.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I might have got lost with the conversation and misunderstood it (though I doubt).

You may ignore this PR entirely or just revert my changes (I can do it on command ;) if you think it is completely irrelevant to the original improvement/discussion. Sorry to have wasted your time in that case :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The first version did

assertEmpty( $terms )

Then I changed it do

assertTrue( empty( $terms ) )

AFAIK that is equivalent. But Lucas said I broke it. Your change here suggests you think it was indeed broken. Where did it get broken?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's not sweat this one anymore.. it is so trivial anyway. Either merge or kill at will please

@JeroenDeDauw JeroenDeDauw reopened this May 21, 2019
@JeroenDeDauw JeroenDeDauw merged commit 20c7ece into master May 21, 2019
@JeroenDeDauw JeroenDeDauw deleted the completelyCleansArray branch May 21, 2019 00:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants