我正在接近phpunit單元測試的100%代碼覆蓋範圍,但目前我唯一沒有涉及的是路由。我不確定如何測試它。任何人都可以協助嗎?單元測試在silex中的匿名回調路由
我使用Silex的框架做我的路由按以下方式:
$api->put('/update/{websiteName}/{endpointName}', function($websiteName, $endpointName, Request $request) use ($databaseServiceContainer, $sourceRetrievalService) {
$controller = new RequestController(
$databaseServiceContainer,
$sourceRetrievalService
);
return $controller->update(
$websiteName,
$endpointName,
$request
);
});
創建自己覆蓋的路由,而不是內部的匿名回調。
正如你可以在此圖像中看到:在https://github.com/ri0t1985/api-creator
https://stackoverflow.com/questions/17580005/silex-phpunit-functional-tests有幫助嗎? –
不,對不起。這將是一個功能測試,而不是單元測試:) – Erik
由於您在路由定義中創建了服務,因此測試它會有點困難,不是嗎? – localheinz