</code>Not sure my conclusion is correct, but running the test suite against Core's Beta 10 release (for which I want to release a compatible Alpha 4 version of this module) gives the following error in the PHPUnit tests (all Drupal tests run correctly):

<code>
Fatal error: Call to undefined function Drupal\search_api\drupal_static() in /var/www/drupal/drupal8/modules/search_api/src/Utility.php on line 130

The function is still there, though, so it seems we need to manually include bootstrap.inc in the tests?
Waiting for confirmation that this is indeed the cause, then I can of course provide a patch.

Also, and unrelatedly, there are again some schema fails. Seems like we need to manually cast the status properties to boolean when saving a server/index?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drunken monkey’s picture

Component: Framework » Tests
Status: Active » Needs review
FileSize
326 bytes

Uploading dummy patch to see if the fail also occurs for the test bot or it's just my setup …

Status: Needs review » Needs work

The last submitted patch, 1: foo.patch, failed testing.

drunken monkey’s picture

Title: It seems PHPUnit tests now need to manually include bootstrap.inc » Adapt to latest Core changes
Issue summary: View changes
Status: Needs work » Active

Huh. Different fails, interesting. Should fix those, too, of course.
But doesn't/shouldn't the test bot test PHPUnit tests, too? I thought it did …

Could someone please test if the Search API PHPUnit tests pass for them locally? (And verify that the normal tests pass with Drupal 8.0.0 Beta 10.)

drunken monkey’s picture

Title: Adapt to latest Core changes » Drupal.org test bot doesn't run our PHPUnit tests

The config fails were fixed by Andrei in #2483179: Fix some config properties for our test servers and indexes, so changing the title again.

Also, I had a short IRC chat with Sascha who helped me a lot. According to him, bootstrap.inc was never included, so probably the need for it is just new (i.e., the drupal_static() calls were newly added). But since the test bot doesn't run our PHPUnit tests, we didn't notice that.

So, the primary goal of this issue is now to get the d.o test bot to run our PHPUnit tests, and (of course) to also get them passing.
The test bot seems to use run-tests.sh --files internally, maybe the problem lies there? Sascha says its similiar to his code for D8 Module Status.

amateescu’s picture

I could swear that we already had an issue with a similar title somewhere on drupal.org. Can't seem to find it on google though :(

LKS90’s picture

Status: Active » Needs review
FileSize
27.62 KB

Alright, a patch that fixes all the test fails and moves the unit tests to the correct location.
In case you would like me to split the commits into separate issues, just tell me. Moving the unit tests to the correct location is a separate commit from the test fixes.

Status: Needs review » Needs work

The last submitted patch, 6: unitTestFix_2482655_1.patch, failed testing.

LKS90’s picture

Status: Needs work » Needs review
FileSize
27.1 KB

Another try, this time it should pass.

Removed another 'menu_link' dependency (which causes the getPath() on non-object error) which I forgot.
Moved 2 unit tests out of the testing folder. Testbot doesn't like them, locally (with the run-tests script) it at least runs but testbot doesn't even do that. Excluding these two tests (from the menu subfolder) should make the testbot run.

Berdir’s picture

Status: Needs review » Needs work

The unit tests are executed now and everything is green, nice. However, we're not quite done yet ;)

  1. +++ b/src/DataType/DataTypePluginManager.php
    @@ -38,4 +39,79 @@ class DataTypePluginManager extends DefaultPluginManager {
    +  /**
    +   * Returns the custom data types.
    +   *
    +   * @return \Drupal\search_api\DataType\DataTypeInterface[]
    +   *   An array of data type plugins, keyed by type identifier.
    +   */
    +  public function getCustomDataTypes() {
    

    We should have an interface for that service and move the documentation to it, would also make unit testing a bit easer. but that can be done in a separate issue I think.

    Do we actually need *Custom* in the method names?

  2. +++ b/src/DataType/DataTypePluginManager.php
    @@ -38,4 +39,79 @@ class DataTypePluginManager extends DefaultPluginManager {
    +      $data_type_plugin_manager = \Drupal::service('plugin.manager.search_api.data_type');
    +
    +      foreach ($data_type_plugin_manager->getDefinitions() as $name => $data_type_definition) {
    +        if (class_exists($data_type_definition['class']) && empty($custom_data_types[$name])) {
    +          $data_type = $data_type_plugin_manager->createInstance($name);
    

    $data_type_plugin_manager is now $this, you don't need to call the service anymore.

  3. +++ b/src/DataType/DataTypePluginManager.php
    @@ -38,4 +39,79 @@ class DataTypePluginManager extends DefaultPluginManager {
    +    $types = NULL;
    

    you need to define this as a property ($this->customDataTypes) otherwise the caching isn't doing anything.

  4. +++ b/src/Tests/Processor/TestItemsTrait.php
    @@ -112,4 +134,30 @@ trait TestItemsTrait {
    +  /**
    +   * Returns the dataTypePlugin.
    +   */
    +  public function getDatatypePlugin() {
    

    Don't return it, assign it to $this->dataTypePlugin. Same for results static cache.

    And then rename the method to setUpDataTypePlugin().

  5. +++ b/src/Tests/Processor/TestItemsTrait.php
    @@ -112,4 +134,30 @@ trait TestItemsTrait {
    +    $data_type_manager->expects($this->any())
    +      ->method('getCustomDataTypes')
    +      ->will($this->returnValue(array()));
    +    $results_static_cache->expects($this->any())
    +      ->method('getResults')
    +      ->will($this->returnValue(array()));
    

    Maybe we will need to extend this at some point and make it more flexible, but it looks like none of the unit tests need anything to be returned right now, they just happen to call it.

  6. +++ b/src/Utility.php
    @@ -73,11 +73,11 @@ class Utility {
        */
       public static function getDataTypeOptions() {
         $types = array();
    -    foreach (self::getDataTypeInfo() as $id => $info) {
    +    foreach (\Drupal::service('plugin.manager.search_api.data_type')->getDataTypeInfo() as $id => $info) {
           $types[$id] = $info['label'];
         }
    

    This method should then move as well.

  7. +++ b/src/Utility.php
    @@ -284,7 +209,7 @@ class Utility {
           static::$dataTypeFallbackMapping[$index_id] = array();
    -      foreach (self::getCustomDataTypes() as $type_id => $data_type) {
    +      foreach (\Drupal::service('plugin.manager.search_api.data_type')->getCustomDataTypes() as $type_id => $data_type) {
    

    In the long term, I think this class should not have any method that call out to Drupal::service(), but I think we don't need to move everything here, the patch is big enough.

  8. +++ b/tests/src/Unit/Plugin/Processor/TransliterationTest.php
    @@ -37,6 +37,7 @@ class TransliterationTest extends UnitTestCase {
     
    +    $this->dataTypePlugin = self::getDatatypePlugin();
    

    This isn't a static method, call it with $this->, same for all other calls.

    Also don't forget to remove the assignment when you don't return it anymore.

LKS90’s picture

Status: Needs work » Needs review
FileSize
27.94 KB

New patch, points 2, 3, 4, 6 and 8 should be improved.

Thing still open:
1. Interface for DatatypePlugin
2. Extend mock methods where needed
3. Remove Drupal::serivce() calls from Utility class
4. Move ResultsCache Mock into a separate set up function. (currently in setUpDataTypePlugin())

Status: Needs review » Needs work

The last submitted patch, 10: unitTestFix_2482655_3.patch, failed testing.

LKS90’s picture

And an interdiff file which shows the last changes.

Berdir’s picture

  1. +++ b/src/DataType/DataTypePluginManager.php
    @@ -23,6 +23,18 @@ use Drupal\search_api\Utility;
     class DataTypePluginManager extends DefaultPluginManager {
     
       /**
    +   * The custom data types property.
    +   *
    +   * @var array $customDataTypes
    +   */
    +  protected $customDataTypes;
    +  /**
    +   * The data type options property.
    +   *
    +   * @var array $dataTypeOptions
    +   */
    +  protected $dataTypeOptions;
    +  /**
    

    should have an empty line between the two and only one between class and the first docblock.

  2. +++ b/src/DataType/DataTypePluginManager.php
    @@ -77,7 +87,7 @@ class DataTypePluginManager extends DefaultPluginManager {
       public function getDataTypeInfo($type = NULL) {
    -    $types = NULL;
    +    $types = $this->customDataTypes;
    

    Not quite ;)

    Just remove $types, use $this->customDataTypes directly.

  3. +++ b/src/Tests/Processor/TestItemsTrait.php
    @@ -135,9 +135,9 @@ trait TestItemsTrait {
    -  public function getDatatypePlugin() {
    +  public function setUpDataTypePlugin() {
    

    The function can be protected.

  4. +++ b/src/Tests/Processor/TestItemsTrait.php
    @@ -157,7 +157,8 @@ trait TestItemsTrait {
    +    $this->dataTypePlugin = $data_type_manager;
    +    $this->resultsStaticCache = $results_static_cache;
    

    No need for temporary local variables, just assign to $this->.. directly.

LKS90’s picture

Status: Needs work » Needs review
FileSize
27.83 KB
3.6 KB

New version, this one seems to take some time while testing, so probably some more issues after this test run.

Test summary
------------

Drupal\search_api_db\Tests\BackendTest                       158 passes                           
Drupal\Tests\search_api\Unit\Plugin\Processor\TokenizerTest   22 passes                                 
Drupal\Tests\search_api\Unit\Plugin\Processor\Transliteratio   3 passes                               
Drupal\Tests\search_api\Unit\Plugin\Processor\FieldsProcesso  13 passes                                      
Drupal\Tests\search_api\Unit\Plugin\Processor\AddURLTest       2 passes                                      
Drupal\Tests\search_api\Unit\Plugin\Processor\IgnoreCaseTest   4 passes                                      
Drupal\Tests\search_api\Unit\Plugin\Processor\StopwordsTest    8 passes                                      
Drupal\Tests\search_api\Unit\Plugin\Processor\HighlightTest   13 passes                                      
Drupal\Tests\search_api\Unit\Plugin\Processor\IgnoreCharacte  39 passes                                      
Drupal\Tests\search_api\Unit\Plugin\Processor\LanguageTest     2 passes                                      
Drupal\Tests\search_api\Unit\Plugin\Processor\AggregatedFiel   9 passes                                      
Drupal\Tests\search_api\Unit\Plugin\Processor\HtmlFilterTest  25 passes                                      
Drupal\Tests\search_api\Unit\Plugin\Processor\NodeStatusTest   3 passes                                      
Drupal\Tests\search_api\Unit\Plugin\Processor\RoleFilterTest   2 passes                                      
Drupal\search_api\Tests\Processor\ContentAccessTest           72 passes                                      
Drupal\search_api\Tests\Processor\RenderedItemTest            42 passes                                      
Drupal\search_api\Tests\Processor\ProcessorIntegrationTest    31 passes  21 fails  20 exceptions             
Drupal\search_api\Tests\ServerTaskUnitTest                    59 passes                                      
Drupal\search_api\Tests\LocalActionsWebTest                    6 passes   7 fails   3 exceptions             
Drupal\search_api\Tests\ServerStorageUnitTest                  6 passes                                      
Drupal\search_api\Tests\LanguageIntegrationUnitTest           35 passes                                      
Drupal\search_api\Tests\IndexStorageUnitTest                   5 passes                                      
Drupal\search_api\Tests\OverviewPageTest                      58 passes  47 fails  25 exceptions             
Drupal\search_api\Tests\CustomDataTypesUnitTest               17 passes   1 fails                            
Drupal\search_api\Tests\IntegrationTest                       18 passes  28 fails  10 exceptions             
Drupal\search_api\Tests\ViewsTest                             16 passes  10 fails   1 exceptions        

Test run duration: 46 min 18 sec

wow... :D
--
Edit:

IntegrationTest: mostly fields that can't be set, tedious but easy fix.

CustomDataTypesUnitTest: FAILED: The processed value matches the altered original value

Status: Needs review » Needs work

The last submitted patch, 14: unitTestFix_2482655_4.patch, failed testing.

Berdir’s picture

+++ b/src/DataType/DataTypePluginManager.php
@@ -120,8 +121,7 @@ class DataTypePluginManager extends DefaultPluginManager {
   public function getCustomDataType($type) {
-    $custom_data_types = $this->getCustomDataTypes();
-    return isset($custom_data_types[$type]) ? $custom_data_types[$type] : NULL;
+    return isset($this->customDataTypes[$type]) ? $this->customDataTypes[$type] : NULL;
   }

This change is not correct, you still need to call the method.

LKS90’s picture

Status: Needs work » Needs review
FileSize
27.86 KB
499 bytes

Modified one method to call getCustomDataTypes().

Status: Needs review » Needs work

The last submitted patch, 17: unitTestFix_2482655_5.patch, failed testing.

LKS90’s picture

Status: Needs work » Needs review
FileSize
28.1 KB
602 bytes

After moving the getDataTypeOptions method, I forgot to update the usage. That caused the test fails for IntegrationTest. New patch, I hope it also fixes the other test :D.

Status: Needs review » Needs work

The last submitted patch, 19: unitTestFix_2482655_6.patch, failed testing.

LKS90’s picture

Status: Needs work » Needs review
FileSize
28.65 KB
777 bytes

Fixed the last test fail.

LKS90’s picture

Some more improvements. Tests should still pass.

getCustomDataType() has been removed, getDataTypeInfo() has been fixed and extractField() has been changed to accommodate the usage of createInstance instead of getCustomDataType(). The tests should pass (I only ran IntegrationTest, the pickiest one :D)

Status: Needs review » Needs work

The last submitted patch, 22: unitTestFix_2482655_8.patch, failed testing.

LKS90’s picture

FileSize
28.36 KB

#21 wasn't really fixing anything, it just made the tests pass. I still don't get what that tests are doing, apparently. Here is the latest patch. with #21 reverted. All tests should pass now.

LKS90’s picture

Status: Needs work » Needs review
Berdir’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/src/Tests/CustomDataTypesUnitTest.php
@@ -121,6 +121,7 @@ class CustomDataTypesUnitTest extends EntityUnitTestBase {
 
+    debug($name_field->getValues());

Left-over debug. Can be fixed on commit as well.

The data type API needs more work, but I think this is a step in the right direction. I'm not sure why there are hardcoded data types and custom plugin data types, I think those should be converted to plugins too, would allow to simplify the API a lot.

drunken monkey’s picture

Status: Reviewed & tested by the community » Active
FileSize
258.92 KB
17.34 KB

The data type API needs more work, but I think this is a step in the right direction. I'm not sure why there are hardcoded data types and custom plugin data types, I think those should be converted to plugins too, would allow to simplify the API a lot.

This is done because those types are special, because they are the types which backends have to support. Thus, they need to be hard-coded, retrievable separately and, e.g., also don't need a fallback type.
Therefore, they are really quite different from the data type plugins, which are really just the "custom" ones.
Of course, it would still be possible to define them as plugins and use other means to mark them as the "default" types, but I think this way is working quite well, and I don't think changing it would really simplify things.

In any case, I now looked over the patch, and it looks quite good, great job!
As is my custom, I'm rather nit-picky and therefore of course had some corrections, mostly about proper dependency injection and – as always – documentation (though you did really well in that last part!).

The updated patch is attached, along with an interdiff. If it passes for the test bot, I'll just commit it and create a new release. If it still needs polish or you have other objections, we can still change it after that. But getting the tests to pass first always seems like a good idea.

drunken monkey’s picture

Issue summary: View changes
  1. +++ a/search_api_db/src/Plugin/search_api/backend/Database.php
    @@ -1370,7 +1401,7 @@ class Database extends BackendPluginBase {
    -            $types = \Drupal::service('plugin.manager.search_api.data_type')->getDataTypeDefinitions();
    +            $types = $this->getDataTypePluginManager()->getDataTypeDefinitions();
    

    In classes which can use dependency injection, you should never use \Drupal. I changed this to proper DI.
    (Same in the IndexFieldsForm class.)

  2. +++ a/src/DataType/DataTypePluginManager.php
    @@ -87,15 +84,12 @@ class DataTypePluginManager extends DefaultPluginManager {
    -   *
    -   * @todo convert default data types into plugin definitions and merge this
    -   *   method into getDefinitions().
    

    As explained above, this has its reason. At the very least it should have its own issue with a discussion, it's not just a @todo.

  3. +++ a/src/Tests/Processor/TestItemsTrait.php
    @@ -33,20 +33,6 @@ trait TestItemsTrait {
    -   * The data type plugin.
    -   *
    -   * @var \Drupal\search_api\DataType\DataTypePluginManager
    -   */
    -  protected $dataTypePlugin;
    -
    -  /**
    -   * The static cached result.
    -   *
    -   * @var \Drupal\search_api\Query\ResultsCache
    -   */
    -  protected $resultsStaticCache;
    -
    

    These don't seem to be used anywhere, currently, so I don't see a reason to keep those references.
    Moreover, if someone needs them, they can just obtain them from \Drupal – that's the whole point, after all.

Also, I moved the two Menu unit tests, too. Or is there a reason this wasn't done?

Anyways, thanks again for all your work on this, Sascha and especially Lukas!
(Now crossing my fingers this still passes …)

drunken monkey’s picture

Status: Active » Reviewed & tested by the community

(Don't know why it switched status, I specifically checked that it's still on "RTBC" before …)

Berdir’s picture

On custom vs. default data types: Ok, but the weird thing is that a number of those methods on the data type plugin manager are now overlapping with the getDefinition()/getDefinitions() methods but by going through multiple nested calls.. getDataTypeDefinitions() calls getCustomDataTypes(), which instantiates all the plugin objects only to get the definitions from them again.

And the naming is quite strange, it's a DataTypePluginManager, but actually defines custom data types only, so getCustomTypes() returns it's own stuff and getDataType* returns more..

We tried to limit how many changes we make here so we stopped making more changes there, that's also why we didn't inject stuff nicely.. it already called static methods that then again called into services before, it was just better hidden :)

Maybe open an issue to discuss the naming of those methods?

We didn't move the Menu unit test because they are broken :) One is completely empty and doesn't do anything, the other fails and is kind of disabled with @requires extension disabled, but that doesn't actually work.

Also, looks like your git isn't configured for renames, so the unit test move makes the patch huge :)

drunken monkey’s picture

And the naming is quite strange, it's a DataTypePluginManager, but actually defines custom data types only, so getCustomTypes() returns it's own stuff and getDataType* returns more..

That's why we had the code in Utility, not in the plugin manager.
But I guess bundling that code there still makes sense. We should just make it clearer to people looking at the code to see what's going on. So, according to your suggestion, I created a new issue for that: #2493599: Make our data type system more easily understandable.

We didn't move the Menu unit test because they are broken :) One is completely empty and doesn't do anything, the other fails and is kind of disabled with @requires extension disabled, but that doesn't actually work.

Oh, so my patch will fail? It worked for me fine locally …
In any case, I don't think leaving them there, without comment, in a kind-of-unsupported location isn't a solution. We should either fix the test cases, or remove them (or fix one and remove the other). Or is the non-empty one just so conceptually broken?
(In any case, whatever we do, we can do that in a new issue. I want to get this committed and don't plan to hold it up any further.)

Also, looks like your git isn't configured for renames, so the unit test move makes the patch huge :)

Ah, thanks a lot for pointing that out, I didn't even know there was a setting for that!
And if d.o understands that format – perfect!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 27: 2482655-27--fix_test.patch, failed testing.

drunken monkey’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
34.77 KB

Ah, OK, then here's the patch with the Menu tests removed, and here is the follow-up issue: #2493863: Re-add tests for the menus.

drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Ah, excellent!
So, finally committed!
Thanks a lot again, Lukas and Sascha!

  • drunken monkey committed ebab3d5 on 8.x-1.x authored by LKS90
    Issue #2482655 by LKS90, Berdir, drunken monkey: Fixed PHPUnit tests.
    

Status: Fixed » Closed (fixed)

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