Browse Source

Update test to only run without quoting

identifier quoting creates inconsistent results and isn't compatible
with string expressions anyways. I also tweaked how spacing was handled
in postgres and sqlserver to generate consistent results.
Mark Story 5 years ago
parent
commit
1b792a208c

+ 1 - 1
src/Database/Expression/QueryExpression.php

@@ -737,7 +737,7 @@ class QueryExpression implements ExpressionInterface, Countable
         $spaces = substr_count($field, ' ');
         if ($spaces > 1) {
             $parts = explode(' ', $field);
-            if (preg_match('/(is not|not in)$/i', $field)) {
+            if (preg_match('/(is not|not \w+)$/i', $field)) {
                 $last = array_pop($parts);
                 $second = array_pop($parts);
                 array_push($parts, strtolower("{$second} {$last}"));

+ 2 - 2
src/Database/PostgresCompiler.php

@@ -41,7 +41,7 @@ class PostgresCompiler extends QueryCompiler
     protected $_templates = [
         'delete' => 'DELETE',
         'where' => ' WHERE %s',
-        'group' => ' GROUP BY %s ',
+        'group' => ' GROUP BY %s',
         'order' => ' %s',
         'limit' => ' LIMIT %s',
         'offset' => ' OFFSET %s',
@@ -88,6 +88,6 @@ class PostgresCompiler extends QueryCompiler
             }
         }
 
-        return sprintf('HAVING %s', implode(', ', $parts));
+        return sprintf(' HAVING %s', implode(', ', $parts));
     }
 }

+ 2 - 2
src/Database/SqlserverCompiler.php

@@ -39,7 +39,7 @@ class SqlserverCompiler extends QueryCompiler
     protected $_templates = [
         'delete' => 'DELETE',
         'where' => ' WHERE %s',
-        'group' => ' GROUP BY %s ',
+        'group' => ' GROUP BY %s',
         'order' => ' %s',
         'offset' => ' OFFSET %s ROWS',
         'epilog' => ' %s',
@@ -155,6 +155,6 @@ class SqlserverCompiler extends QueryCompiler
             }
         }
 
-        return sprintf('HAVING %s', implode(', ', $parts));
+        return sprintf(' HAVING %s', implode(', ', $parts));
     }
 }

+ 6 - 7
tests/TestCase/Database/QueryTest.php

@@ -2309,7 +2309,7 @@ class QueryTest extends TestCase
      */
     public function testHavingAliasCasingStringExpression()
     {
-        $this->loadFixtures('Authors');
+        $this->skipIf($this->autoQuote, 'Does not work when autoquoting is enabled.');
         $query = new Query($this->connection);
         $query
             ->select(['id'])
@@ -2320,12 +2320,11 @@ class QueryTest extends TestCase
             ])
             ->having(['COUNT(DISTINCT Authors.id) =' => 1]);
 
-        $this->assertQuotedQuery(
-            'SELECT <id> FROM <authors> <Authors> WHERE ' .
-            '\(FUNC\( <Authors>\.<id>\) = :c0 AND \(FUNC\( <Authors>\.<id>\)\) IS NOT NULL\) ' .
-            'HAVING COUNT\(DISTINCT <Authors>\.<id>\) = :c1',
-            $query->sql(),
-            !$this->autoQuote
+        $this->assertSame(
+            'SELECT id FROM authors Authors WHERE ' .
+            '(FUNC( Authors.id) = :c0 AND (FUNC( Authors.id)) IS NOT NULL) ' .
+            'HAVING COUNT(DISTINCT Authors.id) = :c1',
+            trim($query->sql())
         );
     }