Write PHPUnit tests for Comment source plugin

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eliza411’s picture

Title: Write PHPUnit tests for Comment source plugin » Write PHPUnit tests for 6.x Comment source plugin
marvil07’s picture

I'm a little confused about how to write a d6 comment source plugin test, since in order to really test it we will need a database to query to see if query goes ok(assuming the new definition of source).
A mock of this piece will end up in a test which does not really test anything.
So, if we include a d6 dump, then we could see if the expected values are returned since we have a value to compare with on the dump, is that the original plan?

chx’s picture

I was planning to mock DBTNG. Why that wouldn't test anything?

marvil07’s picture

Assigned: Unassigned » marvil07

makes sense, will try to star on this.

marvil07’s picture

Status: Active » Needs review
FileSize
4.27 KB

A poor initial patch.
It seems not that straightforward to mock dbtng. In the other side IIRC phpunit tests could not access database, which sounds fine since we are using the configured database directly, but I am not sure if I am assuming correctly.

Some questions:

  • Where SqlBase::query() method on the source is executed? (I could not find one place)
  • What exactly to test, i.e. only methods on MigrateSourceInterface?
alexweber’s picture

Have you had a chance to follow up on this? I have similar questions :)

EDIT: So I managed to get a CacheBackendInterface object by doing the following:

$this->cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface');

I found this in Drupal\locale\Tests\LocaleTranslationTest.php :)

marvil07’s picture

Assigned: marvil07 » Unassigned
Status: Needs review » Fixed

I see in the repository that this test is running, chx++

eliza411’s picture

Status: Fixed » Closed (fixed)

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