add testes for service builder

This commit is contained in:
Nicolas Le Goff
2012-01-23 18:58:39 +01:00
parent 3e1fb21a21
commit 02a1e4b3b9
5 changed files with 296 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class AbstractBuilderTest extends PhraseanetPHPUnitAbstract
{
public function testConstructExceptionNameEmpty()
{
try
{
$stub = $this->getMockForAbstractClass(
"\Alchemy\Phrasea\Core\ServiceBuilder\AbstractBuilder"
, array(
''
, new \Symfony\Component\DependencyInjection\ParameterBag\ParameterBag()
, array('dependency' => 'one_dependency')
, null
)
);
$this->fail("should raise an exception");
}
catch (\Exception $e)
{
}
}
public function testConstructExceptionCreate()
{
try
{
$stub = $this->getMockForAbstractClass(
"\Alchemy\Phrasea\Core\ServiceBuilder\AbstractBuilder"
, array(
'test'
, new \Symfony\Component\DependencyInjection\ParameterBag\ParameterBag()
, array('dependency' => 'one_dependency')
, null
)
);
$this->fail("should raise an exception");
}
catch (\Exception $e)
{
}
}
}

View File

@@ -0,0 +1,50 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class CacheBuilderTest extends PhraseanetPHPUnitAbstract
{
public function testCreateException()
{
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "unknow")
);
try
{
$service = Alchemy\Phrasea\Core\ServiceBuilder\Cache::create("test", $configuration);
$this->fail("An exception should be raised");
}
catch (\Exception $e)
{
}
}
public function testCreate()
{
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "array")
);
$service = Alchemy\Phrasea\Core\ServiceBuilder\Cache::create("test", $configuration);
$this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service);
}
}

View File

@@ -0,0 +1,68 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class LogBuilderTest extends PhraseanetPHPUnitAbstract
{
public function testCreateException()
{
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "unknow", "options" => array())
);
try
{
$service = Alchemy\Phrasea\Core\ServiceBuilder\Log::create("test", $configuration);
$this->fail("An exception should be raised");
}
catch (\Exception $e)
{
}
}
public function testCreate()
{
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "monolog", "options" => array(
"handler" => "rotate"
, "filename" => "test"
)
)
);
$service = Alchemy\Phrasea\Core\ServiceBuilder\Log::create("test", $configuration);
$this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service);
}
public function testCreateNamespace()
{
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "normal", "options" => array(
"handler" => "rotate"
, "filename" => "test"
)
)
);
$service = Alchemy\Phrasea\Core\ServiceBuilder\Log::create("test", $configuration, array(), "Doctrine");
$this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service);
}
}

View File

@@ -0,0 +1,64 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class OrmBuilderTest extends PhraseanetPHPUnitAbstract
{
public function testCreateException()
{
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "unknow", "options" => array())
);
try
{
$service = Alchemy\Phrasea\Core\ServiceBuilder\Orm::create("test", $configuration);
$this->fail("An exception should be raised");
}
catch (\Exception $e)
{
}
}
public function testCreate()
{
$registry = $this->getMock("\RegistryInterface");
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "doctrine", "options" => array(
"debug" => false
, "log" => "sql_logger"
, "dbal" => "main_connexion"
, "orm" => array(
"cache" => array(
"metadata" => "array_cache"
, "query" => "array_cache"
, "result" => "array_cache"
)
)
)
)
);
$service = Alchemy\Phrasea\Core\ServiceBuilder\Orm::create("test", $configuration, array("registry" => $registry));
$this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service);
}
}

View File

@@ -0,0 +1,50 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class TemplateBuilderTest extends PhraseanetPHPUnitAbstract
{
public function testCreateException()
{
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "unknow", "options" => array())
);
try
{
$service = Alchemy\Phrasea\Core\ServiceBuilder\TemplateEngine::create("test", $configuration);
$this->fail("An exception should be raised");
}
catch (\Exception $e)
{
}
}
public function testCreate()
{
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "twig", "options" => array())
);
$service = Alchemy\Phrasea\Core\ServiceBuilder\TemplateEngine::create("test", $configuration);
$this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service);
}
}