1

Perhaps need to enable a PHP extension to do this works. All tests with assertEquals are falling when using usort in array's.

Take a look below in the result of a falling test:

13) Piwik\Tests\Unit\DataAccess\JoinGeneratorTest::test_sortTablesForJoin_shouldSortTablesWithCustomJoinRequiringEachOther2
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
    0 => 'log_link_visit_action'
    1 => Array (
        'table' => 'log_action'
-        'tableAlias' => 'log_action_idaction_event_action'
-        'joinOn' => 'log_link_visit_action.idaction_event_action = log_action_idaction_event_action.idaction'
+        'tableAlias' => 'log_action_visit_entry_idaction_name'
+        'joinOn' => 'log_visit.visit_entry_idaction_name = log_action_visit_entry_idaction_name.idaction'
    )
    2 => Array (
        'table' => 'log_action'
-        'tableAlias' => 'log_action_visit_entry_idaction_name'
-        'joinOn' => 'log_visit.visit_entry_idaction_name = log_action_visit_entry_idaction_name.idaction'
+        'tableAlias' => 'log_action_idaction_event_action'
+        'joinOn' => 'log_link_visit_action.idaction_event_action = log_action_idaction_event_action.idaction'
    )
)

/matomo-3.5.1/tests/PHPUnit/Unit/DataAccess/LogQueryBuilder/JoinGeneratorTest.php:428

FAILURES!
Tests: 6521, Assertions: 10544, Failures: 13.
Aram Grigoryan
  • 740
  • 1
  • 6
  • 24
Bruno Wego
  • 2,099
  • 3
  • 21
  • 38

2 Answers2

1

Perhaps you should try assertSame for arrays that is much beter

Aram Grigoryan
  • 740
  • 1
  • 6
  • 24
1

The sort order must be identical on arrays for assertEquals and assertSame to pass. Imagine if you json_encode both whether or not they will end up with the same result. Looks like your arrays are not in the same sort order based on the phpunit output.

<?php

class ArrayTest extends PHPUnit\Framework\TestCase {

    // Fails
    public function testArraysEqualsDifferentOrder() {
        $a = Array(['3', '2'], '1');
        $b = Array(['2', '3'], '1');

        $this->assertEquals($a, $b);
    }

    // Fails
    public function testArraysSameDifferentOrder() {
        $a = Array(['3', '2'], '1');
        $b = Array(['2', '3'], '1');

        $this->assertSame($a, $b);
    }

    // Passes
    public function testArraysEqualSameOrder() {
        $a = Array(['2', '3'], '1');
        $b = Array(['2', '3'], '1');

        $this->assertEquals($a, $b);
    }

    // Passes
    public function testArraysSameSameOrder() {
        $a = Array(['2', '3'], '1');
        $b = Array(['2', '3'], '1');

        $this->assertSame($a, $b);
    }
}
Josh Woodcock
  • 2,683
  • 1
  • 22
  • 29