Browse files

[Translation] uniformized the way exception are thrown in LoaderInter…

…face::load()
  • Loading branch information...
1 parent 92a6f43 commit 534f46b57f677055ac3e3b2ebb7d7ab1846c3111 @fabpot fabpot committed Dec 12, 2012
View
9 CHANGELOG.md
@@ -1,6 +1,15 @@
CHANGELOG
=========
+2.2.0
+-----
+
+ * [BC BREAK] uniformized the exception thrown by the load() method when an error occurs. The load() method now
+ throws Symfony\Component\Translation\Exception\InvalidResourceException when a resource cannot be found
+ and Symfony\Component\Translation\Exception\InvalidResourceException when a resource is invalid.
+ * changed the exception class thrown by some load() methods from \RuntimeException to \InvalidArgumentException
+ (IcuDatFileLoader, IcuResFileLoader, and QtTranslationsLoader)
+
2.1.0
-----
View
23 Exception/ExceptionInterface.php
@@ -0,0 +1,23 @@
+<?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 Symfony\Component\Translation\Exception;
+
+/**
+ * Exception interface for all exceptions thrown by the component.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ *
+ * @api
+ */
+interface ExceptionInterface
+{
+}
View
23 Exception/InvalidResourceException.php
@@ -0,0 +1,23 @@
+<?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 Symfony\Component\Translation\Exception;
+
+/**
+ * Thrown when a resource cannot be loaded.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ *
+ * @api
+ */
+class InvalidResourceException extends \InvalidArgumentException implements ExceptionInterface
+{
+}
View
23 Exception/NotFoundResourceException.php
@@ -0,0 +1,23 @@
+<?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 Symfony\Component\Translation\Exception;
+
+/**
+ * Thrown when a resource does not exist.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ *
+ * @api
+ */
+class NotFoundResourceException extends \InvalidArgumentException implements ExceptionInterface
+{
+}
View
14 Loader/CsvFileLoader.php
@@ -11,6 +11,8 @@
namespace Symfony\Component\Translation\Loader;
+use Symfony\Component\Translation\Exception\InvalidResourceException;
+use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Config\Resource\FileResource;
/**
@@ -33,16 +35,20 @@ class CsvFileLoader extends ArrayLoader implements LoaderInterface
*/
public function load($resource, $locale, $domain = 'messages')
{
- $messages = array();
-
if (!stream_is_local($resource)) {
- throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $resource));
+ throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
+ }
+
+ if (!file_exists($resource)) {
+ throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
+ $messages = array();
+
try {
$file = new \SplFileObject($resource, 'rb');
} catch (\RuntimeException $e) {
- throw new \InvalidArgumentException(sprintf('Error opening file "%s".', $resource));
+ throw new NotFoundResourceException(sprintf('Error opening file "%s".', $resource), 0, $e);
}
$file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
View
14 Loader/IcuDatFileLoader.php
@@ -12,6 +12,8 @@
namespace Symfony\Component\Translation\Loader;
use Symfony\Component\Translation\MessageCatalogue;
+use Symfony\Component\Translation\Exception\InvalidResourceException;
+use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Config\Resource\FileResource;
/**
@@ -26,12 +28,20 @@ class IcuDatFileLoader extends IcuResFileLoader
*/
public function load($resource, $locale, $domain = 'messages')
{
+ if (!stream_is_local($resource.'.dat')) {
+ throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
+ }
+
+ if (!file_exists($resource.'.dat')) {
+ throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
+ }
+
$rb = new \ResourceBundle($locale, $resource);
if (!$rb) {
- throw new \RuntimeException("cannot load this resource : $resource");
+ throw new InvalidResourceException(sprintf('Cannot load resource "%s"', $resource));
} elseif (intl_is_failure($rb->getErrorCode())) {
- throw new \RuntimeException($rb->getErrorMessage(), $rb->getErrorCode());
+ throw new InvalidResourceException($rb->getErrorMessage(), $rb->getErrorCode());
}
$messages = $this->flatten($rb);
View
14 Loader/IcuResFileLoader.php
@@ -12,6 +12,8 @@
namespace Symfony\Component\Translation\Loader;
use Symfony\Component\Translation\MessageCatalogue;
+use Symfony\Component\Translation\Exception\InvalidResourceException;
+use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Config\Resource\DirectoryResource;
/**
@@ -26,12 +28,20 @@ class IcuResFileLoader implements LoaderInterface
*/
public function load($resource, $locale, $domain = 'messages')
{
+ if (!stream_is_local($resource)) {
+ throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
+ }
+
+ if (!is_dir($resource)) {
+ throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
+ }
+
$rb = new \ResourceBundle($locale, $resource);
if (!$rb) {
- throw new \RuntimeException("cannot load this resource : $resource");
+ throw new InvalidResourceException(sprintf('Cannot load resource "%s"', $resource));
} elseif (intl_is_failure($rb->getErrorCode())) {
- throw new \RuntimeException($rb->getErrorMessage(), $rb->getErrorCode());
+ throw new InvalidResourceException($rb->getErrorMessage(), $rb->getErrorCode());
}
$messages = $this->flatten($rb);
View
10 Loader/IniFileLoader.php
@@ -11,6 +11,8 @@
namespace Symfony\Component\Translation\Loader;
+use Symfony\Component\Translation\Exception\InvalidResourceException;
+use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Config\Resource\FileResource;
/**
@@ -25,8 +27,12 @@ class IniFileLoader extends ArrayLoader implements LoaderInterface
*/
public function load($resource, $locale, $domain = 'messages')
{
- if (!is_file($resource)) {
- throw new \InvalidArgumentException(sprintf('Error opening file "%s".', $resource));
+ if (!stream_is_local($resource)) {
+ throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
+ }
+
+ if (!file_exists($resource)) {
+ throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
$messages = parse_ini_file($resource, true);
View
4 Loader/LoaderInterface.php
@@ -12,6 +12,7 @@
namespace Symfony\Component\Translation\Loader;
use Symfony\Component\Translation\MessageCatalogue;
+use Symfony\Component\Translation\Exception\InvalidResourceException;
/**
* LoaderInterface is the interface implemented by all translation loaders.
@@ -32,6 +33,9 @@
* @return MessageCatalogue A MessageCatalogue instance
*
* @api
+ *
+ * @throws NotFoundResourceException when the resource cannot be found
+ * @throws InvalidResourceException when the resource cannot be loaded
*/
public function load($resource, $locale, $domain = 'messages');
}
View
16 Loader/MoFileLoader.php
@@ -11,6 +11,8 @@
namespace Symfony\Component\Translation\Loader;
+use Symfony\Component\Translation\Exception\InvalidResourceException;
+use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Config\Resource\FileResource;
/**
@@ -43,8 +45,12 @@ class MoFileLoader extends ArrayLoader implements LoaderInterface
public function load($resource, $locale, $domain = 'messages')
{
+ if (!stream_is_local($resource)) {
+ throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
+ }
+
if (!file_exists($resource)) {
- throw new \InvalidArgumentException(sprintf('File "%s" not found.', $resource));
+ throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
$messages = $this->parse($resource);
@@ -56,7 +62,7 @@ public function load($resource, $locale, $domain = 'messages')
// not an array
if (!is_array($messages)) {
- throw new \InvalidArgumentException(sprintf('The file "%s" must contain a valid mo file.', $resource));
+ throw new InvalidResourceException(sprintf('The file "%s" must contain a valid mo file.', $resource));
}
$catalogue = parent::load($messages, $locale, $domain);
@@ -72,7 +78,7 @@ public function load($resource, $locale, $domain = 'messages')
* @param resource $resource
*
* @return array
- * @throws \InvalidArgumentException If stream content has an invalid format.
+ * @throws InvalidResourceException If stream content has an invalid format.
*/
private function parse($resource)
{
@@ -81,7 +87,7 @@ private function parse($resource)
$stat = fstat($stream);
if ($stat['size'] < self::MO_HEADER_SIZE) {
- throw new \InvalidArgumentException("MO stream content has an invalid format.");
+ throw new InvalidResourceException("MO stream content has an invalid format.");
}
$magic = unpack('V1', fread($stream, 4));
$magic = hexdec(substr(dechex(current($magic)), -8));
@@ -91,7 +97,7 @@ private function parse($resource)
} elseif ($magic == self::MO_BIG_ENDIAN_MAGIC) {
$isBigEndian = true;
} else {
- throw new \InvalidArgumentException("MO stream content has an invalid format.");
+ throw new InvalidResourceException("MO stream content has an invalid format.");
}
$formatRevision = $this->readLong($stream, $isBigEndian);
View
10 Loader/PhpFileLoader.php
@@ -11,6 +11,8 @@
namespace Symfony\Component\Translation\Loader;
+use Symfony\Component\Translation\Exception\InvalidResourceException;
+use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Config\Resource\FileResource;
/**
@@ -29,12 +31,12 @@ class PhpFileLoader extends ArrayLoader implements LoaderInterface
*/
public function load($resource, $locale, $domain = 'messages')
{
- if (!file_exists($resource)) {
- throw new \InvalidArgumentException(sprintf('File "%s" not found.', $resource));
+ if (!stream_is_local($resource)) {
+ throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
}
- if (!stream_is_local($resource)) {
- throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $resource));
+ if (!file_exists($resource)) {
+ throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
$messages = require($resource);
View
10 Loader/PoFileLoader.php
@@ -11,6 +11,8 @@
namespace Symfony\Component\Translation\Loader;
+use Symfony\Component\Translation\Exception\InvalidResourceException;
+use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Config\Resource\FileResource;
/**
@@ -21,8 +23,12 @@ class PoFileLoader extends ArrayLoader implements LoaderInterface
{
public function load($resource, $locale, $domain = 'messages')
{
+ if (!stream_is_local($resource)) {
+ throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
+ }
+
if (!file_exists($resource)) {
- throw new \InvalidArgumentException(sprintf('File "%s" not found.', $resource));
+ throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
$messages = $this->parse($resource);
@@ -34,7 +40,7 @@ public function load($resource, $locale, $domain = 'messages')
// not an array
if (!is_array($messages)) {
- throw new \InvalidArgumentException(sprintf('The file "%s" must contain a valid po file.', $resource));
+ throw new InvalidResourceException(sprintf('The file "%s" must contain a valid po file.', $resource));
}
$catalogue = parent::load($messages, $locale, $domain);
View
14 Loader/QtTranslationsLoader.php
@@ -11,8 +11,10 @@
namespace Symfony\Component\Translation\Loader;
-use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Translation\MessageCatalogue;
+use Symfony\Component\Translation\Exception\InvalidResourceException;
+use Symfony\Component\Translation\Exception\NotFoundResourceException;
+use Symfony\Component\Config\Resource\FileResource;
/**
* QtTranslationsLoader loads translations from QT Translations XML files.
@@ -30,10 +32,18 @@ class QtTranslationsLoader implements LoaderInterface
*/
public function load($resource, $locale, $domain = 'messages')
{
+ if (!stream_is_local($resource)) {
+ throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
+ }
+
+ if (!file_exists($resource)) {
+ throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
+ }
+
$dom = new \DOMDocument();
$current = libxml_use_internal_errors(true);
if (!@$dom->load($resource, defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0)) {
- throw new \RuntimeException(implode("\n", $this->getXmlErrors()));
+ throw new InvalidResourceException(implode("\n", $this->getXmlErrors()));
}
$xpath = new \DOMXPath($dom);
View
16 Loader/XliffFileLoader.php
@@ -12,6 +12,8 @@
namespace Symfony\Component\Translation\Loader;
use Symfony\Component\Translation\MessageCatalogue;
+use Symfony\Component\Translation\Exception\InvalidResourceException;
+use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Config\Resource\FileResource;
/**
@@ -30,12 +32,12 @@ class XliffFileLoader implements LoaderInterface
*/
public function load($resource, $locale, $domain = 'messages')
{
- if (!file_exists($resource)) {
- throw new \InvalidArgumentException(sprintf('File "%s" not found.', $resource));
+ if (!stream_is_local($resource)) {
+ throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
}
- if (!stream_is_local($resource)) {
- throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $resource));
+ if (!file_exists($resource)) {
+ throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
$xml = $this->parseFile($resource);
@@ -71,7 +73,7 @@ private function parseFile($file)
if (!@$dom->loadXML(file_get_contents($file), LIBXML_NONET | (defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0))) {
libxml_disable_entity_loader($disableEntities);
- throw new \RuntimeException(implode("\n", $this->getXmlErrors($internalErrors)));
+ throw new InvalidResourceException(implode("\n", $this->getXmlErrors($internalErrors)));
}
libxml_disable_entity_loader($disableEntities);
@@ -80,7 +82,7 @@ private function parseFile($file)
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
libxml_use_internal_errors($internalErrors);
- throw new \RuntimeException('Document types are not allowed.');
+ throw new InvalidResourceException('Document types are not allowed.');
}
}
@@ -100,7 +102,7 @@ private function parseFile($file)
$source = str_replace('http://www.w3.org/2001/xml.xsd', $location, $source);
if (!@$dom->schemaValidateSource($source)) {
- throw new \RuntimeException(implode("\n", $this->getXmlErrors($internalErrors)));
+ throw new InvalidResourceException(implode("\n", $this->getXmlErrors($internalErrors)));
}
$dom->normalizeDocument();
View
19 Loader/YamlFileLoader.php
@@ -11,8 +11,11 @@
namespace Symfony\Component\Translation\Loader;
+use Symfony\Component\Translation\Exception\InvalidResourceException;
+use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Yaml\Yaml;
+use Symfony\Component\Yaml\Exception\ParseException;
/**
* YamlFileLoader loads translations from Yaml files.
@@ -30,7 +33,19 @@ class YamlFileLoader extends ArrayLoader implements LoaderInterface
*/
public function load($resource, $locale, $domain = 'messages')
{
- $messages = Yaml::parse($resource);
+ if (!stream_is_local($resource)) {
+ throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
+ }
+
+ if (!file_exists($resource)) {
+ throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
+ }
+
+ try {
+ $messages = Yaml::parse($resource);
+ } catch (ParseException $e) {
+ throw new InvalidResourceException('Error parsing YAML.', 0, $e);
+ }
// empty file
if (null === $messages) {
@@ -39,7 +54,7 @@ public function load($resource, $locale, $domain = 'messages')
// not an array
if (!is_array($messages)) {
- throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $resource));
+ throw new InvalidResourceException(sprintf('The file "%s" must contain a YAML array.', $resource));
}
$catalogue = parent::load($messages, $locale, $domain);
View
4 Tests/Loader/CsvFileLoaderTest.php
@@ -46,7 +46,7 @@ public function testLoadDoesNothingIfEmpty()
}
/**
- * @expectedException \InvalidArgumentException
+ * @expectedException Symfony\Component\Translation\Exception\NotFoundResourceException
*/
public function testLoadNonExistingResource()
{
@@ -56,7 +56,7 @@ public function testLoadNonExistingResource()
}
/**
- * @expectedException \InvalidArgumentException
+ * @expectedException Symfony\Component\Translation\Exception\InvalidResourceException
*/
public function testLoadNonLocalResource()
{
View
24 Tests/Loader/IcuDatFileLoaderTest.php
@@ -25,12 +25,20 @@ protected function setUp()
if (!extension_loaded('intl')) {
$this->markTestSkipped('This test requires intl extension to work.');
}
+ }
+ /**
+ * @expectedException Symfony\Component\Translation\Exception\InvalidResourceException
+ */
+ public function testLoadInvalidResource()
+ {
+ $loader = new IcuDatFileLoader();
+ $loader->load(__DIR__.'/../fixtures/resourcebundle/corrupted/resources', 'es', 'domain2');
}
public function testDatEnglishLoad()
{
- // bundled resource is build using pkgdata command which at leas in ICU 4.2 comes in extremely! buggy form
+ // bundled resource is build using pkgdata command which at least in ICU 4.2 comes in extremely! buggy form
// you must specify an temporary build directory which is not the same as current directory and
// MUST reside on the same partition. pkgdata -p resources -T /srv -d . packagelist.txt
$loader = new IcuDatFileLoader();
@@ -54,21 +62,11 @@ public function testDatFrenchLoad()
}
/**
- * @expectedException \RuntimeException
+ * @expectedException Symfony\Component\Translation\Exception\NotFoundResourceException
*/
public function testLoadNonExistingResource()
{
$loader = new IcuDatFileLoader();
- $resource = __DIR__.'/../fixtures/non-existing.txt';
- $loader->load($resource, 'en', 'domain1');
- }
-
- /**
- * @expectedException \RuntimeException
- */
- public function testLoadInvalidResource()
- {
- $loader = new IcuDatFileLoader();
- $loader->load(__DIR__.'/../fixtures/resourcebundle/res/en.txt', 'en', 'domain1');
+ $loader->load(__DIR__.'/../fixtures/non-existing.txt', 'en', 'domain1');
}
}
View
10 Tests/Loader/IcuResFileLoaderTest.php
@@ -25,7 +25,6 @@ protected function setUp()
if (!extension_loaded('intl')) {
$this->markTestSkipped('This test requires intl extension to work.');
}
-
}
public function testLoad()
@@ -41,21 +40,20 @@ public function testLoad()
}
/**
- * @expectedException \RuntimeException
+ * @expectedException Symfony\Component\Translation\Exception\NotFoundResourceException
*/
public function testLoadNonExistingResource()
{
$loader = new IcuResFileLoader();
- $resource = __DIR__.'/../fixtures/non-existing.txt';
- $loader->load($resource, 'en', 'domain1');
+ $loader->load(__DIR__.'/../fixtures/non-existing.txt', 'en', 'domain1');
}
/**
- * @expectedException \RuntimeException
+ * @expectedException Symfony\Component\Translation\Exception\InvalidResourceException
*/
public function testLoadInvalidResource()
{
$loader = new IcuResFileLoader();
- $loader->load(__DIR__.'/../fixtures/resourcebundle/res/en.txt', 'en', 'domain1');
+ $loader->load(__DIR__.'/../fixtures/resourcebundle/corrupted', 'en', 'domain1');
}
}
View
12 Tests/Loader/IniFileLoaderTest.php
@@ -46,22 +46,12 @@ public function testLoadDoesNothingIfEmpty()
}
/**
- * @expectedException \InvalidArgumentException
+ * @expectedException Symfony\Component\Translation\Exception\NotFoundResourceException
*/
public function testLoadNonExistingResource()
{
$loader = new IniFileLoader();
$resource = __DIR__.'/../fixtures/non-existing.ini';
$loader->load($resource, 'en', 'domain1');
}
-
- /**
- * @expectedException \InvalidArgumentException
- */
- public function testLoadThrowsAnExceptionIfFileNotExists()
- {
- $loader = new IniFileLoader();
- $resource = __DIR__.'/../fixtures/not-exists.ini';
- $loader->load($resource, 'en', 'domain1');
- }
}
View
4 Tests/Loader/MoFileLoaderTest.php
@@ -46,7 +46,7 @@ public function testLoadPlurals()
}
/**
- * @expectedException \InvalidArgumentException
+ * @expectedException Symfony\Component\Translation\Exception\NotFoundResourceException
*/
public function testLoadNonExistingResource()
{
@@ -56,7 +56,7 @@ public function testLoadNonExistingResource()
}
/**
- * @expectedException \InvalidArgumentException
+ * @expectedException Symfony\Component\Translation\Exception\InvalidResourceException
*/
public function testLoadInvalidResource()
{
View
4 Tests/Loader/PhpFileLoaderTest.php
@@ -35,7 +35,7 @@ public function testLoad()
}
/**
- * @expectedException \InvalidArgumentException
+ * @expectedException Symfony\Component\Translation\Exception\NotFoundResourceException
*/
public function testLoadNonExistingResource()
{
@@ -45,7 +45,7 @@ public function testLoadNonExistingResource()
}
/**
- * @expectedException \InvalidArgumentException
+ * @expectedException Symfony\Component\Translation\Exception\InvalidResourceException
*/
public function testLoadThrowsAnExceptionIfFileNotLocal()
{
View
2 Tests/Loader/PoFileLoaderTest.php
@@ -57,7 +57,7 @@ public function testLoadDoesNothingIfEmpty()
}
/**
- * @expectedException \InvalidArgumentException
+ * @expectedException Symfony\Component\Translation\Exception\NotFoundResourceException
*/
public function testLoadNonExistingResource()
{
View
2 Tests/Loader/QtTranslationsLoaderTest.php
@@ -35,7 +35,7 @@ public function testLoad()
}
/**
- * @expectedException \RuntimeException
+ * @expectedException Symfony\Component\Translation\Exception\NotFoundResourceException
*/
public function testLoadNonExistingResource()
{
View
10 Tests/Loader/XliffFileLoaderTest.php
@@ -43,7 +43,7 @@ public function testIncompleteResource()
}
/**
- * @expectedException \RuntimeException
+ * @expectedException Symfony\Component\Translation\Exception\InvalidResourceException
*/
public function testLoadInvalidResource()
{
@@ -52,7 +52,7 @@ public function testLoadInvalidResource()
}
/**
- * @expectedException \RuntimeException
+ * @expectedException Symfony\Component\Translation\Exception\InvalidResourceException
*/
public function testLoadResourceDoesNotValidate()
{
@@ -61,7 +61,7 @@ public function testLoadResourceDoesNotValidate()
}
/**
- * @expectedException \InvalidArgumentException
+ * @expectedException Symfony\Component\Translation\Exception\NotFoundResourceException
*/
public function testLoadNonExistingResource()
{
@@ -71,7 +71,7 @@ public function testLoadNonExistingResource()
}
/**
- * @expectedException \InvalidArgumentException
+ * @expectedException Symfony\Component\Translation\Exception\InvalidResourceException
*/
public function testLoadThrowsAnExceptionIfFileNotLocal()
{
@@ -81,7 +81,7 @@ public function testLoadThrowsAnExceptionIfFileNotLocal()
}
/**
- * @expectedException \RuntimeException
+ * @expectedException Symfony\Component\Translation\Exception\InvalidResourceException
* @expectedExceptionMessage Document types are not allowed.
*/
public function testDocTypeIsNotAllowed()
View
14 Tests/Loader/YamlFileLoaderTest.php
@@ -50,7 +50,7 @@ public function testLoadDoesNothingIfEmpty()
}
/**
- * @expectedException \InvalidArgumentException
+ * @expectedException Symfony\Component\Translation\Exception\NotFoundResourceException
*/
public function testLoadNonExistingResource()
{
@@ -60,7 +60,17 @@ public function testLoadNonExistingResource()
}
/**
- * @expectedException \InvalidArgumentException
+ * @expectedException Symfony\Component\Translation\Exception\InvalidResourceException
+ */
+ public function testLoadThrowsAnExceptionIfFileNotLocal()
+ {
+ $loader = new YamlFileLoader();
+ $resource = 'http://example.com/resources.yml';
+ $loader->load($resource, 'en', 'domain1');
+ }
+
+ /**
+ * @expectedException Symfony\Component\Translation\Exception\InvalidResourceException
*/
public function testLoadThrowsAnExceptionIfNotAnArray()
{
View
1 Tests/fixtures/resourcebundle/corrupted/resources.dat
@@ -0,0 +1 @@
+XXX
View
3 Tests/fixtures/resourcebundle/res/en.txt
@@ -1,3 +0,0 @@
-en {
- foo { "bar" }
-}

0 comments on commit 534f46b

Please sign in to comment.