I'm coming to the end of the process of upgrading a site from an old version of apachesolr to the latest release, and in doing so I ran into a few cases where function parameters that used to be strings were now arrays, and the module was therefore behaving weirdly. By adding typing to some function definitions I was able to get more useful error messages telling me what I needed to change. I also came across a case where the docblock was outdated for the function it was documenting.

Patch to follow.

Comments

ianthomas_uk’s picture

ianthomas_uk’s picture

Status: Active » Needs review
alanmackenzie’s picture

Status: Needs review » Needs work

+1 very sensible.

A couple of minor points:

We can remove the entire if statement checking if is_array() isn't true now.

public function search($query = '', array $params = array(), $method = 'GET') {
  if (!is_array($params)) {
    $params = array();
  }
   ...

This parameter should have a description to be 100% coding standards compliant. e.g.

   * @param DrupalApacheSolrService $solr
   *   The solr server resource to execute the search on.
   *
ianthomas_uk’s picture

Status: Needs work » Needs review
StatusFileSize
new2.72 KB

This patch addresses Alan's points

nick_vh’s picture

Great work, let's see if the test succeeds and we can start committing some of the patches you guys made :-)

ianthomas_uk’s picture

Is this ready to commit?

pwolanin’s picture

Status: Needs review » Needs work

DrupalApacheSolrService needs to be an interface not the concrete class - I'm confused as to why this doesn't break the tests using the Dummysolr class.

pwolanin’s picture

seems we don' have an interface at the moment, so we need to either define one, or not type hit DrupalApacheSolrService

ianthomas_uk’s picture

Status: Needs work » Needs review
StatusFileSize
new15.04 KB

Here is a version with an interface (just a straight copy of the class, including docs and copyright, with function bodies removed - let me know if I should do anything else).

Status: Needs review » Needs work

The last submitted patch, apachesolr-extra_parameter_typing-1708150-9.patch, failed testing.

ianthomas_uk’s picture

Status: Needs work » Needs review
StatusFileSize
new15.04 KB

Status: Needs review » Needs work

The last submitted patch, apachesolr-extra_parameter_typing-1708150-11.patch, failed testing.

ianthomas_uk’s picture

Status: Needs work » Needs review
StatusFileSize
new13.41 KB

Status: Needs review » Needs work

The last submitted patch, apachesolr-extra_parameter_typing-1708150-13.patch, failed testing.

ianthomas_uk’s picture

Status: Needs work » Needs review
StatusFileSize
new13.77 KB

OK, that failed because the Dummy_Solr class doesn't implement the new interface.

I'm not too familiar with unit tests, so I'm not sure what the correct fix should be, but extending the real class makes sense to me.

Status: Needs review » Needs work

The last submitted patch, apachesolr-extra_parameter_typing-1708150-15.patch, failed testing.

pwolanin’s picture

Better would be to make the dummy (mock) class implement the interface independently. That would be a good basis for more unit testing in any case.

nick_vh’s picture

StatusFileSize
new12.68 KB
nick_vh’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1708150-18.patch, failed testing.

nick_vh’s picture

Status: Needs work » Needs review

#18: 1708150-18.patch queued for re-testing.

nick_vh’s picture

Version: 7.x-1.x-dev » 6.x-3.x-dev
Status: Needs review » Patch (to be ported)
ianthomas_uk’s picture

Assigned: ianthomas_uk » Unassigned

Thanks for finishing that off for me, I wasn't sure what to do with the failures of #15 as the test suite wasn't very specific about the error. Is there a way to get a better error message (setting up tests locally?), or did you just work out the problem from the code?

You've still got DummySolr extending DrupalApacheSolrService - is that intentional? It seems redundant to implement an interface that the parent class implements, but also seems a lot of work to need to re-implement all the methods.

pwolanin’s picture

Version: 6.x-3.x-dev » 7.x-1.x-dev
Status: Patch (to be ported) » Needs work

Ugh, that's wrong we should not do that - it should just implement the interface, even if the functions are no-op for now.

pwolanin’s picture

Status: Needs work » Needs review
StatusFileSize
new8.67 KB

Here's a new patch that move some helper functions out of the interface - either to private, or just let them be helpers that aren't part of the interface.

pwolanin’s picture

Version: 7.x-1.x-dev » 6.x-3.x-dev
Status: Needs review » Patch (to be ported)

committed to 7.x

pwolanin’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new18.68 KB

combined 6.x-3.x patch.

pwolanin’s picture

StatusFileSize
new17.88 KB

patch splitting out part to #1786450: apachesolr.interface.inc is not always loaded

That has to be applied at the same time

pwolanin’s picture

Status: Needs review » Fixed

committed

Status: Fixed » Closed (fixed)

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