-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Do not fail the entire batch because one source failed. - Improve behavior related to noRecordsMatch error. - Improve tests.
- Loading branch information
1 parent
ecf740c
commit b0b5573
Showing
6 changed files
with
232 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
/** | ||
* OAI-PMH exception class | ||
* | ||
* PHP version 7 | ||
* | ||
* Copyright (c) Demian Katz 2021. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2, | ||
* as published by the Free Software Foundation. | ||
* | ||
* 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* @category VuFind | ||
* @package Harvest_Tools | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/indexing:oai-pmh Wiki | ||
*/ | ||
namespace VuFindHarvest\Exception; | ||
|
||
use Throwable; | ||
|
||
/** | ||
* OAI-PMH exception class | ||
* | ||
* @category VuFind | ||
* @package Harvest_Tools | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/indexing:oai-pmh Wiki | ||
*/ | ||
class OaiException extends \RuntimeException | ||
{ | ||
/** | ||
* Error code | ||
* | ||
* @var string | ||
*/ | ||
protected $oaiCode; | ||
|
||
/** | ||
* Error message | ||
* | ||
* @var string | ||
*/ | ||
protected $oaiMessage; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param string $oaiCode OAI-PMH error code | ||
* @param string $oaiMessage OAI-PMH error message | ||
* @param int $code Error code | ||
* @param ?Throwable $previous Previous exception | ||
*/ | ||
public function __construct(string $oaiCode, string $oaiMessage, int $code = 0, | ||
?Throwable $previous = null | ||
) { | ||
$this->oaiCode = $oaiCode; | ||
$this->oaiMessage = $oaiMessage; | ||
$message = "OAI-PMH error -- code: $oaiCode, value: $oaiMessage"; | ||
parent::__construct($message, $code, $previous); | ||
} | ||
|
||
/** | ||
* Get OAI-PMH error code | ||
* | ||
* @return string | ||
*/ | ||
public function getOaiCode(): string | ||
{ | ||
return $this->oaiCode; | ||
} | ||
|
||
/** | ||
* Get OAI-PMH error message | ||
* | ||
* @return string | ||
*/ | ||
public function getOaiMessage(): string | ||
{ | ||
return $this->oaiMessage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
tests/unit-tests/src/VuFindTest/Exception/OaiExceptionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
/** | ||
* OAI exception test | ||
* | ||
* PHP version 7 | ||
* | ||
* Copyright (C) Villanova University 2021. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2, | ||
* as published by the Free Software Foundation. | ||
* | ||
* 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* @category VuFind | ||
* @package Tests | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development | ||
*/ | ||
namespace VuFindTest\Harvest\ConsoleOutput; | ||
|
||
use VuFindHarvest\Exception\OaiException; | ||
|
||
/** | ||
* OAI exception test | ||
* | ||
* @category VuFind | ||
* @package Tests | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development | ||
*/ | ||
class OaiExceptionTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* Test exception | ||
* | ||
* @return void | ||
*/ | ||
public function testException() | ||
{ | ||
$exception = new OaiException('code', 'message'); | ||
$this->assertEquals('code', $exception->getOaiCode()); | ||
$this->assertEquals('message', $exception->getOaiMessage()); | ||
$this->assertEquals( | ||
'OAI-PMH error -- code: code, value: message', $exception->getMessage() | ||
); | ||
$this->assertEquals(0, $exception->getCode()); | ||
$this->assertNull($exception->getPrevious()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters