Skip to content

Instantly share code, notes, and snippets.

@Padam87
Last active August 29, 2015 13:56
Show Gist options
  • Save Padam87/8890950 to your computer and use it in GitHub Desktop.
Save Padam87/8890950 to your computer and use it in GitHub Desktop.
Symfony2 bundle functional test suite with Doctrine
<?php
// Tests/App/app/AppKernel.php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
return array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
// Add dependent bundles
new My\TestedBundle\MyTestedBundle(),
);
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}
/**
* @return string
*/
public function getCacheDir()
{
return sys_get_temp_dir() . '/MyTestedBundle/cache';
}
/**
* @return string
*/
public function getLogDir()
{
return sys_get_temp_dir() . '/MyTestedBundle/logs';
}
}
# Tests/App/app/config.yml
framework:
secret: asd
router: { resource: "%kernel.root_dir%/config/routing.yml" }
form: true
csrf_protection: true
session: ~
default_locale: en
translator: { fallback: en }
profiler: { only_exceptions: false }
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_sqlite
memory: true
orm:
auto_generate_proxy_classes: true
entity_managers:
default:
mappings:
MyTestedBundleTest:
type: annotation
prefix: My\TestedBundle\Tests\Models
dir: "%kernel.root_dir%/../../Models/"
is_bundle: false
# Tests/App/app/config_test.yml
imports:
- { resource: config.yml }
framework:
test: ~
session:
storage_id: session.storage.filesystem
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./Tests/bootstrap.php" colors="true">
<php>
<server name="KERNEL_DIR" value="./Tests/App/app" />
</php>
<testsuites>
<testsuite name="MyTestedBundle">
<directory suffix="Test.php">./Tests</directory>
</testsuite>
</testsuites>
</phpunit>
<?php
// Tests/Functional/SomeFunctionalTest.php
namespace My\TestedBundle\Test\Functional;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class SomeFunctionalTest extends WebTestCase
{
public function setUp()
{
self::createClient();
}
public function testSomething()
{
// ...
$service = self::$kernel->getContainer()->get('service');
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment