1
|
|
|
<?php |
2
|
|
|
/******************************************************************************* |
3
|
|
|
* This file is part of the GraphQL Bundle package. |
4
|
|
|
* |
5
|
|
|
* (c) YnloUltratech <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
******************************************************************************/ |
10
|
|
|
|
11
|
|
|
namespace Ynlo\GraphQLBundle\Behat\Deprecation; |
12
|
|
|
|
13
|
|
|
use Behat\Testwork\EventDispatcher\Event\SuiteTested; |
14
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Storage a set of deprecation warnings to display to users after finish all tests |
18
|
|
|
*/ |
19
|
|
|
class DeprecationAdviser implements EventSubscriberInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
protected $warnings = []; |
25
|
|
|
|
26
|
|
|
public static function getSubscribedEvents() |
27
|
|
|
{ |
28
|
|
|
return [ |
29
|
|
|
SuiteTested::AFTER => 'dump', |
30
|
|
|
]; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param string $message |
35
|
|
|
* @param null|string $file |
36
|
|
|
* @param int|null $line |
37
|
|
|
*/ |
38
|
|
|
public function addWarning(string $message, ?string $file = null, ?int $line = null) |
39
|
|
|
{ |
40
|
|
|
$warning = new DeprecationWarning($message, $file, $line); |
41
|
|
|
$this->warnings[$warning->getMessage()][] = $warning; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Dump all warning ordered by amount of times triggered |
46
|
|
|
*/ |
47
|
|
|
public function dump() |
48
|
|
|
{ |
49
|
|
|
echo (string) $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function __toString(): string |
53
|
|
|
{ |
54
|
|
|
$message = ''; |
55
|
|
|
if (!empty($this->warnings)) { |
56
|
|
|
uasort( |
57
|
|
|
$this->warnings, |
58
|
|
|
function ($a, $b) { |
59
|
|
|
if (count($a) === count($b)) { |
60
|
|
|
return 0; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return (count($a) > count($b)) ? -1 : 1; |
64
|
|
|
} |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
foreach ($this->warnings as $message => $warnings) { |
68
|
|
|
$count = count($warnings); |
69
|
|
|
$message .= sprintf("%sx: %s\n", $count, $message); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $message; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|