1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace SmartWeb\ModuleTesting\Providers; |
5
|
|
|
|
6
|
|
|
use Illuminate\Support\Collection; |
7
|
|
|
use Illuminate\Support\Facades\File; |
8
|
|
|
use Illuminate\Support\ServiceProvider; |
9
|
|
|
use SmartWeb\ModuleTesting\Console\Command\GenerateCest; |
10
|
|
|
use SmartWeb\ModuleTesting\Console\Command\GenerateSetup; |
11
|
|
|
use SmartWeb\ModuleTesting\Console\Command\GenerateTest; |
12
|
|
|
use const DIRECTORY_SEPARATOR; |
13
|
|
|
use function glob; |
14
|
|
|
use function implode; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class TestingServiceProvider |
19
|
|
|
* |
20
|
|
|
* @package SmartWeb\Testing\Providers |
21
|
|
|
*/ |
22
|
|
|
class TestingServiceProvider extends ServiceProvider |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Indicates if loading of the provider is deferred. |
27
|
|
|
* |
28
|
|
|
* @var bool |
29
|
|
|
*/ |
30
|
|
|
protected $defer = false; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Boot the application events. |
34
|
|
|
* |
35
|
|
|
* @return void |
36
|
|
|
*/ |
37
|
|
|
public function boot() |
38
|
|
|
{ |
39
|
|
|
$this->registerConfig(); |
40
|
|
|
$this->registerHelpers(); |
41
|
|
|
$this->registerMacros(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Register the service provider. |
46
|
|
|
* |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
|
|
public function register() |
50
|
|
|
{ |
51
|
|
|
$this->registerCommands(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get the services provided by the provider. |
56
|
|
|
* |
57
|
|
|
* @return array |
58
|
|
|
*/ |
59
|
|
|
public function provides() |
60
|
|
|
{ |
61
|
|
|
return []; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Register config. |
66
|
|
|
* |
67
|
|
|
* @return void |
68
|
|
|
*/ |
69
|
|
|
protected function registerConfig() |
70
|
|
|
{ |
71
|
|
|
$this->publishes([ |
72
|
|
|
__DIR__ . '/../Config/config.php' => config_path('testing.php'), |
73
|
|
|
], 'config'); |
74
|
|
|
$this->mergeConfigFrom( |
75
|
|
|
__DIR__ . '/../Config/config.php', 'testing' |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
protected function registerHelpers() |
80
|
|
|
{ |
81
|
|
|
foreach (glob($this->path('Helpers/*.php')) as $file) { |
82
|
|
|
File::requireOnce($file); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
protected function registerMacros() |
87
|
|
|
{ |
88
|
|
|
Collection::macro('mapInto', function (string $class) |
89
|
|
|
{ |
90
|
|
|
return $this->map(function ($value) use ($class) |
|
|
|
|
91
|
|
|
{ |
92
|
|
|
return new $class($value); |
93
|
|
|
}); |
94
|
|
|
}); |
95
|
|
|
|
96
|
|
|
Collection::macro('mapIntoWithKeys', function (string $class) |
97
|
|
|
{ |
98
|
|
|
return $this->map(function ($value, $key) use ($class) |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
return new $class($value, $key); |
101
|
|
|
}); |
102
|
|
|
}); |
103
|
|
|
|
104
|
|
|
Collection::macro('dd', function () |
105
|
|
|
{ |
106
|
|
|
dd($this); |
107
|
|
|
}); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
protected function registerCommands() |
111
|
|
|
{ |
112
|
|
|
$this->app->singleton( |
113
|
|
|
'command.smartweb.testing.generate-setup', |
114
|
|
|
GenerateSetup::class |
115
|
|
|
); |
116
|
|
|
|
117
|
|
|
$this->app->singleton( |
118
|
|
|
'command.smartweb.testing.generate-test', |
119
|
|
|
GenerateTest::class |
120
|
|
|
); |
121
|
|
|
|
122
|
|
|
$this->app->singleton( |
123
|
|
|
'command.smartweb.testing.generate-cest', |
124
|
|
|
GenerateCest::class |
125
|
|
|
); |
126
|
|
|
|
127
|
|
|
$this->commands( |
128
|
|
|
'command.smartweb.testing.generate-setup', |
129
|
|
|
'command.smartweb.testing.generate-test', |
130
|
|
|
'command.smartweb.testing.generate-cest'); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param string[] ...$parts |
135
|
|
|
* |
136
|
|
|
* @return string |
137
|
|
|
*/ |
138
|
|
|
protected function path(...$parts) : string |
139
|
|
|
{ |
140
|
|
|
return __DIR__ . '/../' . implode(DIRECTORY_SEPARATOR, $parts); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.