perftools / xhgui

Web interface for XHProf profiling data can store data in MongoDB or PDO database
1.65k stars 341 forks source link

Chore: Update phpunit to 8.5 #457

Closed glensc closed 2 years ago

glensc commented 2 years ago

I don't understand how to fix this error:


Expectation failed for method name is "insert" when invoked 8 time(s)
Parameter count for invocation MongoCollection::insert(Array (...), Array (...)) is too low.

src/Saver/MongoSaver.php:45
tests/Saver/MongoTest.php:31

I've tried as described in docs:

luzip665 commented 2 years ago

I have no glue where is the difference in the phpunit versions, but when I use

        $test_data = array();
        foreach ($data as $a) {
            $test_data[] = array($a, ['w' => 0]);
        }

        $collection
            ->expects($this->exactly(count($data)))
            ->method('insert')
            ->withConsecutive(...$test_data);

the error is replaced by

Expectation failed for method name is "insert" when invoked 8 time(s)
Parameter 0 for invocation #0 MongoCollection::insert(Array (...), Array (...)) does not match expected value.
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    '_id' => 'aaaaaaaaaaaaaaaaaaaaaaaa'
+    '_id' => MongoId Object (...)
     'meta' => Array (
         'url' => '/tasks?page=3'
         'simple_url' => '/tasks'
@@ @@
         'get' => Array (...)
         'env' => Array ()
         'SERVER' => Array (...)
-        'request_ts_micro' => Array (...)
+        'request_ts_micro' => MongoDate Object (...)
+        'request_ts' => MongoDate Object (...)
+        'request_date' => '2013-01-21'
     )
     'profile' => Array (...)
 )

which seems expectable to me.

The important difference in the call are the ... in withConsecutive.

May be it help.

glensc commented 2 years ago

you have omitted $this->equalTo calls to items, but I think I've tried too. I'll try again

luzip665 commented 2 years ago

As far as I see in vendor/phpunit/phpunit/src/Framework/MockObject/Rule/ConsecutiveParameters.php the constraint is set to IsEqual, when there is no constraint.

glensc commented 2 years ago

Ok, I figured it out: 9eaa7d89!

luzip665 commented 2 years ago

Just for interest: Would it be possible to check the insert via the MongoSearcher after insertion? For checking if the data is really inserted and not only the insert-method is called.

glensc commented 2 years ago

Just for interest: Would it be possible to check the insert via the MongoSearcher after insertion? For checking if the data is really inserted and not only the insert-method is called.

https://github.com/perftools/xhgui/pull/358