Skip to content

Commit

Permalink
Add functional tests that boot an app with the bundle.
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienbrault committed Oct 14, 2012
1 parent 09994d1 commit 92d372c
Show file tree
Hide file tree
Showing 14 changed files with 327 additions and 12 deletions.
36 changes: 36 additions & 0 deletions Tests/Functional/AppKernel.php
@@ -0,0 +1,36 @@
<?php

namespace FOS\OAuthServerBundle\Tests\Functional;

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

class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new \Symfony\Bundle\SecurityBundle\SecurityBundle(),
new \FOS\OAuthServerBundle\FOSOAuthServerBundle(),

new \FOS\OAuthServerBundle\Tests\Functional\TestBundle\TestBundle(),
);

if ('orm' == $this->getEnvironment()) {
$bundles[] = new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle();
}

return $bundles;
}

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

public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}
}
22 changes: 22 additions & 0 deletions Tests/Functional/BootTest.php
@@ -0,0 +1,22 @@
<?php

namespace FOS\OAuthServerBundle\Tests\Functional;

class BootTest extends TestCase
{
/**
* @dataProvider getTestBootData
*/
public function testBoot($env)
{
$kernel = $this->createKernel(array('env' => $env));
$kernel->boot();
}

public function getTestBootData()
{
return array(
array('orm'),
);
}
}
31 changes: 31 additions & 0 deletions Tests/Functional/TestBundle/Entity/AccessToken.php
@@ -0,0 +1,31 @@
<?php

namespace FOS\OAuthServerBundle\Tests\Functional\TestBundle\Entity;

use FOS\OAuthServerBundle\Entity\AccessToken as BaseAccessToken;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
* @ORM\Table(name="access_tokens")
*/
class AccessToken extends BaseAccessToken
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;

/**
* @ORM\ManyToOne(targetEntity="Client")
* @ORM\JoinColumn(nullable=false)
*/
protected $client;

/**
* @ORM\ManyToOne(targetEntity="User")
*/
protected $user;
}
31 changes: 31 additions & 0 deletions Tests/Functional/TestBundle/Entity/AuthCode.php
@@ -0,0 +1,31 @@
<?php

namespace FOS\OAuthServerBundle\Tests\Functional\TestBundle\Entity;

use FOS\OAuthServerBundle\Entity\AuthCode as BaseAuthCode;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
* @ORM\Table(name="auth_codes")
*/
class AuthCode extends BaseAuthCode
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;

/**
* @ORM\ManyToOne(targetEntity="Client")
* @ORM\JoinColumn(nullable=false)
*/
protected $client;

/**
* @ORM\ManyToOne(targetEntity="User")
*/
protected $user;
}
20 changes: 20 additions & 0 deletions Tests/Functional/TestBundle/Entity/Client.php
@@ -0,0 +1,20 @@
<?php

namespace FOS\OAuthServerBundle\Tests\Functional\TestBundle\Entity;

use FOS\OAuthServerBundle\Entity\Client as BaseClient;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
* @ORM\Table(name="clients")
*/
class Client extends BaseClient
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
}
31 changes: 31 additions & 0 deletions Tests/Functional/TestBundle/Entity/RefreshToken.php
@@ -0,0 +1,31 @@
<?php

namespace FOS\OAuthServerBundle\Tests\Functional\TestBundle\Entity;

use FOS\OAuthServerBundle\Entity\RefreshToken as BaseRefreshToken;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
* @ORM\Table(name="refresh_tokens")
*/
class RefreshToken extends BaseRefreshToken
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;

/**
* @ORM\ManyToOne(targetEntity="Client")
* @ORM\JoinColumn(nullable=false)
*/
protected $client;

/**
* @ORM\ManyToOne(targetEntity="User")
*/
protected $user;
}
59 changes: 59 additions & 0 deletions Tests/Functional/TestBundle/Entity/User.php
@@ -0,0 +1,59 @@
<?php

namespace FOS\OAuthServerBundle\Tests\Functional\TestBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;

/**
* @ORM\Entity
*/
class User implements UserInterface
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;

/**
* @ORM\Column(type="string")
*/
protected $password;

public function getId()
{
return $this->id;
}

public function getRoles()
{
return array('ROLE_USER');
}

public function getPassword()
{
return $this->password;
}

public function setPassword($password)
{
$this->password = $password;
}

public function getSalt()
{
return null;
}

public function getUsername()
{
return $this->getId();
}

public function eraseCredentials()
{

}
}
10 changes: 10 additions & 0 deletions Tests/Functional/TestBundle/TestBundle.php
@@ -0,0 +1,10 @@
<?php

namespace FOS\OAuthServerBundle\Tests\Functional\TestBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class TestBundle extends Bundle
{

}
27 changes: 27 additions & 0 deletions Tests/Functional/TestCase.php
@@ -0,0 +1,27 @@
<?php

namespace FOS\OAuthServerBundle\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['env'] ?: 'test';

return new AppKernel($env, true);
}

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

protected function tearDown()
{
static::$kernel = null;
}
}
25 changes: 25 additions & 0 deletions Tests/Functional/config/config.yml
@@ -0,0 +1,25 @@
framework:
secret: test
router:
resource: "%kernel.root_dir%/config/routing.yml"

fos_oauth_server:

security:
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

firewalls:
oauth_token:
pattern: ^/oauth/v2/token
security: false

oauth_authorize:
pattern: ^/oauth/v2/auth
security: false

secured:
pattern: ^/
fos_oauth: true
stateless: true
30 changes: 30 additions & 0 deletions Tests/Functional/config/config_orm.yml
@@ -0,0 +1,30 @@
imports:
- { resource: config.yml }

doctrine:
dbal:
driver: pdo_sqlite
path: %kernel.cache_dir%/data.sqlite
orm:
entity_managers:
default:
mappings:
TestBundle: ~

fos_oauth_server:
db_driver: orm
service:
user_provider: security.user.provider.concrete.main

client_class: FOS\OAuthServerBundle\Tests\Functional\TestBundle\Entity\Client
access_token_class: FOS\OAuthServerBundle\Tests\Functional\TestBundle\Entity\AccessToken
refresh_token_class: FOS\OAuthServerBundle\Tests\Functional\TestBundle\Entity\RefreshToken
auth_code_class: FOS\OAuthServerBundle\Tests\Functional\TestBundle\Entity\AuthCode

security:
encoders:
FOS\OAuthServerBundle\Tests\Functional\TestBundle\Entity\User: plaintext

providers:
main:
entity: { class: FOS\OAuthServerBundle\Tests\Functional\TestBundle\Entity\User, property: id }
Empty file.
12 changes: 1 addition & 11 deletions Tests/bootstrap.php
Expand Up @@ -17,17 +17,7 @@
require_once $file;
}

spl_autoload_register(function($class) {
if (0 === strpos($class, 'FOS\\OAuthServerBundle\\')) {
$path = __DIR__.'/../'.implode('/', array_slice(explode('\\', $class), 2)).'.php';
if (!stream_resolve_include_path($path)) {
return false;
}
require_once $path;

return true;
}
});
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists');

// Generate Propel base classes on the fly
if (class_exists('TypehintableBehavior')) {
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Expand Up @@ -23,7 +23,10 @@
"require-dev": {
"doctrine/orm": "2.*",
"doctrine/mongodb-odm": "dev-master",
"willdurand/propel-typehintable-behavior": "dev-master"
"willdurand/propel-typehintable-behavior": "dev-master",
"symfony/class-loader": "2.1.*",
"symfony/security-bundle": "2.1.*",
"doctrine/doctrine-bundle": "1.0.*"
},
"suggest": {
"doctrine/doctrine-bundle": "*",
Expand Down

0 comments on commit 92d372c

Please sign in to comment.