hjortur17
4 months ago

Help with test

Posted 4 months ago by hjortur17

Hi, I can't get this to work.

/** @test */
    public function a_user_can_filter_threads_by_popularity()
    {
        $threadWithTwoReplies = create('App\Thread');
        create('App\Reply', ['thread_id' => $threadWithTwoReplies->id], 2);
        
        $threadWithThreeReplies = create('App\Thread');
        create('App\Reply', ['thread_id' => $threadWithThreeReplies->id], 3);
        
        $threadWithNoReplies = $this->thread;
        
        $response = $this->getJson('fréttir?vinsælt=1')->json();
        
        $this->assertEquals([3, 2, 0], array_column($response['data'], 'replies_count'));
    }

This is what the terminal says:

➜  project git:(master) ✗ pf ReadThreadsTest
PHPUnit 7.5.11 by Sebastian Bergmann and contributors.

...F..                                                              6 / 6 (100%)

Time: 424 ms, Memory: 28.00 MB

There was 1 failure:

1) Tests\Feature\ReadThreadsTest::a_user_can_filter_threads_by_popularity
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    0 => 3
-    1 => 2
-    2 => 0
+    0 => '0'
+    1 => '2'
+    2 => '3'
 )

/Users/hjorturfreyrlarusson/websites/project/tests/Feature/ReadThreadsTest.php:63
/Users/hjorturfreyrlarusson/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:208
/Users/hjorturfreyrlarusson/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:164

FAILURES!
Tests: 6, Assertions: 10, Failures: 1.

Please sign in or create an account to participate in this conversation.