Skip to content

Commit

Permalink
Throw an exception in the provider, if the file does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
loranmutafov committed Dec 14, 2016
1 parent 0859ddd commit fa9b4b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Amara/Varcon/TranslationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public function __construct($filePath = null, Util $util = null)
*/
public function getTranslations($from, $to, $threshold = 80)
{
if (!file_exists($this->filePath)) {
throw new \RuntimeException(sprintf('File not found: %s', $this->filePath));
}

$fileHandle = fopen($this->filePath, 'r');

$trans = [];
Expand Down
16 changes: 16 additions & 0 deletions tests/Amara/Varcon/TranslationProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Amara\Varcon;

use PHPUnit_Framework_TestCase;

class TranslationProviderTest extends PHPUnit_Framework_TestCase
{
public function testGetTranslationsFileNotFoundException()
{
$translationProvider = new TranslationProvider('random-name-2439857.txt');

$this->setExpectedException(\RuntimeException::class, 'File not found: ');
$translationProvider->getTranslations('B', 'A');
}
}

0 comments on commit fa9b4b5

Please sign in to comment.