diff --git a/Search/SearchProvider.php b/Search/SearchProvider.php
index 2d46cba9b..f8ab1a636 100644
--- a/Search/SearchProvider.php
+++ b/Search/SearchProvider.php
@@ -63,7 +63,7 @@ class SearchProvider
throw new ParsingException('You should not have more than one domain');
}
- return isset($terms[1][0]) ? $terms[1][0] : '';
+ return isset($terms[1][0]) ? $terms[1][0] : NULL;
}
/**
@@ -89,15 +89,20 @@ class SearchProvider
return $results;
}
- /*
+ /**
* return search services with a specific name, defined in service
* definition.
*
* @return SearchInterface
+ * @throws UnknowSearchNameException if not exists
*/
public function getByName($name)
{
- return $this->searchServices[$name];
+ if (isset($this->searchServices[$name])) {
+ return $this->searchServices;
+ } else {
+ throw new UnknowSearchNameException($name);
+ }
}
public function addSearchService(SearchInterface $service, $name)
diff --git a/Search/UnknowSearchNameException.php b/Search/UnknowSearchNameException.php
new file mode 100644
index 000000000..c03e09923
--- /dev/null
+++ b/Search/UnknowSearchNameException.php
@@ -0,0 +1,35 @@
+
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+namespace Chill\MainBundle\Search;
+
+/**
+ * Throw by search provider when the search name is not found
+ *
+ * @author Julien Fastré
+ */
+class UnknowSearchNameException extends \Exception
+{
+ public function __construct($name)
+ {
+ parent::__construct( "The module search with name $name "
+ . "is not found");
+ }
+}
diff --git a/Tests/Search/SearchProviderTest.php b/Tests/Search/SearchProviderTest.php
index e99925a11..e80465f23 100644
--- a/Tests/Search/SearchProviderTest.php
+++ b/Tests/Search/SearchProviderTest.php
@@ -29,6 +29,14 @@ class SearchProviderTest extends \PHPUnit_Framework_TestCase
$this->search = new SearchProvider();
}
+ /**
+ * @expectedException \Chill\MainBundle\Search\UnknowSearchNameException
+ */
+ public function testInvalidSearchName()
+ {
+ $this->search->getByName("invalid name");
+ }
+
public function testDomain()
{
$term = $this->p("@person is not my name");