Add parse date function to abstract Search

This commit is contained in:
Julien Fastré 2015-01-06 15:31:00 +01:00
parent c584ea2c7c
commit 5289ad9c2c
2 changed files with 76 additions and 1 deletions

View File

@ -22,6 +22,7 @@
namespace Chill\MainBundle\Search;
use Chill\MainBundle\Search\SearchInterface;
use Chill\MainBundle\Search\ParsingException;
/**
* This class implements abstract search with most common responses.
@ -34,5 +35,21 @@ use Chill\MainBundle\Search\SearchInterface;
*/
abstract class AbstractSearch implements SearchInterface
{
/**
*
* @param type $string
* @return \DateTime
* @throws ParsingException if the date is not parseable
*/
public function parseDate($string)
{
try {
return new \DateTime($string);
} catch (ParsingException $ex) {
$exception = new ParsingException('The date is '
. 'not parsable', 0, $ex);
throw $exception;
}
}
}

View File

@ -0,0 +1,58 @@
<?php
/*
* Chill is a suite of a modules, Chill is a software for social workers
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.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\Tests\Search;
/**
* Description of AbstractSearch
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class AbstractSearchTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Ab
* @var type
* @var typestractS
*/
private $stub;
public function setUp()
{
$this->stub = $this->getMockForAbstractClass('Chill\MainBundle\Search\AbstractSearch',
array(),
'',
true,
true,
true,
array('parseDate'));
}
public function testParseDateRegular()
{
$this->markTestSkipped('We have to learn how to mock concret methods for abstract class');
$date = $this->stub->parseDate('2014-05-01');
$this->assertEquals('2014', $date->format('Y'));
$this->assertEquals('05', $date->format('m'));
$this->assertEquals('01', $date->format('d'));
}
}