matomo-org / tag-manager

Free Open Source Matomo Tag Manager - A simple way to manage and maintain all of your (third-party) tags on your website.
https://matomo.org
GNU General Public License v3.0
170 stars 58 forks source link

Add explicit order by to sql statement #843

Closed sgiehl closed 1 month ago

sgiehl commented 1 month ago

Description:

While running core tests for TiDb, we came across a failing test for TagManager:

https://github.com/matomo-org/tag-manager/blob/691169cfb2b187d19eea339a5e368f3b4810a846/tests/Integration/Dao/ContainerReleaseDaoTest.php#L470-L493

The test basically fails, as for TiDb the order of returned items is different. For MySQL the order seems automatically ordered by idsite and idcontainer, for TiDb this isn't the case.

 ✘ GetAllReleasedContainers shouldOnlyReturnActiveReleasesWithContainers [5860.38 ms]
   │
   │ Failed asserting that two arrays are equal.
   │ --- Expected
   │ +++ Actual
   │ @@ @@
   │  Array (
   │      0 => Array (
   │ -        'idsite' => '2'
   │ +        'idsite' => '3'
   │          'idcontainer' => 'A68AGI3Z'
   │      )
   │      1 => Array (
   │ -        'idsite' => '3'
   │ -        'idcontainer' => 'A68AGI3Z'
   │ +        'idsite' => '4'
   │ +        'idcontainer' => 'foobar'
   │      )
   │      2 => Array (
   │          'idsite' => '4'
   │ -        'idcontainer' => 'A68AGI3Z'
   │ +        'idcontainer' => 'abcde'
   │      )
   │      3 => Array (
   │          'idsite' => '4'
   │ -        'idcontainer' => 'abcde'
   │ +        'idcontainer' => 'A68AGI3Z'
   │      )
   │      4 => Array (
   │ -        'idsite' => '4'
   │ -        'idcontainer' => 'foobar'
   │ +        'idsite' => '2'
   │ +        'idcontainer' => 'A68AGI3Z'
   │      )
   │  )
   │
   │ /home/runner/work/matomo/matomo/matomo/plugins/TagManager/tests/Integration/Dao/ContainerReleaseDaoTest.php:491

Adding an explicit order by to the query ensures the same results across different database engines.

Review