Last active
August 29, 2015 13:56
-
-
Save Padam87/8890950 to your computer and use it in GitHub Desktop.
Symfony2 bundle functional test suite with Doctrine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Tests/App/app/config_test.yml | |
imports: | |
- { resource: config.yml } | |
framework: | |
test: ~ | |
session: | |
storage_id: session.storage.filesystem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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