Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fago’s picture

Component: user system » entity system
fago’s picture

Issue tags: +Entity system, +sprint
Berdir’s picture

Related #1553244: Incorrect method calls in exception handling code in EntityDatabaseStorageController

Change looks good, having a test that triggers an exception would be useful I think, as described in the other issue.

fago’s picture

Status: Needs review » Needs work
Issue tags: +Needs work

Agreed. Let's do that.

chia’s picture

Little tests to see if exceptions are working okay, may be we can improve the messages,

fago’s picture

Status: Needs work » Needs review
fago’s picture

Status: Needs review » Needs work
+++ b/core/modules/entity/lib/Drupal/entity/Tests/EntityExceptionTest.php
@@ -0,0 +1,82 @@
+    $user1 = $this->drupalCreateUser();
+    ¶
+    variable_del('entity_exception_test_throw_exception');
+    $entity = entity_create('entity_test', array('name' => 'test', 'uid' => $user1->uid));

You got some whitespaces.. ;)

+++ b/core/modules/entity/lib/Drupal/entity/Tests/EntityExceptionTest.php
@@ -0,0 +1,82 @@
+      // create a test entity

Always start with an uppercase later and end with a dot. Also maybe move the comment before entity_create().

+++ b/core/modules/entity/lib/Drupal/entity/Tests/EntityExceptionTest.php
@@ -0,0 +1,82 @@
+      ¶
+    } catch(EntityStorageException $e) {

catch should be at a new line.

chia’s picture

Assigned: Unassigned » chia
Status: Needs work » Needs review
FileSize
5.69 KB

Another patch with better naming and fixed the above mentioned issues ;)

Berdir’s picture

Issue tags: -Entity system, -Needs work, -sprint
Berdir’s picture

Status: Needs review » Needs work
Issue tags: +Entity system, +Needs work, +sprint

The last submitted patch, entity-storage-exception-testing-1634442.patch, failed testing.

Berdir’s picture

Re-rolled, cleaned up the tests a bit and a tests-only patch to make sure that this works. I hope this doesn't blow up the bot due to another missing use there, see #1759026: Testing broken: Exception is never caught. It will certainly conflict with it since it adds a fix for this as well.

webchick’s picture

Status: Needs review » Needs work

I committed the referenced issue, so this will need a re-roll.

Berdir’s picture

Status: Needs work » Needs review
FileSize
5.28 KB

Re-roll.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs work
FileSize
4.82 KB

Updated the test to be a EntityUnitTest and cleaned up the patch a litte. I think this is good to go now.

catch’s picture

Status: Reviewed & tested by the community » Needs work

The test uses state but everything runs in one request.

Couldn't we set $entity->throw_exception to TRUE directly - would save the hook_node_presave() and the db hits/state dependency in the test.

amateescu’s picture

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

Discussed in IRC and decided to drop the $entity->throw_exception stuff because the storage controller doesn't have a way to know about it, and just use $GLOBALS instead of the state system, which makes perfect sense.

Berdir’s picture

Hm :)

We're in a DUBT test, so state() (or actually, it should use Drupal::state() within the hooks as well) uses the memory backend. Using it seems cleaner to me than $GLOBALS and is essentially the same. I've written other tests before that rely on state for DUBT tests, see for example \Drupal\system\Tests\DrupalKernel\ServiceDestructionTest.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

I'm not fussed if we use globals or state... I like I prefer globals because it is one less dependency.

Committed ce7ff5c and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

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