forked from shopsys/http-smoke-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouteConfigCustomizer.php
More file actions
67 lines (58 loc) · 2.15 KB
/
RouteConfigCustomizer.php
File metadata and controls
67 lines (58 loc) · 2.15 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
67
<?php
namespace Shopsys\HttpSmokeTesting;
use Shopsys\HttpSmokeTesting\Exception\RouteNameNotFoundException;
class RouteConfigCustomizer
{
/**
* @var \Shopsys\HttpSmokeTesting\RequestDataSetGenerator[]
*/
private $requestDataSetGenerators;
/**
* @param \Shopsys\HttpSmokeTesting\RequestDataSetGenerator[] $requestDataSetGenerators
*/
public function __construct(array $requestDataSetGenerators)
{
$this->requestDataSetGenerators = $requestDataSetGenerators;
}
/**
* Provided $callback will be called with RouteConfig and RouteInfo as arguments
*
* @see \Shopsys\HttpSmokeTesting\RouteConfig
* @see \Shopsys\HttpSmokeTesting\RouteInfo
* @param callable $callback
* @return \Shopsys\HttpSmokeTesting\RouteConfigCustomizer
*/
public function customize($callback)
{
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
* @param callable $callback
* @return \Shopsys\HttpSmokeTesting\RouteConfigCustomizer
*/
public function customizeByRouteName($routeName, $callback)
{
$routeNames = (array)$routeName;
$foundRouteNames = [];
foreach ($this->requestDataSetGenerators as $requestDataSetGenerator) {
$routeInfo = $requestDataSetGenerator->getRouteInfo();
if (in_array($routeInfo->getRouteName(), $routeNames, true)) {
$callback($requestDataSetGenerator, $routeInfo);
$foundRouteNames[] = $routeInfo->getRouteName();
}
}
$notFoundRouteNames = array_diff($routeNames, $foundRouteNames);
if (count($notFoundRouteNames) > 0) {
throw new RouteNameNotFoundException($notFoundRouteNames);
}
return $this;
}
}