Skip to content

Instantly share code, notes, and snippets.

@Maff-
Created December 5, 2015 22:44
Show Gist options
  • Save Maff-/c9d2c1592a746da85d5b to your computer and use it in GitHub Desktop.
Save Maff-/c9d2c1592a746da85d5b to your computer and use it in GitHub Desktop.
Symfony2 Service Availability Smoke Test
<?php
namespace AppBundle\Tests;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class ServiceAvailabilityFunctionalTest extends KernelTestCase
{
protected $serviceBlacklist = [
'request',
'form.csrf_provider',
'security.context',
'security.secure_random',
];
/**
* @dataProvider serviceIdProvider
* @param string $serviceId
*/
public function testServiceCreationIsSuccessful($serviceId)
{
static::bootKernel();
static::$kernel->getContainer()->get($serviceId);
}
public function serviceIdProvider()
{
static::bootKernel();
/** @var \Symfony\Component\DependencyInjection\Container $container */
$container = static::$kernel->getContainer();
$serviceIds = $container->getServiceIds();
$serviceIds = array_diff($serviceIds, $this->serviceBlacklist);
return array_chunk($serviceIds, 1);
}
}
@soullivaneuh
Copy link

Any way to simulate request scope to test related services and get rid of this error?

4) Tests\ServiceAvailabilityTest::testServiceInstance with data set #382 ('lexik_paybox.response_handler')
Symfony\Component\DependencyInjection\Exception\InactiveScopeException: You cannot create a service ("request") of an inactive scope ("request").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment