1. Go to this page and download the library: Download shopsys/http-smoke-testing library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
shopsys / http-smoke-testing example snippets
namespace Tests\AppBundle\Smoke;
use Shopsys\HttpSmokeTesting\Auth\BasicHttpAuth;
use Shopsys\HttpSmokeTesting\HttpSmokeTestCase;
use Shopsys\HttpSmokeTesting\RouteConfig;
use Shopsys\HttpSmokeTesting\RouteConfigCustomizer;
use Shopsys\HttpSmokeTesting\RouteInfo;
use Symfony\Component\HttpFoundation\Request;
class SmokeTest extends HttpSmokeTestCase {
/**
* @param \Shopsys\HttpSmokeTesting\RouteConfigCustomizer $routeConfigCustomizer
*/
protected function customizeRouteConfigs(RouteConfigCustomizer $routeConfigCustomizer)
{
$routeConfigCustomizer
->customize(function (RouteConfig $config, RouteInfo $info) {
// This function will be called on every RouteConfig provided by RouterAdapter
if ($info->getRouteName()[0] === '_') {
// You can use RouteConfig to change expected behavior or skip testing particular routes
$config->skipRoute('Route name is prefixed with "_" meaning internal route.');
}
})
->customizeByRouteName('acme_demo_secured_hello', function (RouteConfig $config, RouteInfo $info) {
// You can customize RouteConfig to use authentication for secured routes
$config->changeDefaultRequestDataSet('Log in as "user".')
->setAuth(new BasicHttpAuth('user', 'userpass'));
});
}
/**
* @param \Symfony\Component\HttpFoundation\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function handleRequest(Request $request)
{
$entityManager = self::$kernel->getContainer()->get('doctrine.orm.entity_manager');
// Enclose request handling in rolled-back database transaction to prevent side-effects
$entityManager->beginTransaction();
$response = parent::handleRequest($request);
$entityManager->rollback();
return $response;
}
}