Closed (fixed)
Project:
Drupal core
Version:
8.6.x-dev
Component:
database system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
15 Mar 2018 at 17:55 UTC
Updated:
27 Apr 2018 at 11:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
mondrakePatch.
Comment #3
berdirconfused why this isn't using $this->connection now ;)
Comment #4
mondrake#3
addSampleData()is a static ... so unless we change it to non-static,$thiswill not be in scope :)Did not want to change it, but apparently this is not used anywhere else. It could also be a protected, actually.
Comment #5
mondrake#3, #4,
actually no:
it's more complicated, we cannot change easily to non-static.
Comment #6
volegerit is possible to use
$this->container->get('database');here?
Comment #7
mondrake#6: the database connection code in the
KernelTestBaseclass thatDatabaseTestBaseextends from uses direct calls to theDatabasemethods rather than going through the service container. That's the reason I was going for it too.Comment #8
voleger#7 ok
So maybe it would be better to store connection instance in a single static property?
Comment #9
mondrake@voleger re #8 why do you think it would be better? I cannot say the full consequences of that, but
a) the
::setUpmethod will anyway reset it for every test, which I am afraid may cause issues in running multiple tests in parallelb) it will not solve #3 / #4 because
Drupal\system\Tests\Database\DatabaseWebTestBaseandDrupal\Tests\system\Functional\Database\DatabaseTestBaseare not extending fromDrupal\KernelTests\Core\Database\DatabaseTestBase, so the property will not be initialisedComment #10
volegerfor now, it's ok for me.
+1 for RTBC
I'm waiting this issue to unblock #2939387: Replace all calls to db_query [core/test/../Database]
Comment #11
joshmillerComment #12
alexpottCommitted and pushed 872ddb8101 to 8.6.x and bdfce71e7c to 8.5.x. Thanks!
Backported to 8.5.x as this is a test only change.