1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Lug package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Lug\Component\Translation\Tests\Exception; |
13
|
|
|
|
14
|
|
|
use Lug\Component\Translation\Exception\ExceptionInterface; |
15
|
|
|
use Lug\Component\Translation\Exception\RuntimeException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author GeLo <[email protected]> |
19
|
|
|
*/ |
20
|
|
View Code Duplication |
class RuntimeExceptionTest extends \PHPUnit_Framework_TestCase |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var RuntimeException |
24
|
|
|
*/ |
25
|
|
|
private $exception; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
|
|
protected function setUp() |
31
|
|
|
{ |
32
|
|
|
$this->exception = new RuntimeException(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testInheritance() |
36
|
|
|
{ |
37
|
|
|
$this->assertInstanceOf(\RuntimeException::class, $this->exception); |
38
|
|
|
$this->assertInstanceOf(ExceptionInterface::class, $this->exception); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testDefaultState() |
42
|
|
|
{ |
43
|
|
|
$this->assertSame('', $this->exception->getMessage()); |
44
|
|
|
$this->assertSame(0, $this->exception->getCode()); |
45
|
|
|
$this->assertNull($this->exception->getPrevious()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testInitialState() |
49
|
|
|
{ |
50
|
|
|
$this->exception = new RuntimeException($message = 'foo', $code = 123, $previous = new \Exception()); |
51
|
|
|
|
52
|
|
|
$this->assertSame($message, $this->exception->getMessage()); |
53
|
|
|
$this->assertSame($code, $this->exception->getCode()); |
54
|
|
|
$this->assertSame($previous, $this->exception->getPrevious()); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.