Skip to content

Commit

Permalink
Functional Test Base added
Browse files Browse the repository at this point in the history
  • Loading branch information
baldurrensch committed Mar 12, 2014
1 parent 8fe8c1f commit 592b1db
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<argument type="collection">
<argument key="yaml" type="service" id="hautelook_alice.loader.yaml" />
</argument>
<argument type="service" id="logger" />
<argument type="service" id="logger" on-invalid="null"/>
</service>

</services>
Expand Down
29 changes: 29 additions & 0 deletions Tests/Functional/AppKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Hautelook\AliceBundle\Tests\Functional;

use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;

class AppKernel extends Kernel
{
public function registerBundles()
{
return array(
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new \Hautelook\AliceBundle\HautelookAliceBundle(),

new \Hautelook\AliceBundle\Tests\Functional\TestBundle\TestBundle(),
);
}

public function getCacheDir()
{
return sys_get_temp_dir().'/AliceBundle/';
}

public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}
}
27 changes: 27 additions & 0 deletions Tests/Functional/Command/DoctrineFixtureTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Hautelook\AliceBundle\Tests\Functional\Command;

use Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand;
use Hautelook\AliceBundle\Tests\Functional\TestCase;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Finder\Shell\Command;

class DoctrineFixtureTest extends TestCase
{
public function testFixture()
{
$application = new Application(self::getKernel());
$application->add(new LoadDataFixturesDoctrineCommand());
$command = $application->find('doctrine:fixtures:load');
// $command = new \Symfony\Component\Console\Command\Command();

$commandTester = new CommandTester($command);
$commandTester->execute(array());

$display = $commandTester->getDisplay();

var_dump($display);
}
}
14 changes: 14 additions & 0 deletions Tests/Functional/ControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Hautelook\AliceBundle\Tests\Functional;

/**
* @group functional
*/
class ControllerTest extends TestCase
{
public function testServiceSetup()
{
$client = $this->createClient();
}
}
15 changes: 15 additions & 0 deletions Tests/Functional/TestBundle/Controller/RootController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Hautelook\AliceBundle\Tests\Functional\TestBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;

class RootController extends Controller
{
public function testAction(Request $request)
{
return new Response("TestResponse");
}
}
1 change: 1 addition & 0 deletions Tests/Functional/TestBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
services:
9 changes: 9 additions & 0 deletions Tests/Functional/TestBundle/TestBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Hautelook\AliceBundle\Tests\Functional\TestBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class TestBundle extends Bundle
{
}
44 changes: 44 additions & 0 deletions Tests/Functional/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Hautelook\AliceBundle\Tests\Functional;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Filesystem\Filesystem;

abstract class TestCase extends WebTestCase
{
protected static function createKernel(array $options = array())
{
$env = @$options['environment'] ?: 'test';

return new AppKernel($env, true);
}

protected static function initializeKernel(array $options = array())
{
if (null !== static::$kernel) {
return;
}

static::$kernel = static::createKernel($options);
static::$kernel->boot();
}

protected static function getKernel()
{
static::initializeKernel();

return static::$kernel;
}

protected function setUp()
{
$fs = new Filesystem();
$fs->remove(sys_get_temp_dir().'/AliceBundle/');
}

protected function tearDown()
{
static::$kernel = null;
}
}
10 changes: 10 additions & 0 deletions Tests/Functional/config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
imports:
- { resource: "@TestBundle/Resources/config/services.yml" }

framework:
secret: test
router:
resource: "%kernel.root_dir%/config/routing.yml"
form: ~
validation: ~
session: ~
5 changes: 5 additions & 0 deletions Tests/Functional/config/config_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
imports:
- { resource: config.yml }

framework:
test: ~
4 changes: 4 additions & 0 deletions Tests/Functional/config/routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
api_root:
pattern: /test
defaults:
_controller: TestBundle:Root:test
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
],
"require": {
"php": ">=5.3.0",
"nelmio/alice": "~1.5",
"nelmio/alice": "~1.6",
"doctrine/doctrine-fixtures-bundle": "~2.2",
"doctrine/data-fixtures": "~1.0"
"doctrine/doctrine-bundle": "~1.2"
},
"require-dev": {
"symfony/framework-bundle": "~2.1",
"symfony/console": "~2.1",
"symfony/yaml": "~2.1"
},
"autoload": {
Expand Down

0 comments on commit 592b1db

Please sign in to comment.