Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add functional tests that boot an app with the bundle.

  • Loading branch information...
commit 92d372c088f8067b975dbc0112b3c97ba5565e6c 1 parent 09994d1
@adrienbrault adrienbrault authored
View
36 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');
+ }
+}
View
22 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'),
+ );
+ }
+}
View
31 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;
+}
View
31 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;
+}
View
20 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;
+}
View
31 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;
+}
View
59 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()
+ {
+
+ }
+}
View
10 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
+{
+
+}
View
27 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;
+ }
+}
View
25 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
View
30 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 }
View
0  Tests/Functional/config/routing.yml
No changes.
View
12 Tests/bootstrap.php
@@ -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')) {
View
5 composer.json
@@ -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": "*",
Please sign in to comment.
Something went wrong with that request. Please try again.