1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of PhpUnitGen. |
5
|
|
|
* |
6
|
|
|
* (c) 2017-2018 Paul Thébaud <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace PhpUnitGen\Exception; |
13
|
|
|
|
14
|
|
|
use PhpUnitGen\Configuration\ConfigurationInterface\ConsoleConfigInterface; |
15
|
|
|
use PhpUnitGen\Exception\ExceptionInterface\ExceptionCatcherInterface; |
16
|
|
|
use PhpUnitGen\Report\ReportInterface\ReportInterface; |
17
|
|
|
use Symfony\Component\Console\Style\StyleInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class ExceptionCatcher. |
21
|
|
|
* |
22
|
|
|
* @author Paul Thébaud <[email protected]>. |
23
|
|
|
* @copyright 2017-2018 Paul Thébaud <[email protected]>. |
24
|
|
|
* @license https://opensource.org/licenses/MIT The MIT license. |
25
|
|
|
* @link https://github.com/paul-thebaud/phpunit-generator |
26
|
|
|
* @since Class available since Release 2.0.0. |
27
|
|
|
*/ |
28
|
|
|
class ExceptionCatcher implements ExceptionCatcherInterface |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var ConsoleConfigInterface $config The configuration to use. |
32
|
|
|
*/ |
33
|
|
|
private $config; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var StyleInterface $output The output to display message. |
37
|
|
|
*/ |
38
|
|
|
private $output; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var ReportInterface $report The report to increase the number of ignored errors. |
42
|
|
|
*/ |
43
|
|
|
private $report; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* ExceptionCatcher constructor. |
47
|
|
|
* |
48
|
|
|
* @param ConsoleConfigInterface $config The config to use. |
49
|
|
|
* @param StyleInterface $output The output to use. |
50
|
|
|
* @param ReportInterface $report The report to use. |
51
|
|
|
*/ |
52
|
|
|
public function __construct( |
53
|
|
|
ConsoleConfigInterface $config, |
54
|
|
|
StyleInterface $output, |
55
|
|
|
ReportInterface $report |
56
|
|
|
) { |
57
|
|
|
$this->config = $config; |
58
|
|
|
$this->output = $output; |
59
|
|
|
$this->report = $report; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
|
|
public function catch(Exception $exception, string $path): void |
66
|
|
|
{ |
67
|
|
|
if ($this->config->hasIgnore() |
68
|
|
|
&& $exception instanceof IgnorableException |
69
|
|
|
) { |
70
|
|
|
$this->output->note(sprintf('On file "%s": %s', $path, $exception->getMessage())); |
71
|
|
|
$this->report->increaseIgnoredErrorNumber(); |
72
|
|
|
} else { |
73
|
|
|
throw $exception; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|