Author: fabien
Date: 2010-01-18 13:30:03 +0100 (Mon, 18 Jan 2010)
New Revision: 26808
Added:
branches/2.0/src/Symfony/Components/DependencyInjection/FileResource.php
branches/2.0/src/Symfony/Components/DependencyInjection/ResourceInterface.php
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/ini/parameters2.ini
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/xml/services13.xml
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/yaml/services13.yml
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/FileResourceTest.php
Modified:
branches/2.0/src/Symfony/Components/DependencyInjection/BuilderConfiguration.php
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/FileLoader.php
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/IniFileLoader.php
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/LoaderInterface.php
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/XmlFileLoader.php
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/YamlFileLoader.php
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/xml/services4.xml
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/yaml/services4.yml
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/BuilderConfigurationTest.php
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/Loader/IniLoaderTest.php
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/Loader/XmlFileLoaderTest.php
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/Loader/YamlFileLoaderTest.php
Log:
Merge branch 'master' of git://github.com/symfony/symfony
Modified:
branches/2.0/src/Symfony/Components/DependencyInjection/BuilderConfiguration.php
===================================================================
---
branches/2.0/src/Symfony/Components/DependencyInjection/BuilderConfiguration.php
2010-01-18 11:54:29 UTC (rev 26807)
+++
branches/2.0/src/Symfony/Components/DependencyInjection/BuilderConfiguration.php
2010-01-18 12:30:03 UTC (rev 26808)
@@ -23,6 +23,7 @@
protected $definitions = array();
protected $parameters = array();
protected $aliases = array();
+ protected $resources = array();
public function __construct(array $definitions = array(), array $parameters
= array())
{
@@ -31,6 +32,26 @@
}
/**
+ * Returns an array of resources loaded to build this configuration.
+ *
+ * @return array An array of resources
+ */
+ public function getResources()
+ {
+ return $this->resources;
+ }
+
+ /**
+ * Adds a resource for this configuration.
+ *
+ * @param ResourceInterface $resource A resource instance
+ */
+ public function addResource(ResourceInterface $resource)
+ {
+ $this->resources[] = $resource;
+ }
+
+ /**
* Merges a BuilderConfiguration with the current one.
*
* @param BuilderConfiguration $configuration
@@ -45,6 +66,11 @@
$this->addDefinitions($configuration->getDefinitions());
$this->addAliases($configuration->getAliases());
$this->addParameters($configuration->getParameters());
+
+ foreach ($configuration->getResources() as $resource)
+ {
+ $this->addResource($resource);
+ }
}
/**
Added: branches/2.0/src/Symfony/Components/DependencyInjection/FileResource.php
===================================================================
--- branches/2.0/src/Symfony/Components/DependencyInjection/FileResource.php
(rev 0)
+++ branches/2.0/src/Symfony/Components/DependencyInjection/FileResource.php
2010-01-18 12:30:03 UTC (rev 26808)
@@ -0,0 +1,61 @@
+<?php
+
+namespace Symfony\Components\DependencyInjection;
+
+/*
+ * This file is part of the symfony framework.
+ *
+ * (c) Fabien Potencier <[email protected]>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+/**
+ * FileResource represents a resource stored on the filesystem.
+ *
+ * @package symfony
+ * @subpackage dependency_injection
+ * @author Fabien Potencier <[email protected]>
+ */
+class FileResource implements ResourceInterface
+{
+ protected $resource;
+
+ /**
+ * Constructor.
+ *
+ * @param string $resource The file path to the resource
+ */
+ public function __construct($resource)
+ {
+ $this->resource = $resource;
+ }
+
+ /**
+ * Returns the resource tied to this Resource.
+ *
+ * @return mixed The resource
+ */
+ public function getResource()
+ {
+ return $this->resource;
+ }
+
+ /**
+ * Returns true if the resource has not been updated since the given
timestamp.
+ *
+ * @param timestamp $timestamp The last time the resource was loaded
+ *
+ * @return Boolean true if the resource has not been updated, false otherwise
+ */
+ public function isUptodate($timestamp)
+ {
+ if (!file_exists($this->resource))
+ {
+ return false;
+ }
+
+ return filemtime($this->resource) < $timestamp;
+ }
+}
Modified:
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/FileLoader.php
===================================================================
---
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/FileLoader.php
2010-01-18 11:54:29 UTC (rev 26807)
+++
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/FileLoader.php
2010-01-18 12:30:03 UTC (rev 26808)
@@ -37,6 +37,17 @@
$this->paths = $paths;
}
+ protected function findFile($file)
+ {
+ $path = $this->getAbsolutePath($file);
+ if (!file_exists($path))
+ {
+ throw new \InvalidArgumentException(sprintf('The file "%s" does not
exist (in: %s).', $file, implode(', ', $this->paths)));
+ }
+
+ return realpath($path);
+ }
+
protected function getAbsolutePath($file, $currentPath = null)
{
if (self::isAbsolutePath($file))
Modified:
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/IniFileLoader.php
===================================================================
---
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/IniFileLoader.php
2010-01-18 11:54:29 UTC (rev 26807)
+++
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/IniFileLoader.php
2010-01-18 12:30:03 UTC (rev 26808)
@@ -3,6 +3,7 @@
namespace Symfony\Components\DependencyInjection\Loader;
use Symfony\Components\DependencyInjection\BuilderConfiguration;
+use Symfony\Components\DependencyInjection\FileResource;
/*
* This file is part of the symfony framework.
@@ -25,40 +26,30 @@
/**
* Loads a resource.
*
- * @param mixed $resource The resource path
+ * @param string $file An INI file path
*
* @return BuilderConfiguration A BuilderConfiguration instance
*/
- public function load($files)
+ public function load($file)
{
- if (!is_array($files))
- {
- $files = array($files);
- }
+ $path = $this->findFile($file);
$configuration = new BuilderConfiguration();
- foreach ($files as $file)
+ $configuration->addResource(new FileResource($path));
+
+ $result = parse_ini_file($path, true);
+ if (false === $result || array() === $result)
{
- $path = $this->getAbsolutePath($file);
- if (!file_exists($path))
- {
- throw new \InvalidArgumentException(sprintf('The %s file does not
exist.', $file));
- }
+ throw new \InvalidArgumentException(sprintf('The %s file is not valid.',
$file));
+ }
- $result = parse_ini_file($path, true);
- if (false === $result || array() === $result)
+ if (isset($result['parameters']) && is_array($result['parameters']))
+ {
+ foreach ($result['parameters'] as $key => $value)
{
- throw new \InvalidArgumentException(sprintf('The %s file is not
valid.', $file));
+ $configuration->setParameter(strtolower($key), $value);
}
-
- if (isset($result['parameters']) && is_array($result['parameters']))
- {
- foreach ($result['parameters'] as $key => $value)
- {
- $configuration->setParameter(strtolower($key), $value);
- }
- }
}
return $configuration;
Modified:
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/LoaderInterface.php
===================================================================
---
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/LoaderInterface.php
2010-01-18 11:54:29 UTC (rev 26807)
+++
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/LoaderInterface.php
2010-01-18 12:30:03 UTC (rev 26808)
@@ -56,7 +56,7 @@
* If you load file1.xml and file2.xml in this order, the value of complex
* will be "foo".
*
- * @param mixed $resource The resource path
+ * @param mixed $resource The resource
*
* @return BuilderConfiguration A BuilderConfiguration instance
*/
Modified:
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/XmlFileLoader.php
===================================================================
---
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/XmlFileLoader.php
2010-01-18 11:54:29 UTC (rev 26807)
+++
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/XmlFileLoader.php
2010-01-18 12:30:03 UTC (rev 26808)
@@ -6,6 +6,7 @@
use Symfony\Components\DependencyInjection\Reference;
use Symfony\Components\DependencyInjection\BuilderConfiguration;
use Symfony\Components\DependencyInjection\SimpleXMLElement;
+use Symfony\Components\DependencyInjection\FileResource;
/*
* This file is part of the symfony framework.
@@ -28,42 +29,35 @@
/**
* Loads an array of XML files.
*
- * @param array $files An array of XML files
+ * @param string $file An XML file path
*
* @return BuilderConfiguration A BuilderConfiguration instance
*/
- public function load($files)
+ public function load($file)
{
- if (!is_array($files))
- {
- $files = array($files);
- }
+ $path = $this->findFile($file);
- return $this->parse($this->getFilesAsXml($files));
- }
+ $xml = $this->parseFile($path);
- protected function parse(array $xmls)
- {
$configuration = new BuilderConfiguration();
- foreach ($xmls as $file => $xml)
- {
- // anonymous services
- $xml = $this->processAnonymousServices($configuration, $xml, $file);
+ $configuration->addResource(new FileResource($path));
- // imports
- $this->parseImports($configuration, $xml, $file);
+ // anonymous services
+ $xml = $this->processAnonymousServices($configuration, $xml, $file);
- // parameters
- $this->parseParameters($configuration, $xml, $file);
+ // imports
+ $this->parseImports($configuration, $xml, $file);
- // services
- $this->parseDefinitions($configuration, $xml, $file);
+ // parameters
+ $this->parseParameters($configuration, $xml, $file);
- // extensions
- $this->loadFromExtensions($configuration, $xml);
- }
+ // services
+ $this->parseDefinitions($configuration, $xml, $file);
+ // extensions
+ $this->loadFromExtensions($configuration, $xml);
+
return $configuration;
}
@@ -92,16 +86,27 @@
protected function parseImport($import, $file)
{
- if (isset($import['class']) && $import['class'] != get_class($this))
+ $class = null;
+ if (isset($import['class']) && $import['class'] !== get_class($this))
{
$class = (string) $import['class'];
- $loader = new $class($this->paths);
}
else
{
- $loader = $this;
+ // try to detect loader with the extension
+ switch (pathinfo((string) $import['resource'], PATHINFO_EXTENSION))
+ {
+ case 'yml':
+ $class =
'Symfony\\Components\\DependencyInjection\\Loader\\YamlFileLoader';
+ break;
+ case 'ini':
+ $class =
'Symfony\\Components\\DependencyInjection\\Loader\\IniFileLoader';
+ break;
+ }
}
+ $loader = null === $class ? $this : new $class($this->paths);
+
$importedFile = $this->getAbsolutePath((string) $import['resource'],
dirname($file));
return $loader->load($importedFile);
@@ -176,33 +181,20 @@
$configuration->setDefinition($id, $definition);
}
- protected function getFilesAsXml(array $files)
+ protected function parseFile($file)
{
- $xmls = array();
- foreach ($files as $file)
+ $dom = new \DOMDocument();
+ libxml_use_internal_errors(true);
+ if (!$dom->load($file, LIBXML_COMPACT))
{
- $path = $this->getAbsolutePath($file);
-
- if (!file_exists($path))
- {
- throw new \InvalidArgumentException(sprintf('The service file "%s"
does not exist (in: %s).', $file, implode(', ', $this->paths)));
- }
-
- $dom = new \DOMDocument();
- libxml_use_internal_errors(true);
- if (!$dom->load(realpath($path), LIBXML_COMPACT))
- {
- throw new \InvalidArgumentException(implode("\n",
$this->getXmlErrors()));
- }
- $dom->validateOnParse = true;
- $dom->normalizeDocument();
- libxml_use_internal_errors(false);
- $this->validate($dom, $path);
-
- $xmls[$path] = simplexml_import_dom($dom,
'Symfony\\Components\\DependencyInjection\\SimpleXMLElement');
+ throw new \InvalidArgumentException(implode("\n",
$this->getXmlErrors()));
}
+ $dom->validateOnParse = true;
+ $dom->normalizeDocument();
+ libxml_use_internal_errors(false);
+ $this->validate($dom, $file);
- return $xmls;
+ return simplexml_import_dom($dom,
'Symfony\\Components\\DependencyInjection\\SimpleXMLElement');
}
protected function processAnonymousServices(BuilderConfiguration
$configuration, $xml, $file)
Modified:
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/YamlFileLoader.php
===================================================================
---
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/YamlFileLoader.php
2010-01-18 11:54:29 UTC (rev 26807)
+++
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/YamlFileLoader.php
2010-01-18 12:30:03 UTC (rev 26808)
@@ -6,6 +6,7 @@
use Symfony\Components\DependencyInjection\Definition;
use Symfony\Components\DependencyInjection\Reference;
use Symfony\Components\DependencyInjection\BuilderConfiguration;
+use Symfony\Components\DependencyInjection\FileResource;
use Symfony\Components\YAML\YAML;
/*
@@ -31,49 +32,42 @@
/**
* Loads an array of Yaml files.
*
- * @param array $files An array of Yaml files
+ * @param string $file A YAML file path
*
* @return BuilderConfiguration A BuilderConfiguration instance
*/
- public function load($files)
+ public function load($file)
{
- if (!is_array($files))
- {
- $files = array($files);
- }
+ $path = $this->findFile($file);
- return $this->parse($this->getFilesAsArray($files));
- }
+ $content = $this->loadFile($path);
- protected function parse($data)
- {
$configuration = new BuilderConfiguration();
- foreach ($data as $file => $content)
+ $configuration->addResource(new FileResource($path));
+
+ if (!$content)
{
- if (!$content)
- {
- continue;
- }
+ return $configuration;
+ }
- // imports
- $this->parseImports($configuration, $content, $file);
+ // imports
+ $this->parseImports($configuration, $content, $file);
- // parameters
- if (isset($content['parameters']))
+ // parameters
+ if (isset($content['parameters']))
+ {
+ foreach ($content['parameters'] as $key => $value)
{
- foreach ($content['parameters'] as $key => $value)
- {
- $configuration->setParameter(strtolower($key),
$this->resolveServices($value));
- }
+ $configuration->setParameter(strtolower($key),
$this->resolveServices($value));
}
+ }
- // services
- $this->parseDefinitions($configuration, $content, $file);
+ // services
+ $this->parseDefinitions($configuration, $content, $file);
- // extensions
- $this->loadFromExtensions($configuration, $content);
- }
+ // extensions
+ $this->loadFromExtensions($configuration, $content);
return $configuration;
}
@@ -93,16 +87,27 @@
protected function parseImport($import, $file)
{
- if (isset($import['class']) && $import['class'] != get_class($this))
+ $class = null;
+ if (isset($import['class']) && $import['class'] !== get_class($this))
{
$class = $import['class'];
- $loader = new $class($this->paths);
}
else
{
- $loader = $this;
+ // try to detect loader with the extension
+ switch (pathinfo((string) $import['resource'], PATHINFO_EXTENSION))
+ {
+ case 'xml':
+ $class =
'Symfony\\Components\\DependencyInjection\\Loader\\XmlFileLoader';
+ break;
+ case 'ini':
+ $class =
'Symfony\\Components\\DependencyInjection\\Loader\\IniFileLoader';
+ break;
+ }
}
+ $loader = null === $class ? $this : new $class($this->paths);
+
$importedFile = $this->getAbsolutePath($import['resource'],
dirname($file));
return $loader->load($importedFile);
@@ -175,22 +180,9 @@
$configuration->setDefinition($id, $definition);
}
- protected function getFilesAsArray(array $files)
+ protected function loadFile($file)
{
- $yamls = array();
- foreach ($files as $file)
- {
- $path = $this->getAbsolutePath($file);
-
- if (!file_exists($path))
- {
- throw new \InvalidArgumentException(sprintf('The service file "%s"
does not exist (in: %s).', $file, implode(', ', $this->paths)));
- }
-
- $yamls[$path] = $this->validate(YAML::load($path), $path);
- }
-
- return $yamls;
+ return $this->validate(YAML::load($file), $file);
}
protected function validate($content, $file)
Added:
branches/2.0/src/Symfony/Components/DependencyInjection/ResourceInterface.php
===================================================================
---
branches/2.0/src/Symfony/Components/DependencyInjection/ResourceInterface.php
(rev 0)
+++
branches/2.0/src/Symfony/Components/DependencyInjection/ResourceInterface.php
2010-01-18 12:30:03 UTC (rev 26808)
@@ -0,0 +1,38 @@
+<?php
+
+namespace Symfony\Components\DependencyInjection;
+
+/*
+ * This file is part of the symfony framework.
+ *
+ * (c) Fabien Potencier <[email protected]>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+/**
+ * ResourceInterface is the interface that must be implemented by all Resource
classes.
+ *
+ * @package symfony
+ * @subpackage dependency_injection
+ * @author Fabien Potencier <[email protected]>
+ */
+interface ResourceInterface
+{
+ /**
+ * Returns true if the resource has not been updated since the given
timestamp.
+ *
+ * @param timestamp $timestamp The last time the resource was loaded
+ *
+ * @return Boolean true if the resource has not been updated, false otherwise
+ */
+ function isUptodate($timestamp);
+
+ /**
+ * Returns the resource tied to this Resource.
+ *
+ * @return mixed The resource
+ */
+ function getResource();
+}
Added:
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/ini/parameters2.ini
===================================================================
---
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/ini/parameters2.ini
(rev 0)
+++
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/ini/parameters2.ini
2010-01-18 12:30:03 UTC (rev 26808)
@@ -0,0 +1,2 @@
+[parameters]
+ imported_from_ini = true
Copied:
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/xml/services13.xml
(from rev 26683,
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/xml/services4.xml)
===================================================================
---
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/xml/services13.xml
(rev 0)
+++
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/xml/services13.xml
2010-01-18 12:30:03 UTC (rev 26808)
@@ -0,0 +1,9 @@
+<?xml version="1.0" ?>
+
+<container xmlns="http://www.symfony-project.org/schema/dic/services"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services
http://www.symfony-project.org/schema/dic/services/services-1.0.xsd">
+ <parameters>
+ <parameter key="imported_from_xml">true</parameter>
+ </parameters>
+</container>
Modified:
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/xml/services4.xml
===================================================================
---
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/xml/services4.xml
2010-01-18 11:54:29 UTC (rev 26807)
+++
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/xml/services4.xml
2010-01-18 12:30:03 UTC (rev 26808)
@@ -7,5 +7,7 @@
<import resource="services2.xml" />
<import resource="services3.xml" />
<import resource="../ini/parameters.ini"
class="Symfony\Components\DependencyInjection\Loader\IniFileLoader" />
+ <import resource="../ini/parameters2.ini" />
+ <import resource="../yaml/services13.yml" />
</imports>
</container>
Added:
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/yaml/services13.yml
===================================================================
---
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/yaml/services13.yml
(rev 0)
+++
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/yaml/services13.yml
2010-01-18 12:30:03 UTC (rev 26808)
@@ -0,0 +1,3 @@
+# used to test imports in XML
+parameters:
+ imported_from_yaml: true
Modified:
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/yaml/services4.yml
===================================================================
---
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/yaml/services4.yml
2010-01-18 11:54:29 UTC (rev 26807)
+++
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/yaml/services4.yml
2010-01-18 12:30:03 UTC (rev 26808)
@@ -2,3 +2,5 @@
- { resource: services2.yml }
- { resource: services3.yml }
- { resource: "../ini/parameters.ini", class:
Symfony\Components\DependencyInjection\Loader\IniFileLoader }
+ - { resource: "../ini/parameters2.ini" }
+ - { resource: "../xml/services13.xml" }
Modified:
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/BuilderConfigurationTest.php
===================================================================
---
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/BuilderConfigurationTest.php
2010-01-18 11:54:29 UTC (rev 26807)
+++
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/BuilderConfigurationTest.php
2010-01-18 12:30:03 UTC (rev 26808)
@@ -14,10 +14,11 @@
use Symfony\Components\DependencyInjection\BuilderConfiguration;
use Symfony\Components\DependencyInjection\Definition;
use Symfony\Components\DependencyInjection\Reference;
+use Symfony\Components\DependencyInjection\FileResource;
$fixturesPath =
__DIR__.'/../../../../fixtures/Symfony/Components/DependencyInjection/';
-$t = new LimeTest(37);
+$t = new LimeTest(39);
// __construct()
$t->diag('__construct()');
@@ -62,6 +63,13 @@
$configuration->merge($config);
$t->is($configuration->getDefinition('foo')->getClass(), 'BazClass',
'->merge() overrides already defined services');
+$configuration = new BuilderConfiguration();
+$configuration->addResource($a = new FileResource('foo.xml'));
+$config = new BuilderConfiguration();
+$config->addResource($b = new FileResource('foo.yml'));
+$configuration->merge($config);
+$t->is($configuration->getResources(), array($a, $b), '->merge() merges
resources');
+
// ->setParameters() ->getParameters()
$t->diag('->setParameters() ->getParameters()');
@@ -175,3 +183,10 @@
$configuration->setAlias('bar', 'foo');
$configuration->setAlias('foobar', 'bar');
$t->is($configuration->findDefinition('foobar'), $definition,
'->findDefinition() returns a Definition');
+
+// ->addResource() ->getResources()
+$t->diag('->addResource() ->getResources()');
+$configuration = new BuilderConfiguration();
+$configuration->addResource($a = new FileResource('foo.xml'));
+$configuration->addResource($b = new FileResource('foo.yml'));
+$t->is($configuration->getResources(), array($a, $b), '->getResources()
returns an array of resources read for the current configuration');
Added:
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/FileResourceTest.php
===================================================================
---
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/FileResourceTest.php
(rev 0)
+++
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/FileResourceTest.php
2010-01-18 12:30:03 UTC (rev 26808)
@@ -0,0 +1,31 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * (c) Fabien Potencier <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+require_once __DIR__.'/../../../bootstrap.php';
+
+use Symfony\Components\DependencyInjection\FileResource;
+
+$t = new LimeTest(4);
+
+// ->getResource()
+$t->diag('->getResource()');
+$file = sys_get_temp_dir().'/tmp.xml';
+touch($file);
+$resource = new FileResource($file);
+$t->is($resource->getResource(), $file, '->getResource() returns the path to
the resource');
+
+// ->isUptodate()
+$t->diag('->isUptodate()');
+$t->ok($resource->isUptodate(time() + 10), '->isUptodate() returns true if the
resource has not changed');
+$t->ok(!$resource->isUptodate(time() - 86400), '->isUptodate() returns false
if the resource has been updated');
+unlink($file);
+
+$resource = new FileResource('/____foo/foobar'.rand(1, 999999));
+$t->ok(!$resource->isUptodate(time()), '->isUptodate() returns false if the
resource does not exist');
Modified:
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/Loader/IniLoaderTest.php
===================================================================
---
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/Loader/IniLoaderTest.php
2010-01-18 11:54:29 UTC (rev 26807)
+++
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/Loader/IniLoaderTest.php
2010-01-18 12:30:03 UTC (rev 26808)
@@ -13,22 +13,14 @@
use Symfony\Components\DependencyInjection\Builder;
use Symfony\Components\DependencyInjection\Loader\IniFileLoader;
-$t = new LimeTest(5);
+$t = new LimeTest(3);
$fixturesPath =
realpath(__DIR__.'/../../../../../fixtures/Symfony/Components/DependencyInjection/');
$loader = new IniFileLoader($fixturesPath.'/ini');
-$config = $loader->load(array('parameters.ini'));
-$t->is($config->getParameters(), array('foo' => 'bar', 'bar' => '%foo%'),
'->load() takes an array of file names as its first argument');
-
-$loader = new IniFileLoader($fixturesPath.'/ini');
$config = $loader->load('parameters.ini');
$t->is($config->getParameters(), array('foo' => 'bar', 'bar' => '%foo%'),
'->load() takes a single file name as its first argument');
-$loader = new IniFileLoader($fixturesPath.'/ini');
-$config = $loader->load(array('parameters.ini', 'parameters1.ini'));
-$t->is($config->getParameters(), array('foo' => 'foo', 'bar' => '%foo%', 'baz'
=> 'baz'), '->load() merges parameters from all given files');
-
try
{
$loader->load('foo.ini');
Modified:
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/Loader/XmlFileLoaderTest.php
===================================================================
---
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/Loader/XmlFileLoaderTest.php
2010-01-18 11:54:29 UTC (rev 26807)
+++
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/Loader/XmlFileLoaderTest.php
2010-01-18 12:30:03 UTC (rev 26808)
@@ -16,7 +16,7 @@
use Symfony\Components\DependencyInjection\Loader\Loader;
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
-$t = new LimeTest(44);
+$t = new LimeTest(40);
$fixturesPath =
realpath(__DIR__.'/../../../../../fixtures/Symfony/Components/DependencyInjection/');
@@ -24,20 +24,20 @@
class ProjectLoader extends XmlFileLoader
{
- public function getFilesAsXml(array $files)
+ public function parseFile($file)
{
- return parent::getFilesAsXml($files);
+ return parent::parseFile($file);
}
}
-// ->getFilesAsXml()
-$t->diag('->getFilesAsXml()');
+// ->load()
+$t->diag('->load()');
$loader = new ProjectLoader($fixturesPath.'/ini');
try
{
- $loader->getFilesAsXml(array('foo.xml'));
+ $loader->load('foo.xml');
$t->fail('->load() throws an InvalidArgumentException if the loaded file
does not exist');
}
catch (InvalidArgumentException $e)
@@ -45,51 +45,48 @@
$t->pass('->load() throws an InvalidArgumentException if the loaded file
does not exist');
}
+// ->parseFile()
+$t->diag('->parseFile()');
+
try
{
- $loader->getFilesAsXml(array('parameters.ini'));
- $t->fail('->load() throws an InvalidArgumentException if the loaded file is
not a valid XML file');
+ $loader->parseFile($fixturesPath.'/ini/parameters.ini');
+ $t->fail('->parseFile() throws an InvalidArgumentException if the loaded
file is not a valid XML file');
}
catch (InvalidArgumentException $e)
{
- $t->pass('->load() throws an InvalidArgumentException if the loaded file is
not a valid XML file');
+ $t->pass('->parseFile() throws an InvalidArgumentException if the loaded
file is not a valid XML file');
}
$loader = new ProjectLoader($fixturesPath.'/xml');
try
{
- $loader->getFilesAsXml(array('nonvalid.xml'));
- $t->fail('->load() throws an InvalidArgumentException if the loaded file
does not validate the XSD');
+ $loader->parseFile($fixturesPath.'/xml/nonvalid.xml');
+ $t->fail('->parseFile() throws an InvalidArgumentException if the loaded
file does not validate the XSD');
}
catch (InvalidArgumentException $e)
{
- $t->pass('->load() throws an InvalidArgumentException if the loaded file
does not validate the XSD');
+ $t->pass('->parseFile() throws an InvalidArgumentException if the loaded
file does not validate the XSD');
}
-$xmls = $loader->getFilesAsXml(array('services1.xml'));
-$t->is(count($xmls), 1, '->getFilesAsXml() returns an array of simple xml
objects');
-$t->is(key($xmls), realpath($fixturesPath.'/xml/services1.xml'),
'->getFilesAsXml() returns an array where the keys are absolutes paths to the
original XML file');
-$t->is(get_class(current($xmls)),
'Symfony\\Components\\DependencyInjection\\SimpleXMLElement',
'->getFilesAsXml() returns an array where values are SimpleXMLElement objects');
+$xml = $loader->parseFile($fixturesPath.'/xml/services1.xml');
+$t->is(get_class($xml),
'Symfony\\Components\\DependencyInjection\\SimpleXMLElement', '->parseFile()
returns an SimpleXMLElement object');
// ->load() # parameters
$t->diag('->load() # parameters');
$loader = new ProjectLoader($fixturesPath.'/xml');
-$config = $loader->load(array('services2.xml'));
+$config = $loader->load('services2.xml');
$t->is($config->getParameters(), array('a string', 'foo' => 'bar', 'values' =>
array(0, 'integer' => 4, 100 => null, 'true', true, false, 'on', 'off', 'float'
=> 1.3, 1000.3, 'a string', array('foo', 'bar')), 'foo_bar' => new
Reference('foo_bar')), '->load() converts XML values to PHP ones');
-$loader = new ProjectLoader($fixturesPath.'/xml');
-$config = $loader->load(array('services2.xml', 'services3.xml'));
-$t->is($config->getParameters(), array('a string', 'foo' => 'foo', 'values' =>
array(true, false), 'foo_bar' => new Reference('foo_bar')), '->load() merges
the first level of arguments when multiple files are loaded');
-
// ->load() # imports
$t->diag('->load() # imports');
-$config = $loader->load(array('services4.xml'));
-$t->is($config->getParameters(), array('a string', 'foo' => 'bar', 'bar' =>
'%foo%', 'values' => array(true, false), 'foo_bar' => new
Reference('foo_bar')), '->load() imports and merges imported files');
+$config = $loader->load('services4.xml');
+$t->is($config->getParameters(), array('a string', 'foo' => 'bar', 'bar' =>
'%foo%', 'values' => array(true, false), 'foo_bar' => new Reference('foo_bar'),
'imported_from_yaml' => true, 'imported_from_ini' => true), '->load() imports
and merges imported files');
// ->load() # anonymous services
$t->diag('->load() # anonymous services');
-$config = $loader->load(array('services5.xml'));
+$config = $loader->load('services5.xml');
$services = $config->getDefinitions();
$t->is(count($services), 3, '->load() attributes unique ids to anonymous
services');
$args = $services['foo']->getArguments();
@@ -108,7 +105,7 @@
// ->load() # services
$t->diag('->load() # services');
-$config = $loader->load(array('services6.xml'));
+$config = $loader->load('services6.xml');
$services = $config->getDefinitions();
$t->ok(isset($services['foo']), '->load() parses <service> elements');
$t->is(get_class($services['foo']),
'Symfony\\Components\\DependencyInjection\\Definition', '->load() converts
<service> element to Definition instances');
@@ -127,10 +124,6 @@
$t->ok(isset($aliases['alias_for_foo']), '->load() parses <service> elements');
$t->is($aliases['alias_for_foo'], 'foo', '->load() parses aliases');
-$config = $loader->load(array('services6.xml', 'services7.xml'));
-$services = $config->getDefinitions();
-$t->is($services['foo']->getClass(), 'BarClass', '->load() merges the services
when multiple files are loaded');
-
// ::convertDomElementToArray()
$t->diag('::convertDomElementToArray()');
$doc = new DOMDocument("1.0");
Modified:
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/Loader/YamlFileLoaderTest.php
===================================================================
---
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/Loader/YamlFileLoaderTest.php
2010-01-18 11:54:29 UTC (rev 26807)
+++
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/Loader/YamlFileLoaderTest.php
2010-01-18 12:30:03 UTC (rev 26808)
@@ -16,7 +16,7 @@
use Symfony\Components\DependencyInjection\Loader\Loader;
use Symfony\Components\DependencyInjection\Loader\YamlFileLoader;
-$t = new LimeTest(29);
+$t = new LimeTest(25);
$fixturesPath =
realpath(__DIR__.'/../../../../../fixtures/Symfony/Components/DependencyInjection/');
@@ -24,20 +24,20 @@
class ProjectLoader extends YamlFileLoader
{
- public function getFilesAsArray(array $files)
+ public function loadFile($file)
{
- return parent::getFilesAsArray($files);
+ return parent::loadFile($file);
}
}
-// ->getFilesAsArray()
-$t->diag('->getFilesAsArray()');
+// ->loadFile()
+$t->diag('->loadFile()');
$loader = new ProjectLoader($fixturesPath.'/ini');
try
{
- $loader->getFilesAsArray(array('foo.yml'));
+ $loader->loadFile('foo.yml');
$t->fail('->load() throws an InvalidArgumentException if the loaded file
does not exist');
}
catch (InvalidArgumentException $e)
@@ -47,7 +47,7 @@
try
{
- $loader->getFilesAsArray(array('parameters.ini'));
+ $loader->loadFile('parameters.ini');
$t->fail('->load() throws an InvalidArgumentException if the loaded file is
not a valid YAML file');
}
catch (InvalidArgumentException $e)
@@ -61,7 +61,7 @@
{
try
{
- $loader->getFilesAsArray(array($fixture.'.yml'));
+ $loader->loadFile($fixture.'.yml');
$t->fail('->load() throws an InvalidArgumentException if the loaded file
does not validate');
}
catch (InvalidArgumentException $e)
@@ -70,28 +70,20 @@
}
}
-$yamls = $loader->getFilesAsArray(array('services1.yml'));
-$t->ok(is_array($yamls), '->getFilesAsArray() returns an array');
-$t->is(key($yamls), realpath($fixturesPath.'/yaml/services1.yml'),
'->getFilesAsArray() returns an array where the keys are absolutes paths to the
original YAML file');
-
// ->load() # parameters
$t->diag('->load() # parameters');
$loader = new ProjectLoader($fixturesPath.'/yaml');
-$config = $loader->load(array('services2.yml'));
+$config = $loader->load('services2.yml');
$t->is($config->getParameters(), array('foo' => 'bar', 'values' => array(true,
false, 0, 1000.3), 'bar' => 'foo', 'foo_bar' => new Reference('foo_bar')),
'->load() converts YAML keys to lowercase');
-$loader = new ProjectLoader($fixturesPath.'/yaml');
-$config = $loader->load(array('services2.yml', 'services3.yml'));
-$t->is($config->getParameters(), array('foo' => 'foo', 'values' => array(true,
false), 'bar' => 'foo', 'foo_bar' => new Reference('foo_bar')), '->load()
merges the first level of arguments when multiple files are loaded');
-
// ->load() # imports
$t->diag('->load() # imports');
-$config = $loader->load(array('services4.yml'));
-$t->is($config->getParameters(), array('foo' => 'bar', 'bar' => '%foo%',
'values' => array(true, false), 'foo_bar' => new Reference('foo_bar')),
'->load() imports and merges imported files');
+$config = $loader->load('services4.yml');
+$t->is($config->getParameters(), array('foo' => 'bar', 'bar' => '%foo%',
'values' => array(true, false), 'foo_bar' => new Reference('foo_bar'),
'imported_from_xml' => true, 'imported_from_ini' => true), '->load() imports
and merges imported files');
// ->load() # services
$t->diag('->load() # services');
-$config = $loader->load(array('services6.yml'));
+$config = $loader->load('services6.yml');
$services = $config->getDefinitions();
$t->ok(isset($services['foo']), '->load() parses service elements');
$t->is(get_class($services['foo']),
'Symfony\\Components\\DependencyInjection\\Definition', '->load() converts
service element to Definition instances');
@@ -110,10 +102,6 @@
$t->ok(isset($aliases['alias_for_foo']), '->load() parses aliases');
$t->is($aliases['alias_for_foo'], 'foo', '->load() parses aliases');
-$config = $loader->load(array('services6.yml', 'services7.yml'));
-$services = $config->getDefinitions();
-$t->is($services['foo']->getClass(), 'BarClass', '->load() merges the services
when multiple files are loaded');
-
// extensions
$t->diag('extensions');
Loader::registerExtension(new ProjectExtension());
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.