Comments

alexpott’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
benjy’s picture

I had a go at unit testing runQuery() before and gave up. There is a lot going on in SqlBase::runQuery() and it would mean mocking quite a few things.

Could we get away with just testing mapJoinable(), that would probably be easier?

benjy’s picture

Status: Needs work » Needs review
StatusFileSize
new4.93 KB
new4.11 KB

Added a unit test for mapJoinable(). Unit tests sure get complicated quick when you have a bit of mocking going on.

Status: Needs review » Needs work

The last submitted patch, 3: 2181775-3.patch, failed testing.

benjy’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new4.99 KB
new440 bytes

Doh!

benjy’s picture

Title: Fix up doc in SqlBase mapJoinable() » Fix up doc in SqlBase mapJoinable() and add test coverage
ultimike’s picture

Everything looks good - just a minor comment and a question.

Thanks,
-mike

  1. +++ b/core/modules/migrate/tests/src/Unit/SqlBaseTest.php
    @@ -0,0 +1,153 @@
    +
    

    Minor - extra linefeed.

  2. +++ b/core/modules/migrate/tests/src/Unit/SqlBaseTest.php
    @@ -0,0 +1,153 @@
    +    $this->assertEquals($sql_base->mapJoinable(), TRUE);
    

    I'm not sure I understand why this assertion fails the first time and works the second time...

benjy’s picture

StatusFileSize
new11.42 KB
new588 bytes

1. Removed the white space.

2. Yes, that is a little bit of PHPUnit black magic. As you can see here, $this->at(0), $this->at(1) has different values, which means a different value is returned from the method the second time it is called.

+++ b/core/modules/migrate/tests/src/Unit/SqlBaseTest.php
@@ -0,0 +1,153 @@
+    $idmap_connection->expects($this->at(0))
+      ->method('getConnectionOptions')
+      ->willReturn(['username' => 'different_from_source', 'password' => 'different_from_source']);
+    $idmap_connection->expects($this->at(1))
+      ->method('getConnectionOptions')
+      ->willReturn(['username' => 'same_value', 'password' => 'same_value']);
benjy’s picture

StatusFileSize
new4.99 KB
new588 bytes

Path in #8 seemed to have a few extra things so new patch attached.

benjy’s picture

StatusFileSize
new5.67 KB
new4.68 KB

@chx wasn't so happy with the readability of the test so i've refactored the creation of the TestSqlBase into another method and added parameters to define how that is setup rather than relaying on ->at(0), ->at(1) etc.

benjy’s picture

StatusFileSize
new5.85 KB
new1.88 KB

Discussed on IRC, made number of calls more specific.

chx’s picture

Status: Needs review » Reviewed & tested by the community

Let's do this.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/migrate/tests/src/Unit/SqlBaseTest.php
    @@ -0,0 +1,170 @@
    +class SqlBaseTest extends MigrateTestCase {
    

    Why is this not just extending UnitTestCase - I can't see why it needs MigrateTestCase

  2. +++ b/core/modules/migrate/tests/src/Unit/SqlBaseTest.php
    @@ -0,0 +1,170 @@
    +  /**
    ...
    +  public function testMapJoinable() {
    +
    +    // Source ids are empty so mapJoinable() is false.
    +    $sql_base = $this->getSqlBase(FALSE, FALSE);
    +    $this->assertEquals($sql_base->mapJoinable(), FALSE);
    +
    +    // Still false because getIdMap() is not a subclass of Sql.
    +    $sql_base = $this->getSqlBase(FALSE, TRUE);
    +    $this->assertEquals($sql_base->mapJoinable(), FALSE);
    +
    +    // Test mapJoinable() returns false when source and id connection options
    +    // differ.
    +    $sql_base = $this->getSqlBase(TRUE, TRUE, ['username' => 'different_from_map', 'password' => 'different_from_map'], ['username' => 'different_from_source', 'password' => 'different_from_source']);
    +    $this->assertEquals($sql_base->mapJoinable(), FALSE);
    +
    +    // Returns true because source and id map connection options are the same.
    +    $options = ['username' => 'same_value', 'password' => 'same_value'];
    +    $sql_base = $this->getSqlBase(TRUE, TRUE, $options, $options);
    +    $this->assertEquals($sql_base->mapJoinable(), TRUE);
    +  }
    

    This could be a dataprovider to getSqlBase - which would need to be changed to a test and have an assertion.

benjy’s picture

Status: Needs work » Needs review
StatusFileSize
new5.76 KB
new3.16 KB
chx’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new2.99 KB
new5.77 KB

That's really great, let me resurrect the comments however, those were useful. Did very minor cleanup as well.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: 2289555_15.patch, failed testing.

Status: Needs work » Needs review

benjy queued 15: 2289555_15.patch for re-testing.

benjy’s picture

Status: Needs review » Reviewed & tested by the community

Fails were unrelated.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: 2289555_15.patch, failed testing.

chx’s picture

Status: Needs work » Reviewed & tested by the community

Back to where it belongs...

webchick’s picture

Assigned: Unassigned » alexpott

Looks like Alex was looking into this one.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: 2289555_15.patch, failed testing.

Status: Needs work » Needs review

daffie queued 15: 2289555_15.patch for re-testing.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

And again back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Migrate changes are unfrozen as part of beta evaluation. Committed ca51249 and pushed to 8.0.x. Thanks!

  • alexpott committed ca51249 on 8.0.x
    Issue #2289555 by benjy, chx: Fix up doc in SqlBase mapJoinable() and...

Status: Fixed » Closed (fixed)

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