Skip to content

Commit ba38089

Browse files
committed
Merge pull request #762 from im-denisenko/fix-es-exception
Add missing interface to ElasticsearchException
2 parents 222a994 + dab72a1 commit ba38089

20 files changed

+274
-10
lines changed

changes.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
CHANGES
22

3+
2015-01-27
4+
- Exception\ElasticsearchException now can be catched like all other exceptions as Exception\ExceptionInterface
5+
36
2015-01-25
47
- Release v1.4.2.0
58

lib/Elastica/Exception/ElasticsearchException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @package Elastica
1010
* @author Ian Babrou <[email protected]>
1111
*/
12-
class ElasticsearchException extends \Exception
12+
class ElasticsearchException extends \Exception implements ExceptionInterface
1313
{
1414
const REMOTE_TRANSPORT_EXCEPTION = 'RemoteTransportException';
1515

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
namespace Elastica\Test\Exception\Bulk\Response;
3+
4+
use Elastica\Test\Base as BaseTest;
5+
6+
class ActionExceptionTest extends BaseTest
7+
{
8+
public function testInheritance()
9+
{
10+
$exception = $this->getMockBuilder('Elastica\Exception\Bulk\Response\ActionException')
11+
->disableOriginalConstructor()
12+
->getMock();
13+
$this->assertInstanceOf('Exception', $exception);
14+
$this->assertInstanceOf('Elastica\Exception\ExceptionInterface', $exception);
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
namespace Elastica\Test\Exception\Bulk;
3+
4+
use Elastica\Test\Base as BaseTest;
5+
6+
class ResponseExceptionTest extends BaseTest
7+
{
8+
public function testInheritance()
9+
{
10+
$exception = $this->getMockBuilder('Elastica\Exception\Bulk\ResponseException')
11+
->disableOriginalConstructor()
12+
->getMock();
13+
$this->assertInstanceOf('Exception', $exception);
14+
$this->assertInstanceOf('Elastica\Exception\ExceptionInterface', $exception);
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
namespace Elastica\Test\Exception\Bulk;
3+
4+
use Elastica\Exception\Bulk\UdpException;
5+
use Elastica\Test\Base as BaseTest;
6+
7+
class UdpExceptionTest extends BaseTest
8+
{
9+
public function testInheritance()
10+
{
11+
$exception = new UdpException();
12+
$this->assertInstanceOf('Exception', $exception);
13+
$this->assertInstanceOf('Elastica\Exception\ExceptionInterface', $exception);
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
namespace Elastica\Test\Exception;
3+
4+
use Elastica\Exception\BulkException;
5+
use Elastica\Test\Base as BaseTest;
6+
7+
class BulkExceptionTest extends BaseTest
8+
{
9+
public function testInheritance()
10+
{
11+
$exception = new BulkException();
12+
$this->assertInstanceOf('Exception', $exception);
13+
$this->assertInstanceOf('Elastica\Exception\ExceptionInterface', $exception);
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
namespace Elastica\Test\Exception;
3+
4+
use Elastica\Exception\ClientException;
5+
use Elastica\Test\Base as BaseTest;
6+
7+
class ClientExceptionTest extends BaseTest
8+
{
9+
public function testInheritance()
10+
{
11+
$exception = new ClientException();
12+
$this->assertInstanceOf('Exception', $exception);
13+
$this->assertInstanceOf('Elastica\Exception\ExceptionInterface', $exception);
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
namespace Elastica\Test\Exception\Connection;
3+
4+
use Elastica\Test\Base as BaseTest;
5+
6+
class GuzzleExceptionTest extends BaseTest
7+
{
8+
public static function setUpBeforeClass()
9+
{
10+
if (!class_exists('GuzzleHttp\\Client')) {
11+
self::markTestSkipped('guzzlehttp/guzzle package should be installed to run guzzle transport tests');
12+
}
13+
}
14+
15+
public function testInheritance()
16+
{
17+
$exception = $this->getMockBuilder('Elastica\Exception\Connection\GuzzleException')
18+
->disableOriginalConstructor()
19+
->getMock();
20+
$this->assertInstanceOf('Exception', $exception);
21+
$this->assertInstanceOf('Elastica\Exception\ExceptionInterface', $exception);
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
namespace Elastica\Test\Exception\Connection;
3+
4+
use Elastica\Test\Base as BaseTest;
5+
6+
class HttpExceptionTest extends BaseTest
7+
{
8+
public function testInheritance()
9+
{
10+
$exception = $this->getMockBuilder('Elastica\Exception\Connection\HttpException')
11+
->disableOriginalConstructor()
12+
->getMock();
13+
$this->assertInstanceOf('Exception', $exception);
14+
$this->assertInstanceOf('Elastica\Exception\ExceptionInterface', $exception);
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
namespace Elastica\Test\Exception\Connection;
3+
4+
use Elastica\Test\Base as BaseTest;
5+
6+
class ThriftExceptionTest extends BaseTest
7+
{
8+
public static function setUpBeforeClass()
9+
{
10+
if (!class_exists('Elasticsearch\\RestClient')) {
11+
self::markTestSkipped('munkie/elasticsearch-thrift-php package should be installed to run thrift exception tests');
12+
}
13+
}
14+
15+
public function testInheritance()
16+
{
17+
$exception = $this->getMockBuilder('Elastica\Exception\Connection\ThriftException')
18+
->disableOriginalConstructor()
19+
->getMock();
20+
$this->assertInstanceOf('Exception', $exception);
21+
$this->assertInstanceOf('Elastica\Exception\ExceptionInterface', $exception);
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
namespace Elastica\Test\Exception;
3+
4+
use Elastica\Test\Base as BaseTest;
5+
6+
class ConnectionExceptionTest extends BaseTest
7+
{
8+
public function testInheritance()
9+
{
10+
$exception = $this->getMockBuilder('Elastica\Exception\ConnectionException')
11+
->disableOriginalConstructor()
12+
->getMock();
13+
$this->assertInstanceOf('Exception', $exception);
14+
$this->assertInstanceOf('Elastica\Exception\ExceptionInterface', $exception);
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
namespace Elastica\Test\Exception;
3+
4+
use Elastica\Test\Base as BaseTest;
5+
6+
class ElasticsearchExceptionTest extends BaseTest
7+
{
8+
public function testInheritance()
9+
{
10+
$exception = $this->getMockBuilder('Elastica\Exception\ElasticsearchException')
11+
->disableOriginalConstructor()
12+
->getMock();
13+
$this->assertInstanceOf('Exception', $exception);
14+
$this->assertInstanceOf('Elastica\Exception\ExceptionInterface', $exception);
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
namespace Elastica\Test\Exception;
3+
4+
use Elastica\Exception\InvalidException;
5+
use Elastica\Test\Base as BaseTest;
6+
7+
class InvalidExceptionTest extends BaseTest
8+
{
9+
public function testInheritance()
10+
{
11+
$exception = new InvalidException();
12+
$this->assertInstanceOf('Exception', $exception);
13+
$this->assertInstanceOf('Elastica\Exception\ExceptionInterface', $exception);
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
namespace Elastica\Test\Exception;
3+
4+
use Elastica\Exception\JSONParseException;
5+
use Elastica\Test\Base as BaseTest;
6+
7+
class JSONParseExceptionTest extends BaseTest
8+
{
9+
public function testInheritance()
10+
{
11+
$exception = new JSONParseException();
12+
$this->assertInstanceOf('Exception', $exception);
13+
$this->assertInstanceOf('Elastica\Exception\ExceptionInterface', $exception);
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
namespace Elastica\Test\Exception;
3+
4+
use Elastica\Exception\NotFoundException;
5+
use Elastica\Test\Base as BaseTest;
6+
7+
class NotFoundExceptionTest extends BaseTest
8+
{
9+
public function testInheritance()
10+
{
11+
$exception = new NotFoundException();
12+
$this->assertInstanceOf('Exception', $exception);
13+
$this->assertInstanceOf('Elastica\Exception\ExceptionInterface', $exception);
14+
}
15+
}

test/lib/Elastica/Test/Exception/NotImplementedTest.php renamed to test/lib/Elastica/Test/Exception/NotImplementedExceptionTest.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
<?php
2-
32
namespace Elastica\Test\Exception;
43

54
use Elastica\Exception\NotImplementedException;
65
use Elastica\Test\Base as BaseTest;
76

8-
class NotImplementedTest extends BaseTest
7+
class NotImplementedExceptionTest extends BaseTest
98
{
9+
public function testInheritance()
10+
{
11+
$exception = new NotImplementedException();
12+
$this->assertInstanceOf('Exception', $exception);
13+
$this->assertInstanceOf('Elastica\Exception\ExceptionInterface', $exception);
14+
}
15+
1016
public function testInstance()
1117
{
1218
$code = 4;
1319
$message = 'Hello world';
1420
$exception = new NotImplementedException($message, $code);
15-
16-
$this->assertInstanceOf('Elastica\Exception\NotImplementedException', $exception);
17-
$this->assertInstanceOf('Elastica\Exception\ExceptionInterface', $exception);
18-
$this->assertInstanceOf('Exception', $exception);
19-
2021
$this->assertEquals($message, $exception->getMessage());
2122
$this->assertEquals($code, $exception->getCode());
2223
}

test/lib/Elastica/Test/Exception/PartialShardFailureExceptionTest.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
namespace Elastica\Test\Exception;
43

54
use Elastica\Document;
@@ -10,6 +9,14 @@
109

1110
class PartialShardFailureExceptionTest extends BaseTest
1211
{
12+
public function testInheritance()
13+
{
14+
$exception = $this->getMockBuilder('Elastica\Exception\PartialShardFailureException')
15+
->disableOriginalConstructor()
16+
->getMock();
17+
$this->assertInstanceOf('Exception', $exception);
18+
$this->assertInstanceOf('Elastica\Exception\ExceptionInterface', $exception);
19+
}
1320

1421
public function testPartialFailure()
1522
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
namespace Elastica\Test\Exception;
3+
4+
use Elastica\Exception\QueryBuilderException;
5+
use Elastica\Test\Base as BaseTest;
6+
7+
class QueryBuilderExceptionTest extends BaseTest
8+
{
9+
public function testInheritance()
10+
{
11+
$exception = new QueryBuilderException();
12+
$this->assertInstanceOf('Exception', $exception);
13+
$this->assertInstanceOf('Elastica\Exception\ExceptionInterface', $exception);
14+
}
15+
}

test/lib/Elastica/Test/Exception/ResponseExceptionTest.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
namespace Elastica\Test\Exception;
43

54
use Elastica\Document;
@@ -8,6 +7,14 @@
87

98
class ResponseExceptionTest extends BaseTest
109
{
10+
public function testInheritance()
11+
{
12+
$exception = $this->getMockBuilder('Elastica\Exception\ResponseException')
13+
->disableOriginalConstructor()
14+
->getMock();
15+
$this->assertInstanceOf('Exception', $exception);
16+
$this->assertInstanceOf('Elastica\Exception\ExceptionInterface', $exception);
17+
}
1118

1219
public function testCreateExistingIndex()
1320
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
namespace Elastica\Test\Exception;
3+
4+
use Elastica\Exception\RuntimeException;
5+
use Elastica\Test\Base as BaseTest;
6+
7+
class RuntimeExceptionTest extends BaseTest
8+
{
9+
public function testInheritance()
10+
{
11+
$exception = new RuntimeException();
12+
$this->assertInstanceOf('Exception', $exception);
13+
$this->assertInstanceOf('Elastica\Exception\ExceptionInterface', $exception);
14+
}
15+
}

0 commit comments

Comments
 (0)