diff --git a/src/Symfony/Component/Locale/Tests/Stub/StubLocaleTest.php b/src/Symfony/Component/Locale/Tests/Stub/StubLocaleTest.php index 568ee1ead3..ed08aac272 100644 --- a/src/Symfony/Component/Locale/Tests/Stub/StubLocaleTest.php +++ b/src/Symfony/Component/Locale/Tests/Stub/StubLocaleTest.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Locale\Tests\Stub; -use Symfony\Component\Locale\Locale; use Symfony\Component\Locale\Stub\StubLocale; use Symfony\Component\Locale\Tests\TestCase as LocaleTestCase; @@ -22,7 +21,7 @@ class StubLocaleTest extends LocaleTestCase */ public function testGetDisplayCountriesWithUnsupportedLocale() { - $countries = StubLocale::getDisplayCountries('pt_BR'); + StubLocale::getDisplayCountries('pt_BR'); } public function testGetDisplayCountries() @@ -42,7 +41,7 @@ class StubLocaleTest extends LocaleTestCase */ public function testGetDisplayLanguagesWithUnsupportedLocale() { - $countries = StubLocale::getDisplayLanguages('pt_BR'); + StubLocale::getDisplayLanguages('pt_BR'); } public function testGetDisplayLanguages() @@ -62,7 +61,7 @@ class StubLocaleTest extends LocaleTestCase */ public function testGetCurrenciesDataWithUnsupportedLocale() { - $currencies = StubLocale::getCurrenciesData('pt_BR'); + StubLocale::getCurrenciesData('pt_BR'); } public function testGetCurrenciesData() @@ -97,7 +96,7 @@ class StubLocaleTest extends LocaleTestCase */ public function testGetDisplayLocalesWithUnsupportedLocale() { - $locales = StubLocale::getDisplayLocales('pt'); + StubLocale::getDisplayLocales('pt'); } public function testGetDisplayLocales() diff --git a/src/Symfony/Component/Translation/Loader/MoFileLoader.php b/src/Symfony/Component/Translation/Loader/MoFileLoader.php index 181915073f..724fb7f0b3 100644 --- a/src/Symfony/Component/Translation/Loader/MoFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/MoFileLoader.php @@ -43,6 +43,10 @@ class MoFileLoader extends ArrayLoader implements LoaderInterface public function load($resource, $locale, $domain = 'messages') { + if (!file_exists($resource)) { + throw new \InvalidArgumentException(sprintf('File "%s" not found.', $resource)); + } + $messages = $this->parse($resource); // empty file diff --git a/src/Symfony/Component/Translation/Loader/PhpFileLoader.php b/src/Symfony/Component/Translation/Loader/PhpFileLoader.php index c80d938a8a..ebb73200e5 100644 --- a/src/Symfony/Component/Translation/Loader/PhpFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/PhpFileLoader.php @@ -29,6 +29,10 @@ 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 \InvalidArgumentException(sprintf('This is not a local file "%s".', $resource)); } diff --git a/src/Symfony/Component/Translation/Loader/PoFileLoader.php b/src/Symfony/Component/Translation/Loader/PoFileLoader.php index c783cb1ecc..686162ac18 100644 --- a/src/Symfony/Component/Translation/Loader/PoFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/PoFileLoader.php @@ -21,6 +21,10 @@ class PoFileLoader extends ArrayLoader implements LoaderInterface { public function load($resource, $locale, $domain = 'messages') { + if (!file_exists($resource)) { + throw new \InvalidArgumentException(sprintf('File "%s" not found.', $resource)); + } + $messages = $this->parse($resource); // empty file diff --git a/src/Symfony/Component/Translation/Loader/XliffFileLoader.php b/src/Symfony/Component/Translation/Loader/XliffFileLoader.php index e8bc40d47a..8e5e0db092 100644 --- a/src/Symfony/Component/Translation/Loader/XliffFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/XliffFileLoader.php @@ -30,6 +30,10 @@ 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 \InvalidArgumentException(sprintf('This is not a local file "%s".', $resource)); } diff --git a/src/Symfony/Component/Translation/Tests/Loader/CsvFileLoaderTest.php b/src/Symfony/Component/Translation/Tests/Loader/CsvFileLoaderTest.php index 303e22868f..b74521bdc9 100644 --- a/src/Symfony/Component/Translation/Tests/Loader/CsvFileLoaderTest.php +++ b/src/Symfony/Component/Translation/Tests/Loader/CsvFileLoaderTest.php @@ -48,7 +48,7 @@ class CsvFileLoaderTest extends \PHPUnit_Framework_TestCase /** * @expectedException \InvalidArgumentException */ - public function testLoadThrowsAnExceptionIfFileNotExists() + public function testLoadNonExistingResource() { $loader = new CsvFileLoader(); $resource = __DIR__.'/../fixtures/not-exists.csv'; @@ -58,7 +58,7 @@ class CsvFileLoaderTest extends \PHPUnit_Framework_TestCase /** * @expectedException \InvalidArgumentException */ - public function testLoadThrowsAnExceptionIfFileNotLocal() + public function testLoadNonLocalResource() { $loader = new CsvFileLoader(); $resource = 'http://example.com/resources.csv'; diff --git a/src/Symfony/Component/Translation/Tests/Loader/IcuDatFileLoaderTest.php b/src/Symfony/Component/Translation/Tests/Loader/IcuDatFileLoaderTest.php index 5dc85f1b56..1e6b3dadf0 100644 --- a/src/Symfony/Component/Translation/Tests/Loader/IcuDatFileLoaderTest.php +++ b/src/Symfony/Component/Translation/Tests/Loader/IcuDatFileLoaderTest.php @@ -53,12 +53,22 @@ class IcuDatFileLoaderTest extends LocalizedTestCase $this->assertEquals(array(new FileResource($resource.'.dat')), $catalogue->getResources()); } + /** + * @expectedException \RuntimeException + */ + 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(); - $catalogue = $loader->load(__DIR__.'/../fixtures/resourcebundle/res/en.txt', 'en', 'domain1'); + $loader->load(__DIR__.'/../fixtures/resourcebundle/res/en.txt', 'en', 'domain1'); } } diff --git a/src/Symfony/Component/Translation/Tests/Loader/IcuResFileLoaderTest.php b/src/Symfony/Component/Translation/Tests/Loader/IcuResFileLoaderTest.php index eeb84bc0e7..cc6e28b3c9 100644 --- a/src/Symfony/Component/Translation/Tests/Loader/IcuResFileLoaderTest.php +++ b/src/Symfony/Component/Translation/Tests/Loader/IcuResFileLoaderTest.php @@ -40,12 +40,22 @@ class IcuResFileLoaderTest extends LocalizedTestCase $this->assertEquals(array(new DirectoryResource($resource)), $catalogue->getResources()); } + /** + * @expectedException \RuntimeException + */ + public function testLoadNonExistingResource() + { + $loader = new IcuResFileLoader(); + $resource = __DIR__.'/../fixtures/non-existing.txt'; + $loader->load($resource, 'en', 'domain1'); + } + /** * @expectedException \RuntimeException */ public function testLoadInvalidResource() { $loader = new IcuResFileLoader(); - $catalogue = $loader->load(__DIR__.'/../fixtures/resourcebundle/res/en.txt', 'en', 'domain1'); + $loader->load(__DIR__.'/../fixtures/resourcebundle/res/en.txt', 'en', 'domain1'); } } diff --git a/src/Symfony/Component/Translation/Tests/Loader/IniFileLoaderTest.php b/src/Symfony/Component/Translation/Tests/Loader/IniFileLoaderTest.php index 30dd3595ed..43a5e774a7 100644 --- a/src/Symfony/Component/Translation/Tests/Loader/IniFileLoaderTest.php +++ b/src/Symfony/Component/Translation/Tests/Loader/IniFileLoaderTest.php @@ -45,6 +45,16 @@ class IniFileLoaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); } + /** + * @expectedException \InvalidArgumentException + */ + public function testLoadNonExistingResource() + { + $loader = new IniFileLoader(); + $resource = __DIR__.'/../fixtures/non-existing.ini'; + $loader->load($resource, 'en', 'domain1'); + } + /** * @expectedException \InvalidArgumentException */ diff --git a/src/Symfony/Component/Translation/Tests/Loader/MoFileLoaderTest.php b/src/Symfony/Component/Translation/Tests/Loader/MoFileLoaderTest.php index b90d07cb3a..1cd9543102 100644 --- a/src/Symfony/Component/Translation/Tests/Loader/MoFileLoaderTest.php +++ b/src/Symfony/Component/Translation/Tests/Loader/MoFileLoaderTest.php @@ -45,6 +45,16 @@ class MoFileLoaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); } + /** + * @expectedException \InvalidArgumentException + */ + public function testLoadNonExistingResource() + { + $loader = new MoFileLoader(); + $resource = __DIR__.'/../fixtures/non-existing.mo'; + $loader->load($resource, 'en', 'domain1'); + } + /** * @expectedException \InvalidArgumentException */ @@ -52,6 +62,6 @@ class MoFileLoaderTest extends \PHPUnit_Framework_TestCase { $loader = new MoFileLoader(); $resource = __DIR__.'/../fixtures/empty.mo'; - $catalogue = $loader->load($resource, 'en', 'domain1'); + $loader->load($resource, 'en', 'domain1'); } } diff --git a/src/Symfony/Component/Translation/Tests/Loader/PhpFileLoaderTest.php b/src/Symfony/Component/Translation/Tests/Loader/PhpFileLoaderTest.php index e90aa99539..279c92e090 100644 --- a/src/Symfony/Component/Translation/Tests/Loader/PhpFileLoaderTest.php +++ b/src/Symfony/Component/Translation/Tests/Loader/PhpFileLoaderTest.php @@ -34,6 +34,16 @@ class PhpFileLoaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); } + /** + * @expectedException \InvalidArgumentException + */ + public function testLoadNonExistingResource() + { + $loader = new PhpFileLoader(); + $resource = __DIR__.'/../fixtures/non-existing.php'; + $loader->load($resource, 'en', 'domain1'); + } + /** * @expectedException \InvalidArgumentException */ diff --git a/src/Symfony/Component/Translation/Tests/Loader/PoFileLoaderTest.php b/src/Symfony/Component/Translation/Tests/Loader/PoFileLoaderTest.php index 39039120d2..3f643266ab 100644 --- a/src/Symfony/Component/Translation/Tests/Loader/PoFileLoaderTest.php +++ b/src/Symfony/Component/Translation/Tests/Loader/PoFileLoaderTest.php @@ -56,6 +56,16 @@ class PoFileLoaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); } + /** + * @expectedException \InvalidArgumentException + */ + public function testLoadNonExistingResource() + { + $loader = new PoFileLoader(); + $resource = __DIR__.'/../fixtures/non-existing.po'; + $loader->load($resource, 'en', 'domain1'); + } + public function testLoadEmptyTranslation() { $loader = new PoFileLoader(); diff --git a/src/Symfony/Component/Translation/Tests/Loader/QtTranslationsLoaderTest.php b/src/Symfony/Component/Translation/Tests/Loader/QtTranslationsLoaderTest.php index 16c2f78f6f..b58c6ff193 100644 --- a/src/Symfony/Component/Translation/Tests/Loader/QtTranslationsLoaderTest.php +++ b/src/Symfony/Component/Translation/Tests/Loader/QtTranslationsLoaderTest.php @@ -33,4 +33,14 @@ class QtTranslationsLoaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals('en', $catalogue->getLocale()); $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); } + + /** + * @expectedException \RuntimeException + */ + public function testLoadNonExistingResource() + { + $loader = new QtTranslationsLoader(); + $resource = __DIR__.'/../fixtures/non-existing.ts'; + $loader->load($resource, 'en', 'domain1'); + } } diff --git a/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php b/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php index 748c13483f..7e80142da9 100644 --- a/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php +++ b/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php @@ -48,7 +48,7 @@ class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase public function testLoadInvalidResource() { $loader = new XliffFileLoader(); - $catalogue = $loader->load(__DIR__.'/../fixtures/resources.php', 'en', 'domain1'); + $loader->load(__DIR__.'/../fixtures/resources.php', 'en', 'domain1'); } /** @@ -57,7 +57,17 @@ class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase public function testLoadResourceDoesNotValidate() { $loader = new XliffFileLoader(); - $catalogue = $loader->load(__DIR__.'/../fixtures/non-valid.xlf', 'en', 'domain1'); + $loader->load(__DIR__.'/../fixtures/non-valid.xlf', 'en', 'domain1'); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testLoadNonExistingResource() + { + $loader = new XliffFileLoader(); + $resource = __DIR__.'/../fixtures/non-existing.xlf'; + $loader->load($resource, 'en', 'domain1'); } /** diff --git a/src/Symfony/Component/Translation/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/Translation/Tests/Loader/YamlFileLoaderTest.php index d954dd3f5e..c73fe645b4 100644 --- a/src/Symfony/Component/Translation/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/Translation/Tests/Loader/YamlFileLoaderTest.php @@ -49,6 +49,16 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); } + /** + * @expectedException \InvalidArgumentException + */ + public function testLoadNonExistingResource() + { + $loader = new YamlFileLoader(); + $resource = __DIR__.'/../fixtures/non-existing.yml'; + $loader->load($resource, 'en', 'domain1'); + } + /** * @expectedException \InvalidArgumentException */