getMockBuilder(RecentFavoriteTable::class) ->disableOriginalConstructor() ->getMock(); $favoriteInstance->expects($this->exactly(2)) ->method('getTables') ->will($this->onConsecutiveCalls([[]], [['db' => 'db', 'table' => 'table']])); $class = new ReflectionClass(FavoriteTableController::class); $method = $class->getMethod('synchronizeFavoriteTables'); $method->setAccessible(true); $template = new Template(); $controller = new FavoriteTableController( new ResponseStub(), $template, 'db', new Relation($this->dbi, $template) ); // The user hash for test $user = 'abcdefg'; $favoriteTable = [ $user => [ [ 'db' => 'db', 'table' => 'table', ], ], ]; $json = $method->invokeArgs($controller, [$favoriteInstance, $user, $favoriteTable]); $this->assertEquals(json_encode($favoriteTable), $json['favoriteTables'] ?? ''); $this->assertArrayHasKey('list', $json); } }