'Mocking service method still executes real method

I have testcase to run controller API call. I need to mock service method being used in the controller but its still calling real method. What am I missing here?

namespace App\Tests\Controller;

use App\Helpers\PrivateUserHelper;
use App\Tests\ApplicationTest;

class PrivateAdsControllerTest extends ApplicationTest
{

    /**
     * Test valid user's saved ads list.
     * @runInSeparateProcess
     */
    public function testValidSavedAdsList()
    {
        $this->loadValidUser();
        $client = static::createClient();
        // Start mocking
        $mockUserHelper = $this->getMockBuilder(PrivateUserHelper::class)
            ->disableOriginalConstructor()
            ->getMock();
        $mockUserHelper->expects($this->any())
            ->method('verifyAccessToken')
            ->will($this->returnValue($this->userName));
        $client->getContainer()->set('App\Helpers\PrivateUserHelper', $mockUserHelper);
        // End mocking

        $client->request(
            self::POST,
            '/list',
            [],
            [],
            $this->content,
            '{
             "AccessToken":"access token here"
             }');
        $response = json_decode($client->getResponse()->getContent(), true);
        $data = $response['body'];
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source