Skip to content

Commit

Permalink
Add TranslationNotExists exception
Browse files Browse the repository at this point in the history
  • Loading branch information
faizshukri committed Jan 29, 2016
1 parent f42045e commit 51dc65b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Exceptions/TranslationNotExists.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace FaizShukri\Quran\Exceptions;

use \Exception;

class TranslationNotExists extends Exception { }
4 changes: 4 additions & 0 deletions src/Quran.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace FaizShukri\Quran;

use FaizShukri\Quran\Exceptions\TranslationNotExists;

class Quran
{
private $config;
Expand Down Expand Up @@ -69,6 +71,8 @@ public function get($args)
$xmlFile = $this->firstMatchAvailableTranslation($translation);
}

if(!$xmlFile) throw new TranslationNotExists("Translation " . $translation . " didn't exists. Please check your config.");

$xml = new XML( $xmlFile );
$res = $xml->find($args[0], $this->parseSurah($args[1]));
$result[$translation] = $res;
Expand Down
2 changes: 1 addition & 1 deletion src/config/quran.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,5 @@
|
*/

"translations" => ["en.sahih", "ms.basmeih"],
"translations" => ["en.sahih"],
];
9 changes: 9 additions & 0 deletions tests/QuranTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use FaizShukri\Quran\Quran;
use FaizShukri\Quran\Exceptions\TranslationNotExists;

class QuranTest extends PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -99,4 +100,12 @@ public function test_mix_ayah_translation_sort()
$this->assertEquals('12', key($res)); next($res);
$this->assertEquals('13', key($res));
}

/**
* @expectedException \FaizShukri\Quran\Exceptions\TranslationNotExists
*/
public function test_exception()
{
$this->quran->translation('ms')->get('1:3');
}
}

0 comments on commit 51dc65b

Please sign in to comment.