Functional Tests v1

This commit is contained in:
Tim Nagel 2014-06-08 22:35:38 +10:00
parent 833feee207
commit 5009673b6a
8 changed files with 291 additions and 6 deletions

View file

@ -8,3 +8,6 @@ php:
before_script:
- echo "extension = mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- composer install --dev --prefer-source
services:
- elasticsearch

View file

@ -0,0 +1,52 @@
<?php
/**
* This file is part of the FOSElasticaBundle project.
*
* (c) Tim Nagel <tim@nagel.com.au>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace FOS\ElasticaBundle\Tests\Functional;
use Symfony\Bundle\FrameworkBundle\Client;
/**
* @group functional
*/
class MappingToElasticaTest extends WebTestCase
{
public function testReset()
{
$client = $this->createClient(array('test_case' => 'Basic'));
$resetter = $this->getResetter($client);
$resetter->resetIndex('index');
$resetter->resetIndexType('index', 'type');
}
/**
* @param Client $client
* @return \FOS\ElasticaBundle\Resetter $resetter
*/
private function getResetter(Client $client)
{
return $client->getContainer()->get('fos_elastica.resetter');
}
protected function setUp()
{
parent::setUp();
$this->deleteTmpDir('Basic');
}
protected function tearDown()
{
parent::tearDown();
$this->deleteTmpDir('Basic');
}
}

View file

@ -0,0 +1,40 @@
<?php
/**
* This file is part of the FOSElasticaBundle project.
*
* (c) Tim Nagel <tim@nagel.com.au>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace FOS\ElasticaBundle\Tests\Functional;
use Symfony\Bundle\FrameworkBundle\Tests\Functional\WebTestCase as BaseWebTestCase;
class WebTestCase extends BaseWebTestCase
{
protected static function getKernelClass()
{
require_once __DIR__.'/app/AppKernel.php';
return 'FOS\ElasticaBundle\Tests\Functional\app\AppKernel';
}
protected static function createKernel(array $options = array())
{
$class = self::getKernelClass();
if (!isset($options['test_case'])) {
throw new \InvalidArgumentException('The option "test_case" must be set.');
}
return new $class(
$options['test_case'],
isset($options['root_config']) ? $options['root_config'] : 'config.yml',
isset($options['environment']) ? $options['environment'] : 'foselasticabundle'.strtolower($options['test_case']),
isset($options['debug']) ? $options['debug'] : true
);
}
}

View file

@ -0,0 +1,118 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\ElasticaBundle\Tests\Functional\app;
// get the autoload file
$dir = __DIR__;
$lastDir = null;
while ($dir !== $lastDir) {
$lastDir = $dir;
if (file_exists($dir.'/autoload.php')) {
require_once $dir.'/autoload.php';
break;
}
if (file_exists($dir.'/autoload.php.dist')) {
require_once $dir.'/autoload.php.dist';
break;
}
if (file_exists($dir.'/vendor/autoload.php')) {
require_once $dir.'/vendor/autoload.php';
break;
}
$dir = dirname($dir);
}
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\Kernel;
/**
* App Test Kernel for functional tests.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class AppKernel extends Kernel
{
private $testCase;
private $rootConfig;
public function __construct($testCase, $rootConfig, $environment, $debug)
{
if (!is_dir(__DIR__.'/'.$testCase)) {
throw new \InvalidArgumentException(sprintf('The test case "%s" does not exist.', $testCase));
}
$this->testCase = $testCase;
$fs = new Filesystem();
if (!$fs->isAbsolutePath($rootConfig) && !file_exists($rootConfig = __DIR__.'/'.$testCase.'/'.$rootConfig)) {
throw new \InvalidArgumentException(sprintf('The root config "%s" does not exist.', $rootConfig));
}
$this->rootConfig = $rootConfig;
parent::__construct($environment, $debug);
}
public function registerBundles()
{
if (!file_exists($filename = $this->getRootDir().'/'.$this->testCase.'/bundles.php')) {
throw new \RuntimeException(sprintf('The bundles file "%s" does not exist.', $filename));
}
return include $filename;
}
public function init()
{
}
public function getRootDir()
{
return __DIR__;
}
public function getCacheDir()
{
return sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$this->testCase.'/cache/'.$this->environment;
}
public function getLogDir()
{
return sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$this->testCase.'/logs';
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->rootConfig);
}
public function serialize()
{
return serialize(array($this->testCase, $this->rootConfig, $this->getEnvironment(), $this->isDebug()));
}
public function unserialize($str)
{
call_user_func_array(array($this, '__construct'), unserialize($str));
}
protected function getKernelParameters()
{
$parameters = parent::getKernelParameters();
$parameters['kernel.test_case'] = $this->testCase;
return $parameters;
}
}

View file

@ -0,0 +1,10 @@
<?php
use FOS\ElasticaBundle\FOSElasticaBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
return array(
new FrameworkBundle(),
new FOSElasticaBundle(),
);

View file

@ -0,0 +1,53 @@
imports:
- { resource: ./../config/config.yml }
fos_elastica:
clients:
default:
url: http://localhost:9200
indexes:
index:
index_name: foselastica_test_%kernel.environment%
settings:
analysis:
analyzer:
my_analyzer:
type: custom
tokenizer: lowercase
filter: [my_ngram]
filter:
my_ngram:
type: "nGram"
min_gram: 3
max_gram: 5
types:
parent:
mappings:
field1: ~
field2: ~
type:
search_analyzer: my_analyzer
mappings:
field1: ~
field2:
type: integer
date: { boost: 5 }
title: { boost: 8, analyzer: my_analyzer }
content: ~
comments:
type: "nested"
properties:
date: { boost: 5 }
content: ~
user:
type: "object"
approver:
type: "object"
properties:
date: { boost: 5 }
lastlogin: { type: date, format: basic_date_time }
birthday: { type: date, format: "yyyy-MM-dd" }
_parent:
type: "parent"
property: "parent"
identifier: "id"

View file

@ -0,0 +1,8 @@
framework:
secret: secret
router: { resource: "%kernel.root_dir%/%kernel.test_case%/routing.yml" }
test: ~
default_locale: en
services:
logger: { class: Symfony\Component\HttpKernel\Log\NullLogger }

View file

@ -20,20 +20,21 @@
"psr/log": "~1.0"
},
"require-dev":{
"doctrine/orm": ">=2.2,<2.5-dev",
"doctrine/orm": "~2.2",
"doctrine/mongodb-odm": "1.0.*@dev",
"propel/propel1": "1.6.*",
"pagerfanta/pagerfanta": "1.0.*@dev",
"knplabs/knp-components": "1.2.*",
"symfony/expression-language" : "2.4.*@dev"
"knplabs/knp-components": "~1.2",
"symfony/browser-kit" : "~2.3",
"symfony/expression-language" : "~2.4"
},
"suggest": {
"doctrine/orm": ">=2.2,<2.5-dev",
"doctrine/orm": "~2.2",
"doctrine/mongodb-odm": "1.0.*@dev",
"propel/propel1": "1.6.*",
"pagerfanta/pagerfanta": "1.0.*@dev",
"knplabs/knp-components": "1.2.*",
"symfony/expression-language" : "2.4.*@dev"
"knplabs/knp-components": "~1.2",
"symfony/expression-language" : "~2.4"
},
"autoload": {
"psr-0": { "FOS\\ElasticaBundle": "" }