[Gravity] Made a SQLite3QueryResult class and some classes to support it

Review Request #414 — Created Feb. 9, 2016 and submitted

rubendgr
Lunr
rubendgr:sqlite_result
lunr

Implementation of the SQLite3QueryResult class and tests to support it.

Unit test.

  • 0
  • 0
  • 23
  • 0
  • 23
Description From Last Updated
tardypad
  1. It feels like many unit tests are missing if you compare with the way the MySQLResult class is tested

  2. src/Lunr/Gravity/Database/SQLite3/SQLite3QueryResult.php (Diff revision 1)
     
     
     
     
     
     

    no need for this if not used

  3. to be removed as well

  4. src/Lunr/Gravity/Database/SQLite3/SQLite3QueryResult.php (Diff revision 1)
     
     
     
     
     
     
     
     
     
     

    I guess you still need to return something that "makes sense".
    Any code can call this function and should know what to do with the result. Here there is nothing.
    Maybe the comment of the interface function should be updated as well to explain the behavior

    1. I deleted the number_of_rows from the DatabaseQueryResultInterface. Now SQLite3QueryResult is not forced to use this method anymore.

  5. This is not how mocks are supposed to be created.
    You either use the mock builder for PHPUnit to automatically create a mock of the class you want.
    Or you define manually a mock class yourself if really needed (this happens rarely)
    Here you seem to mix things

    1. Not making a mock of a mock anymore.

  6. 
      
rubendgr
smillernl
  1. 
      
  2. This could be even shorter by just returning the boolean result.

    return ($this->error_number == self::DEADLOCK_ERR_CODE);
    
    1. I kept it for being consistent with other code.

  3. The newer php array syntax is prefered.

    [] over array()

  4. This is not needed if you call the set up method setUp() in SQLite3QueryResultTest

    1. I kept it because I have three versions of the setUp.

  5. The LunrBaseTest class has a function for this:

    get_accessible_reflection_property($property)

    And in this case you could even use the assertPropertySame($property, $expected) function.

    1. Using this method now.

  6. LunrBaseTests set_reflection_property_value is an easy replacement for this.

    1. Using this method now.

  7. assertEquals tests only the value of the parameters while assertSame tests the type as well. Saves you some lines.

    1. Changed assertInternalType and assertEquals to assertSame. With arrays this was not working.

  8. this needs to be setUp() or it wont be run :(

    1. Changed to setUp when needed.

  9. 
      
rubendgr
rubendgr
rubendgr
rubendgr
rubendgr
tardypad
  1. The rest looks fine

  2. this can't be removed like that
    some projects most likely already use it

    1. Put number_of_rows back in the interface. Now the method is returning -1 instead of the number of rows.

  3. tests/phpunit.xml (Diff revision 5)
     
     

    If this was missing before, don't make it part of this review but create another one
    This is confusing if you mix different unrelated things in a same review

    1. Yes, this was a fix for MySQL.

  4. 
      
rubendgr
tardypad
  1. Ship It!
  2. 
      
pprkut
  1. 
      
  2. This does not mean what you think it means. A query might have rows, but it's just string formatting depending on where in the query I set a line-break, and even that only when I type it manually ;)
    The query we generate only has one row.

    1. I changed it to the number of rows in the result set.

  3. src/Lunr/Gravity/Database/SQLite3/SQLite3QueryResult.php (Diff revision 6)
     
     
     
     
     
     
     
     
     
     
     

    what about SQLiteResult->numRows()?

    1. Ok, so that is for sqlite2, not 3. But still, -1 is not really an appropriate reply. We know the row count, we just have to work a bit harder to get it.

    2. /
      * Returns the number of rows in the result set.

      * @return Integer $number Number of rows in the result set.
      /
      public function number_of_rows()
      {
      $count = 0;

          while ($this->result->fetchArray(SQLITE3_ASSOC))
          {
              $count++;
          }
      
          $this->free_result();
      
          return $count;
      }
      

      Is this a good solution ?

    3. almost. You want to somehow interact with the result() functions, since otherwise you either can only check row count or fetch results, or fetch results twice. Neither is what we want.

    4. /
      * Returns the number of rows in the query.

      * @return Integer $number Number of rows in the result set.
      /
      public function number_of_rows()
      {
      $count = 0;

          while ($this->result->fetchArray(SQLITE3_ASSOC))
          {
              $count++;
          }
      
          return $count;
      }
      
      I removed the free_result() function. Is the code ready to ship ?
      
  4. pls use [] instead of array()

  5. 
      
smillernl
  1. Make sure you check the other files for the comment changes as well. Didn't mark all of them.

  2. This is not in tests though (no big deal but i'm nitpicking anyways)

  3. Usually has email address (yay, nitpicking)

  4. No need for ? TRUE : FALSE

    ($this->error_number == self::DEADLOCK_ERR_CODE) will already return a boolean.

  5. We don't generally define the Tests part of the namespace in the package. (again no big deal)

  6. Many of the functions here are missing an @covers annotation.

  7. See previous comments

  8. See previous comments

  9. 
      
rubendgr
rubendgr
pprkut
  1. There are no tests for the number_of_rows() method.

  2. 
      
rubendgr
pprkut
  1. Ship It!
  2. 
      
rubendgr
Review request changed

Status: Closed (submitted)

Change Summary:

Merged into master

Loading...