-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathRouteConfigCustomizer.php
More file actions
66 lines (53 loc) · 1.9 KB
/
RouteConfigCustomizer.php
File metadata and controls
66 lines (53 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
declare(strict_types=1);
namespace Shopsys\HttpSmokeTesting;
use Shopsys\HttpSmokeTesting\Exception\RouteNameNotFoundException;
class RouteConfigCustomizer
{
/**
* @param \Shopsys\HttpSmokeTesting\RequestDataSetGenerator[] $requestDataSetGenerators
*/
public function __construct(private readonly array $requestDataSetGenerators)
{
}
/**
* Provided $callback will be called with RouteConfig and RouteInfo as arguments
*
* @see \Shopsys\HttpSmokeTesting\RouteConfig
* @see \Shopsys\HttpSmokeTesting\RouteInfo
*/
public function customize(callable $callback): self
{
foreach ($this->requestDataSetGenerators as $requestDataSetGenerator) {
$callback($requestDataSetGenerator, $requestDataSetGenerator->getRouteInfo());
}
return $this;
}
/**
* Provided $callback will be called with RouteConfig and RouteInfo that matches by route name as arguments
*
* @see \Shopsys\HttpSmokeTesting\RouteConfig
* @see \Shopsys\HttpSmokeTesting\RouteInfo
* @param string|string[] $routeName
*/
public function customizeByRouteName(
string|array $routeName,
callable $callback,
): self {
$routeNames = (array)$routeName;
$foundRouteNames = [];
foreach ($this->requestDataSetGenerators as $requestDataSetGenerator) {
$routeInfo = $requestDataSetGenerator->getRouteInfo();
if (!in_array($routeInfo->getRouteName(), $routeNames, true)) {
continue;
}
$callback($requestDataSetGenerator, $routeInfo);
$foundRouteNames[] = $routeInfo->getRouteName();
}
$notFoundRouteNames = array_diff($routeNames, $foundRouteNames);
if (count($notFoundRouteNames) > 0) {
throw new RouteNameNotFoundException($notFoundRouteNames);
}
return $this;
}
}