Problem/Motivation

EntityType::setStorageClass() does not return anything.
Per EntityTypeInterface::setStorageClass(), however, it should return $this.

Proposed resolution

Add a return statement.

Remaining tasks

User interface changes

None.

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tstoeckler created an issue. See original summary.

kamalrajsahu21’s picture

Assigned: Unassigned » kamalrajsahu21
kamalrajsahu21’s picture

Here is the patch. Please review and commit.

kamalrajsahu21’s picture

Assigned: kamalrajsahu21 » Unassigned
Status: Active » Needs review
tstoeckler’s picture

Status: Needs review » Needs work

That looks's perfect, thanks!

Can you add a quick test to EntityTypeTest? There's already a testGetStorageClass() so maybe we can add a little testSetStorageClass() below it.

leolandotan’s picture

Assigned: Unassigned » leolandotan

I'll try to work on this.

leolandotan’s picture

Assigned: leolandotan » Unassigned
Status: Needs work » Needs review
FileSize
1.33 KB
915 bytes

Here I have added a simple test method for the `setStorageClass` method.

Hope everything is in order.

Status: Needs review » Needs work

The last submitted patch, 7: return-this-2758559-7.patch, failed testing.

eporama’s picture

Version: 8.1.x-dev » 8.2.x-dev
Status: Needs work » Needs review
FileSize
1.2 KB
940 bytes
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php
@@ -166,6 +166,20 @@ public function testGetStorageClass() {
+    $updated_entity_type = $entity_type->setStorageClass($controller . 'NewTest');
+    $this->assertSame($controller . 'NewTest', $updated_entity_type->handlers['storage']);

The issue here is that setStorageClass is now returning a full entityType object, not just the name of the storage class itself.

Also, since handlers is a private method of entityType, you can't call it here. So we have to use getStorageClass (which is getHanderClass('storage')). However, getHandlerClass has a check to make sure the class is defined, we can't test with just concatenating "NewTest" on the name of the class because then getHandlerClass returns null.

You can, however, set up the entity with a null storage class and then change it to the $controller class.

Status: Needs review » Needs work

The last submitted patch, 9: 2758559-9.patch, failed testing.

eporama’s picture

Just FYI, looks like this failure is not specifically in this new patch, but due to #2749955: Random fails in UpdatePathTestBase tests. Will hold off on retesting until that is resolved.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

eporama’s picture

Status: Needs work » Needs review

Requeueing the test in #9 as the random failures appear to have been accounted for.

larowlan’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests

Looking good - comments follow

+++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php
@@ -166,6 +166,16 @@ public function testGetStorageClass() {
+    $entity_type->setStorageClass($controller);
+    $this->assertSame($controller, $entity_type->getHandlerClass('storage'));

You need to test what you're actually fixing.

$this->assertSame($entity_type, $entity_type->setStorageClass($controller));
eporama’s picture

Status: Needs work » Needs review
FileSize
1.16 KB
706 bytes

Right. New test does check to make sure that what we're getting back is $this.

Do we need any kind of testing that setStorageClass is actually setting a storage class? That was more what the original test was attempting, but not what this issue was fixing.

claudiu.cristea’s picture

Status: Needs review » Reviewed & tested by the community

Do we need any kind of testing that setStorageClass is actually setting a storage class?

That seems to be covered by EntityTypeTest::testGetStorageClass().

Looks good to go.

  • xjm committed 24d528d on 8.3.x
    Issue #2758559 by eporama, leolando.tan, kamalrajsahu21, tstoeckler,...
xjm’s picture

Status: Reviewed & tested by the community » Fixed

Committed 24d528d and pushed to 8.3.x. Thanks!

tstoeckler’s picture

Version: 8.3.x-dev » 8.2.x-dev
Status: Fixed » Reviewed & tested by the community

Thanks all, great to see this fixed!

I hadn't noticed this has been auto-moved to 8.3.x but as a bug fix, this should go into 8.2.x as well, so re-opening for that.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: 2758559-15.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Reviewed & tested by the community

Sent for a test run on 8.2.x now (and accidentally retested on 8.3.x, oops...)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: 2758559-15.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Reviewed & tested by the community
xjm’s picture

Status: Reviewed & tested by the community » Fixed

Well, this changes the return value of the implementation (to match the interface), so it does have the teeniest bit of potential disruption.

However, it's very theoretical and unlikely that something could possibly rely on this implementation returning NULL, so I think it is fine to backport while we are still in beta. (I would not during RC or in a patch release, since EntityType is an important base class.)

Thanks @tstoeckler!

  • xjm committed 3d26d39 on 8.2.x
    Issue #2758559 by eporama, leolando.tan, kamalrajsahu21, tstoeckler,...

Status: Fixed » Closed (fixed)

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

rangana’s picture