fix when search service not exists

throw an error when the search service name does not exists.
+ test
This commit is contained in:
Julien Fastré 2014-12-28 23:45:42 +01:00
parent 13f7dcb00b
commit 0157e90753
3 changed files with 51 additions and 3 deletions

View File

@ -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)

View File

@ -0,0 +1,35 @@
<?php
/*
* Chill is a software for social workers
* Copyright (C) 2014 Julien Fastré <julien.fastre@champs-libres.coop>
*
* 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 <http://www.gnu.org/licenses/>.
*/
namespace Chill\MainBundle\Search;
/**
* Throw by search provider when the search name is not found
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class UnknowSearchNameException extends \Exception
{
public function __construct($name)
{
parent::__construct( "The module search with name $name "
. "is not found");
}
}

View File

@ -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");