Page MenuHomeDevCentral

ErrorException: count(): Parameter must be an array or an object that implements Countable
Closed, ResolvedPublic

Description

Nasqueron\Notifications\Tests\Jobs\NotifyNewCommitsToDiffusionTest::testHandle with data set #2 (null, 1)
ErrorException: count(): Parameter must be an array or an object that implements Countable

/usr/home/dereckson/dev/nasqueron/notifications/repo/app/Jobs/NotifyNewCommitsToDiffusion.php:182
/usr/home/dereckson/dev/nasqueron/notifications/repo/app/Jobs/NotifyNewCommitsToDiffusion.php:162
/usr/home/dereckson/dev/nasqueron/notifications/repo/app/Jobs/NotifyNewCommitsToDiffusion.php:137
/usr/home/dereckson/dev/nasqueron/notifications/repo/app/Jobs/NotifyNewCommitsToDiffusion.php:76
/usr/home/dereckson/dev/nasqueron/notifications/repo/tests/Jobs/NotifyNewCommitsToDiffusionTest.php:32

Test
/**
 * Provides API repository reply and associated API calls count
 */
public function apiRepositoryReplyProvider () : array {
    return [
        // Regular behavior
        [[new class { public $callsign = "K2"; }], 2],

        // Phabricator doesn't know this repo
        [[], 1],

        // Some error occurs and the API reply is null
        [null, 1],
    ];
}


/**
 * @dataProvider apiRepositoryReplyProvider
 */
public function testHandle ($apiRepositoryReply, int $apiCallCounts) {
    $this->mockPhabricatorAPI()
        ->shouldReceive('getForProject->call')
        ->andReturn(
            // First API call: repository.query
            $apiRepositoryReply,

            // Second API call: diffusion.looksoon
            null
        )
        ->times($apiCallCounts); // 2 when repository.query is valid
                                 // 1 otherwise

    $job = $this->mockJob();
    $job->handle();
}