Skip to content

Instantly share code, notes, and snippets.

@pschultz
Forked from meddulla/config_test.yml
Created November 27, 2012 08:02

Revisions

  1. pschultz revised this gist Nov 27, 2012. 3 changed files with 61 additions and 65 deletions.
    59 changes: 59 additions & 0 deletions bootstrap.phpunit.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    <?php
    // in /app/bootstrap.phpunit.php:

    require_once __DIR__.'/bootstrap.php.cache';
    require_once __DIR__.'/AppKernel.php';

    use Symfony\Component\Console\Command\Command;
    use Symfony\Component\Console\Input\ArrayInput;
    use Symfony\Component\Console\Output\ConsoleOutput;

    use Symfony\Bundle\FrameworkBundle\Console\Application;
    use Symfony\Bundle\FrameworkBundle\Command\CacheWarmupCommand;

    use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand;
    use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand;
    use Doctrine\Bundle\DoctrineBundle\Command\Proxy\CreateSchemaDoctrineCommand;
    use Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand;

    $environment = getenv('SF2_TEST_ENV') ?: 'test';
    $kernel = new AppKernel($environment, true);
    $kernel->boot();

    $application = new Application($kernel);

    $runCommand = function (Command $command, array $args) use ($application) {
    $application->add($command);

    $input = new ArrayInput($args);
    $input->setInteractive(false);

    $command->run($input, new ConsoleOutput());
    };

    $runCommand(new DropDatabaseDoctrineCommand, [
    'command' => 'doctrine:database:drop',
    '--force' => true,
    ]);

    $runCommand(new CreateDatabaseDoctrineCommand, [
    'command' => 'doctrine:database:create',
    ]);

    $runCommand(new CreateSchemaDoctrineCommand, [
    'command' => 'doctrine:schema:create',
    ]);

    try {
    $runCommand(new LoadDataFixturesDoctrineCommand, [
    'command' => 'doctrine:fixtures:load',
    '--env' => $environment
    ]);
    } catch (InvalidArgumentException $ignored) {
    // thrown when there are no fixtures to load
    }

    $runCommand(new CacheWarmupCommand, [
    'command' => 'cache:warmup',
    '--env' => $environment
    ]);
    63 changes: 0 additions & 63 deletions my_phpunit_bootstrap.php
    Original file line number Diff line number Diff line change
    @@ -1,63 +0,0 @@
    <?php

    // in /app/my_phpunit_bootstrap.php:
    require_once __DIR__.'/bootstrap.php.cache';
    require_once __DIR__.'/AppKernel.php';

    use Symfony\Bundle\FrameworkBundle\Console\Application;
    use Symfony\Component\Console\Output\ConsoleOutput;
    use Symfony\Component\Console\Input\ArrayInput;

    use Symfony\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand;
    use Symfony\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand;
    use Symfony\Bundle\DoctrineBundle\Command\Proxy\CreateSchemaDoctrineCommand;
    use Symfony\Bundle\DoctrineFixturesBundle\Command\LoadDataFixturesDoctrineCommand;
    use Symfony\Bundle\FrameworkBundle\Command\CacheWarmupCommand;

    $kernel = new AppKernel('test', true); // create a "test" kernel
    $kernel->boot();

    $application = new Application($kernel);

    // add the database:drop command to the application and run it
    $command = new DropDatabaseDoctrineCommand();
    $application->add($command);
    $input = new ArrayInput(array(
    'command' => 'doctrine:database:drop',
    '--force' => true,
    ));
    $command->run($input, new ConsoleOutput());

    // add the database:create command to the application and run it
    $command = new CreateDatabaseDoctrineCommand();
    $application->add($command);
    $input = new ArrayInput(array(
    'command' => 'doctrine:database:create',
    ));
    $command->run($input, new ConsoleOutput());

    // let Doctrine create the database schema (i.e. the tables)
    $command = new CreateSchemaDoctrineCommand();
    $application->add($command);
    $input = new ArrayInput(array(
    'command' => 'doctrine:schema:create',
    ));
    $command->run($input, new ConsoleOutput());

    //load fixtures
    $command = new LoadDataFixturesDoctrineCommand();
    $application->add($command);
    $input = new ArrayInput(array(
    'command' => 'doctrine:fixtures:load',
    '--env' => 'test'
    ));
    $command->run($input, new ConsoleOutput());

    //warmup cache
    $command = new CacheWarmupCommand();
    $application->add($command);
    $input = new ArrayInput(array(
    'command' => 'cache:warmup',
    '--env' => 'test'
    ));
    $command->run($input, new ConsoleOutput());
    4 changes: 2 additions & 2 deletions phpunit.xml
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    processIsolation = "false"
    stopOnFailure = "false"
    syntaxCheck = "false"
    bootstrap = "my_phpunit_bootstrap.php" >
    bootstrap = "bootstrap.phpunit.php" >

    <testsuites>
    <testsuite name="Project Test Suite">
    @@ -32,4 +32,4 @@
    </whitelist>
    </filter>

    </phpunit>
    </phpunit>
  2. @meddulla meddulla revised this gist Feb 3, 2012. 1 changed file with 0 additions and 7 deletions.
    7 changes: 0 additions & 7 deletions config_test.yml
    Original file line number Diff line number Diff line change
    @@ -6,13 +6,6 @@ framework:
    session:
    storage_id: session.storage.filesystem

    web_profiler:
    toolbar: false
    intercept_redirects: false

    swiftmailer:
    disable_delivery: true

    doctrine:
    dbal:
    default_connection: default
  3. @meddulla meddulla created this gist Feb 3, 2012.
    22 changes: 22 additions & 0 deletions config_test.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    imports:
    - { resource: config_dev.yml }

    framework:
    test: ~
    session:
    storage_id: session.storage.filesystem

    web_profiler:
    toolbar: false
    intercept_redirects: false

    swiftmailer:
    disable_delivery: true

    doctrine:
    dbal:
    default_connection: default
    connections:
    default:
    driver: pdo_sqlite
    path: %kernel.cache_dir%/test.db
    63 changes: 63 additions & 0 deletions my_phpunit_bootstrap.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    <?php

    // in /app/my_phpunit_bootstrap.php:
    require_once __DIR__.'/bootstrap.php.cache';
    require_once __DIR__.'/AppKernel.php';

    use Symfony\Bundle\FrameworkBundle\Console\Application;
    use Symfony\Component\Console\Output\ConsoleOutput;
    use Symfony\Component\Console\Input\ArrayInput;

    use Symfony\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand;
    use Symfony\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand;
    use Symfony\Bundle\DoctrineBundle\Command\Proxy\CreateSchemaDoctrineCommand;
    use Symfony\Bundle\DoctrineFixturesBundle\Command\LoadDataFixturesDoctrineCommand;
    use Symfony\Bundle\FrameworkBundle\Command\CacheWarmupCommand;

    $kernel = new AppKernel('test', true); // create a "test" kernel
    $kernel->boot();

    $application = new Application($kernel);

    // add the database:drop command to the application and run it
    $command = new DropDatabaseDoctrineCommand();
    $application->add($command);
    $input = new ArrayInput(array(
    'command' => 'doctrine:database:drop',
    '--force' => true,
    ));
    $command->run($input, new ConsoleOutput());

    // add the database:create command to the application and run it
    $command = new CreateDatabaseDoctrineCommand();
    $application->add($command);
    $input = new ArrayInput(array(
    'command' => 'doctrine:database:create',
    ));
    $command->run($input, new ConsoleOutput());

    // let Doctrine create the database schema (i.e. the tables)
    $command = new CreateSchemaDoctrineCommand();
    $application->add($command);
    $input = new ArrayInput(array(
    'command' => 'doctrine:schema:create',
    ));
    $command->run($input, new ConsoleOutput());

    //load fixtures
    $command = new LoadDataFixturesDoctrineCommand();
    $application->add($command);
    $input = new ArrayInput(array(
    'command' => 'doctrine:fixtures:load',
    '--env' => 'test'
    ));
    $command->run($input, new ConsoleOutput());

    //warmup cache
    $command = new CacheWarmupCommand();
    $application->add($command);
    $input = new ArrayInput(array(
    'command' => 'cache:warmup',
    '--env' => 'test'
    ));
    $command->run($input, new ConsoleOutput());
    35 changes: 35 additions & 0 deletions phpunit.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    <?xml version="1.0" encoding="UTF-8"?>

    <!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
    <phpunit
    backupGlobals = "false"
    backupStaticAttributes = "false"
    colors = "true"
    convertErrorsToExceptions = "true"
    convertNoticesToExceptions = "true"
    convertWarningsToExceptions = "true"
    processIsolation = "false"
    stopOnFailure = "false"
    syntaxCheck = "false"
    bootstrap = "my_phpunit_bootstrap.php" >

    <testsuites>
    <testsuite name="Project Test Suite">
    <directory>../src/*/*Bundle/Tests</directory>
    <directory>../src/*/Bundle/*Bundle/Tests</directory>
    </testsuite>
    </testsuites>

    <filter>
    <whitelist>
    <directory>../src</directory>
    <exclude>
    <directory>../src/*/*Bundle/Resources</directory>
    <directory>../src/*/*Bundle/Tests</directory>
    <directory>../src/*/Bundle/*Bundle/Resources</directory>
    <directory>../src/*/Bundle/*Bundle/Tests</directory>
    </exclude>
    </whitelist>
    </filter>

    </phpunit>