mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
Coding standards
This commit is contained in:
@@ -51,7 +51,7 @@ class PathFileTest implements ControllerProviderInterface
|
||||
, 'json'
|
||||
)
|
||||
, 200
|
||||
, array('application/json')
|
||||
, array('content-type' => 'application/json')
|
||||
);
|
||||
});
|
||||
|
||||
@@ -59,6 +59,8 @@ class PathFileTest implements ControllerProviderInterface
|
||||
{
|
||||
$url = $app['request']->get('url');
|
||||
|
||||
$Serializer = $app['Core']['Serializer'];
|
||||
|
||||
return new Response(
|
||||
$Serializer->serialize(
|
||||
array(
|
||||
@@ -67,7 +69,7 @@ class PathFileTest implements ControllerProviderInterface
|
||||
, 'json'
|
||||
)
|
||||
, 200
|
||||
, array('application/json')
|
||||
, array('content-type' => 'application/json')
|
||||
);
|
||||
});
|
||||
|
||||
|
@@ -96,7 +96,7 @@ class Configuration
|
||||
{
|
||||
if (null === $this->environment && $this->isInstalled())
|
||||
{
|
||||
$this->getConfiguration();
|
||||
$this->refresh();
|
||||
}
|
||||
|
||||
return $this->environment;
|
||||
@@ -110,6 +110,7 @@ class Configuration
|
||||
public function setEnvironnement($environement = null)
|
||||
{
|
||||
$this->environment = $environement;
|
||||
$this->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -204,15 +205,20 @@ class Configuration
|
||||
*/
|
||||
public function getConfiguration()
|
||||
{
|
||||
$configuration = array();
|
||||
|
||||
if ($this->installed)
|
||||
if ($this->installed && null === $this->configuration)
|
||||
{
|
||||
$configuration = $this->configurationHandler->handle($this->environment);
|
||||
$this->environment = $this->configurationHandler->getSelectedEnvironnment();
|
||||
$this->configuration = new ParameterBag($configuration);
|
||||
}
|
||||
elseif(!$this->installed)
|
||||
{
|
||||
$configuration = array();
|
||||
$this->configuration = new ParameterBag($configuration);
|
||||
}
|
||||
|
||||
return $this->configuration = new ParameterBag($configuration);
|
||||
return $this->configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -309,7 +315,7 @@ class Configuration
|
||||
->getSpecification()
|
||||
->getConfigurationPathName();
|
||||
|
||||
if (!file_put_contents($filePathName, $yaml, $flag) !== false)
|
||||
if (false === file_put_contents($filePathName, $yaml, $flag))
|
||||
{
|
||||
$filePath = $this->configurationHandler
|
||||
->getSpecification()
|
||||
@@ -326,6 +332,8 @@ class Configuration
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$deleted = false;
|
||||
|
||||
try
|
||||
{
|
||||
$filePathName = $this
|
||||
@@ -422,6 +430,8 @@ class Configuration
|
||||
try
|
||||
{
|
||||
$this->configurationHandler->getSpecification()->getConfigurationFile();
|
||||
$this->configurationHandler->getSpecification()->getServiceFile();
|
||||
$this->configurationHandler->getSpecification()->getConnexionFile();
|
||||
|
||||
$this->installed = true;
|
||||
}
|
||||
@@ -430,8 +440,6 @@ class Configuration
|
||||
$this->installed = false;
|
||||
}
|
||||
|
||||
$this->configuration = new ParameterBag();
|
||||
|
||||
if ($this->installed)
|
||||
{
|
||||
$configuration = $this->configurationHandler->handle($this->environment);
|
||||
|
@@ -13,6 +13,7 @@ class ControllerPathFileTestTest extends \PhraseanetWebTestCaseAbstract
|
||||
* As controllers use WebTestCase, it requires a client
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* If the controller tests require some records, specify it her
|
||||
*
|
||||
@@ -41,11 +42,32 @@ class ControllerPathFileTestTest extends \PhraseanetWebTestCaseAbstract
|
||||
/**
|
||||
* Default route test
|
||||
*/
|
||||
public function testRouteSlash()
|
||||
public function testRoutePath()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
$file = new \SplFileObject(__DIR__ . '/../../../../testfiles/cestlafete.jpg');
|
||||
$this->client->request("GET", "/tests/pathurl/path/", array('path' => $file->getPathname()));
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertTrue($response->isOk());
|
||||
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
$this->assertTrue(is_object($content));
|
||||
$this->assertObjectHasAttribute('exists', $content);
|
||||
$this->assertObjectHasAttribute('file', $content);
|
||||
$this->assertObjectHasAttribute('dir', $content);
|
||||
$this->assertObjectHasAttribute('readable', $content);
|
||||
$this->assertObjectHasAttribute('executable', $content);
|
||||
}
|
||||
|
||||
public function testRouteUrl()
|
||||
{
|
||||
$this->client->request("GET", "/tests/pathurl/url/", array('url' => "www.google.com"));
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertTrue($response->isOk());
|
||||
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
$this->assertTrue(is_object($content));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -87,7 +87,6 @@ class ConfigurationTest extends \PhraseanetPHPUnitAbstract
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$handler = new Configuration\Handler($specNotInstalled, new Configuration\Parser\Yaml());
|
||||
$this->confNotInstalled = new PhraseaCore\Configuration($handler);
|
||||
|
||||
@@ -104,10 +103,20 @@ class ConfigurationTest extends \PhraseanetPHPUnitAbstract
|
||||
|
||||
public function testSetEnvironment()
|
||||
{
|
||||
$this->object->setEnvironnement("ok");
|
||||
$this->assertEquals("ok", $this->object->getEnvironnement());
|
||||
$this->confNotInstalled->setEnvironnement("ok");
|
||||
$this->assertEquals("ok", $this->confNotInstalled->getEnvironnement());
|
||||
$this->object->setEnvironnement("test");
|
||||
$this->assertEquals("test", $this->object->getEnvironnement());
|
||||
$this->confNotInstalled->setEnvironnement("prod");
|
||||
$this->assertEquals("prod", $this->confNotInstalled->getEnvironnement());
|
||||
|
||||
try
|
||||
{
|
||||
$this->object->setEnvironnement("unknow");
|
||||
$this->fail("should raise exception");
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function testIsDebug()
|
||||
@@ -199,7 +208,7 @@ class ConfigurationTest extends \PhraseanetPHPUnitAbstract
|
||||
{
|
||||
try
|
||||
{
|
||||
$connexion = $this->object->getConnexion('unknow_connexion');
|
||||
$this->object->getConnexion('unknow_connexion');
|
||||
$this->fail('should raise an exception');
|
||||
}
|
||||
catch (\Exception $e)
|
||||
@@ -236,13 +245,33 @@ class ConfigurationTest extends \PhraseanetPHPUnitAbstract
|
||||
$this->assertArrayHasKey("environment", $all);
|
||||
}
|
||||
|
||||
public function testGetService()
|
||||
public function testGetServices()
|
||||
{
|
||||
$services = $this->object->getServices();
|
||||
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $services);
|
||||
$this->assertGreaterThan(0, sizeof($services->all()));
|
||||
}
|
||||
|
||||
public function testGetService()
|
||||
{
|
||||
$services = $this->object->getService('twig');
|
||||
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $services);
|
||||
$this->assertGreaterThan(0, sizeof($services->all()));
|
||||
}
|
||||
|
||||
public function testGetServiceException()
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->object->getService('unknow_service');
|
||||
$this->fail('should raise an exception');
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function testWrite()
|
||||
{
|
||||
touch(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
|
||||
@@ -295,7 +324,7 @@ class ConfigurationTest extends \PhraseanetPHPUnitAbstract
|
||||
$stub->expects($this->any())
|
||||
->method('getConfigurationPathName')
|
||||
->will(
|
||||
$this->returnValue($file->getPathname())
|
||||
$this->returnValue("unknow_path")
|
||||
);
|
||||
|
||||
$handler = new Configuration\Handler($stub, new Configuration\Parser\Yaml());
|
||||
@@ -312,7 +341,6 @@ class ConfigurationTest extends \PhraseanetPHPUnitAbstract
|
||||
|
||||
try
|
||||
{
|
||||
chmod($file->getPathname(), 0444);
|
||||
$configuration->write($arrayToBeWritten);
|
||||
$this->fail("should raise an exception");
|
||||
}
|
||||
@@ -320,7 +348,6 @@ class ConfigurationTest extends \PhraseanetPHPUnitAbstract
|
||||
{
|
||||
|
||||
}
|
||||
chmod($file->getPathname(), 0666);
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
@@ -347,6 +374,7 @@ class ConfigurationTest extends \PhraseanetPHPUnitAbstract
|
||||
$configuration->delete();
|
||||
|
||||
$this->assertFileNotExists($file->getPathname());
|
||||
<<<<<<< HEAD
|
||||
|
||||
}
|
||||
|
||||
@@ -384,5 +412,146 @@ class ConfigurationTest extends \PhraseanetPHPUnitAbstract
|
||||
// $this->assertFileExists($file->getPathname());
|
||||
//
|
||||
// }
|
||||
=======
|
||||
}
|
||||
|
||||
public function testDeleteException()
|
||||
{
|
||||
touch(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
|
||||
|
||||
$stub = $this->getMock(
|
||||
'\Alchemy\Phrasea\Core\Configuration\Application'
|
||||
, array('getConfigurationPathName')
|
||||
);
|
||||
|
||||
$file = new \SplFileObject(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
|
||||
|
||||
$stub->expects($this->any())
|
||||
->method('getConfigurationPathName')
|
||||
->will(
|
||||
$this->returnValue("unknow_path")
|
||||
);
|
||||
|
||||
$handler = new Configuration\Handler($stub, new Configuration\Parser\Yaml());
|
||||
|
||||
$configuration = new PhraseaCore\Configuration($handler);
|
||||
|
||||
try
|
||||
{
|
||||
$configuration->delete();
|
||||
$this->fail("should raise an exception");
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
$this->assertFileExists($file->getPathname());
|
||||
|
||||
unlink(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
|
||||
}
|
||||
|
||||
public function testGetTemplating()
|
||||
{
|
||||
try
|
||||
{
|
||||
$templating = $this->object->getTemplating();
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->fail("not template_engine provided");
|
||||
}
|
||||
$this->assertTrue(is_string($templating));
|
||||
}
|
||||
|
||||
public function testGetOrm()
|
||||
{
|
||||
try
|
||||
{
|
||||
$orm = $this->object->getOrm();
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->fail("not template_engine provided");
|
||||
}
|
||||
$this->assertTrue(is_string($orm));
|
||||
}
|
||||
|
||||
public function testGetServiceFile()
|
||||
{
|
||||
$this->assertInstanceOf("\SplFileObject", $this->object->getServiceFile());
|
||||
}
|
||||
|
||||
public function testGetConnexionFile()
|
||||
{
|
||||
$this->assertInstanceOf("\SplFileObject", $this->object->getConnexionFile());
|
||||
}
|
||||
|
||||
public function testRefresh()
|
||||
{
|
||||
$this->confNotInstalled->refresh();
|
||||
$this->assertFalse($this->confNotInstalled->isInstalled());
|
||||
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $this->confNotInstalled->getConfiguration());
|
||||
|
||||
touch(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
|
||||
|
||||
$stub = $this->getMock(
|
||||
'\Alchemy\Phrasea\Core\Configuration\Application'
|
||||
, array('getConfigurationPathName')
|
||||
);
|
||||
|
||||
$file = new \SplFileObject(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
|
||||
|
||||
$stub->expects($this->any())
|
||||
->method('getConfigurationPathName')
|
||||
->will(
|
||||
$this->returnValue($file->getPathname())
|
||||
);
|
||||
|
||||
$handler = new Configuration\Handler($stub, new Configuration\Parser\Yaml());
|
||||
|
||||
$configuration = new PhraseaCore\Configuration($handler);
|
||||
|
||||
$newScope = array("prod" => array('key' => 'value', 'key2' => 'value2'));
|
||||
|
||||
//append new conf
|
||||
$configuration->write($newScope, FILE_APPEND);
|
||||
|
||||
try
|
||||
{
|
||||
$configuration->getConfiguration();//it is not loaded
|
||||
$this->fail("should raise an exception");
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
$configuration->refresh(); //reload conf
|
||||
$prod = $configuration->getConfiguration();
|
||||
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $prod);
|
||||
|
||||
unlink(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
|
||||
}
|
||||
|
||||
public function testSetHandler()
|
||||
{
|
||||
$handler = new Configuration\Handler(new Configuration\Application(), new Configuration\Parser\Yaml());
|
||||
$this->object->setConfigurationHandler($handler);
|
||||
$this->assertEquals($handler, $this->object->getConfigurationHandler());
|
||||
}
|
||||
>>>>>>> 6c616f05de57005857dd23faafef4c028992e770
|
||||
|
||||
public function testGetHandler()
|
||||
{
|
||||
$stub = $this->getMock(
|
||||
'\Alchemy\Phrasea\Core\Configuration\Application'
|
||||
, array('getConfigurationFile')
|
||||
);
|
||||
|
||||
$handler = new Configuration\Handler($stub, new Configuration\Parser\Yaml());
|
||||
|
||||
$this->assertEquals($handler, $this->object->getConfigurationHandler());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,13 +0,0 @@
|
||||
main_connexion:
|
||||
host: hostname
|
||||
port: port
|
||||
user: username
|
||||
password: password
|
||||
dbname: dbname
|
||||
driver: pdo_mysql
|
||||
charset: UTF8
|
||||
|
||||
test_connexion:
|
||||
driver: pdo_sqlite
|
||||
path: one/path/to/database
|
||||
charset: UTF8
|
@@ -1,79 +0,0 @@
|
||||
twig:
|
||||
type: twig
|
||||
options:
|
||||
debug: false
|
||||
charset: utf-8
|
||||
strict_variables: true
|
||||
optimizer: true
|
||||
|
||||
twig_debug:
|
||||
type: twig
|
||||
options:
|
||||
debug: true
|
||||
charset: utf-8
|
||||
strict_variables: true
|
||||
autoescape: true
|
||||
optimizer: true
|
||||
|
||||
doctrine_dev:
|
||||
type: doctrine
|
||||
options:
|
||||
debug: true
|
||||
dbal: main_connexion
|
||||
orm:
|
||||
cache:
|
||||
query: array_cache
|
||||
result: array_cache
|
||||
metadata: array_cache
|
||||
log: query_logger
|
||||
|
||||
doctrine_test:
|
||||
type: doctrine
|
||||
options:
|
||||
debug: true
|
||||
dbal: test_connexion
|
||||
orm:
|
||||
cache:
|
||||
query: array_cache
|
||||
result: array_cache
|
||||
metadata: array_cache
|
||||
log: query_logger
|
||||
|
||||
doctrine_prod:
|
||||
type: doctrine
|
||||
options:
|
||||
debug: false
|
||||
dbal: main_connexion
|
||||
orm:
|
||||
cache:
|
||||
query: apc_cache
|
||||
result: apc_cache
|
||||
metadata: apc_cache
|
||||
log: query_logger
|
||||
|
||||
|
||||
query_logger:
|
||||
type: monolog
|
||||
options:
|
||||
output: json
|
||||
channel: query-logger
|
||||
max_day: 2
|
||||
filename: doctrine-query.log
|
||||
|
||||
sql_logger:
|
||||
type: normal
|
||||
|
||||
array_cache:
|
||||
type: array
|
||||
|
||||
memcache_cache:
|
||||
type: memcache
|
||||
options:
|
||||
host: localhost
|
||||
port: 11211
|
||||
|
||||
apc_cache:
|
||||
type: apc
|
||||
|
||||
xcache_cache:
|
||||
type: xcache
|
@@ -20,10 +20,7 @@ require_once __DIR__ . '/../../../../../PhraseanetPHPUnitAbstract.class.inc';
|
||||
class MonologTest extends PhraseanetPHPUnitAbstract
|
||||
{
|
||||
|
||||
protected $options = array(
|
||||
"handler" => "rotate"
|
||||
, "filename" => "test"
|
||||
);
|
||||
protected $options;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
@@ -110,4 +107,30 @@ class MonologTest extends PhraseanetPHPUnitAbstract
|
||||
}
|
||||
}
|
||||
|
||||
public function testMissingFile()
|
||||
{
|
||||
try
|
||||
{
|
||||
unset($this->options["filename"]);
|
||||
$log = new \Alchemy\Phrasea\Core\Service\Log\Monolog(
|
||||
'hello', $this->options, array()
|
||||
);
|
||||
$this->fail("should raise an exception");
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function testStreamLogger()
|
||||
{
|
||||
|
||||
$this->options["handler"] = "stream";
|
||||
$log = new \Alchemy\Phrasea\Core\Service\Log\Monolog(
|
||||
'hello', $this->options, array()
|
||||
);
|
||||
$this->assertInstanceOf("\Monolog\Logger", $log->getService());
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user