Completed
Pull Request — master (#16)
by Sergii
04:51
created

DrupalKernelPlaceholder::getEmailMessages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * @author Sergii Bondarenko, <[email protected]>
4
 */
5
namespace Drupal\TqExtension\Cores;
6
7
use Behat\Behat\Hook\Scope\BeforeFeatureScope;
8
use Drupal\TqExtension\Context\TqContext;
9
10
class DrupalKernelPlaceholder
11
{
12
    /**
13
     * Version-related implementation of @BeforeFeature hook for TqContext.
14
     *
15
     * @param BeforeFeatureScope $scope
16
     *
17
     * @see TqContext::beforeFeature()
18
     */
19
    public static function beforeFeature(BeforeFeatureScope $scope)
20
    {
21
        self::requireContext(__FUNCTION__, func_get_args());
22
    }
23
24
    /**
25
     * @param string $string
26
     * @param array $arguments
27
     * @param array $options
28
     *
29
     * @return string
30
     */
31
    public static function t($string, array $arguments = [], array $options = [])
32
    {
33
        return self::requireContext(__FUNCTION__, func_get_args());
34
    }
35
36
    /**
37
     * @param string $string
38
     * @param array $arguments
39
     *
40
     * @return string
41
     */
42
    public static function formatString($string, array $arguments = [])
43
    {
44
        return self::requireContext(__FUNCTION__, func_get_args());
45
    }
46
47
    /**
48
     * @return string[]
49
     */
50
    public static function arg()
51
    {
52
        return self::requireContext(__FUNCTION__, func_get_args());
53
    }
54
55
    /**
56
     * @param string $text
57
     *   Input text.
58
     * @param array $data
59
     *   Data for replacements.
60
     * @param array $options
61
     *   Replacement configuration.
62
     *
63
     * @return string
64
     *   Processed text.
65
     */
66
    public static function tokenReplace($text, array $data = [], array $options = [])
67
    {
68
        return self::requireContext(__FUNCTION__, func_get_args());
69
    }
70
71
    /**
72
     * @param mixed $data
73
     *
74
     * @return string
75
     */
76
    public static function jsonEncode($data)
77
    {
78
        return self::requireContext(__FUNCTION__, func_get_args());
79
    }
80
81
    /**
82
     * @return object
83
     */
84
    public static function getCurrentUser()
85
    {
86
        return self::requireContext(__FUNCTION__, func_get_args());
87
    }
88
89
    public static function setCurrentUser($user)
90
    {
91
        self::requireContext(__FUNCTION__, func_get_args());
92
    }
93
94
    public static function setCurrentPath($path)
95
    {
96
        self::requireContext(__FUNCTION__, func_get_args());
97
    }
98
99
    /**
100
     * Locate user ID by its name.
101
     *
102
     * @param string $username
103
     *
104
     * @return int
105
     */
106
    public static function getUidByName($username)
107
    {
108
        return self::requireContext(__FUNCTION__, func_get_args());
109
    }
110
111
    /**
112
     * @param int $user_id
113
     */
114
    public static function deleteUser($user_id)
115
    {
116
        self::requireContext(__FUNCTION__, func_get_args());
117
    }
118
119
    /**
120
     * @param string $table
121
     * @param string $alias
122
     * @param array $options
123
     *
124
     * @return object
125
     */
126
    public static function selectQuery($table, $alias = null, array $options = [])
127
    {
128
        return self::requireContext(__FUNCTION__, func_get_args());
129
    }
130
131
    /**
132
     * @param string $entityType
133
     * @param string $bundle
134
     *
135
     * @return array[]
136
     *   An associative array where key - machine-name of a field and
137
     *   value - an array with two keys: "label" and "required".
138
     */
139
    public static function getFieldDefinitions($entityType, $bundle)
140
    {
141
        return self::requireContext(__FUNCTION__, func_get_args());
142
    }
143
144
    /**
145
     * Get information about database connections.
146
     *
147
     * Impossible to use $GLOBALS['databases'] in Drupal 8 since {@link https://www.drupal.org/node/2176621}.
148
     *
149
     * @param string $connection
150
     *   Connection name.
151
     *
152
     * @return array[]
153
     */
154
    public static function getDatabaseConnectionInfo($connection)
155
    {
156
        return (array) self::requireContext(__FUNCTION__, func_get_args());
157
    }
158
159
    /**
160
     * @param string $entityType
161
     *   The type of entity.
162
     * @param array $values
163
     *   Values for entity creation.
164
     *
165
     * @return string[]
166
     *   List with three items in order: entity ID, type and bundle.
167
     */
168
    public static function entityCreate($entityType, array $values)
169
    {
170
        return self::requireContext(__FUNCTION__, func_get_args());
171
    }
172
173
    /**
174
     * @param string $entityType
175
     *   The type of entity.
176
     * @param int $id
177
     *
178
     * @return object|null
179
     */
180
    public static function entityLoad($entityType, $id)
181
    {
182
        return self::requireContext(__FUNCTION__, func_get_args());
183
    }
184
185
    /**
186
     * @param object $entity
187
     * @param string $fieldName
188
     *
189
     * @return bool
190
     */
191
    public static function entityHasField($entity, $fieldName)
192
    {
193
        return self::requireContext(__FUNCTION__, func_get_args());
194
    }
195
196
    /**
197
     * @param object $entity
198
     * @param string $fieldName
199
     *
200
     * @return mixed
201
     */
202
    public static function entityFieldValue($entity, $fieldName)
203
    {
204
        return self::requireContext(__FUNCTION__, func_get_args());
205
    }
206
207
    /**
208
     * Switching the mail system.
209
     *
210
     * @param bool $useTesting
211
     *   Whether testing or standard mail system should be used.
212
     */
213
    public static function switchMailSystem($useTesting)
214
    {
215
        self::requireContext(__FUNCTION__, func_get_args());
216
    }
217
218
    /**
219
     * Get a list of emails, collected by testing mail system.
220
     *
221
     * @return array
222
     */
223
    public static function getEmailMessages()
224
    {
225
        return self::requireContext(__FUNCTION__, func_get_args());
226
    }
227
228
    /**
229
     * Check existence of the content type by its machine name or title.
230
     *
231
     * @param string $contentType
232
     *   Machine name or title of the content type.
233
     *
234
     * @return string
235
     *   Machine name.
236
     */
237
    public static function getContentTypeName($contentType)
238
    {
239
        return self::requireContext(__FUNCTION__, func_get_args());
240
    }
241
242
    /**
243
     * @param string $file
244
     *   Existing file from "src/JavaScript" without ".js" extension.
245
     * @param bool $delete
246
     *   Whether injection should be deleted.
247
     */
248
    public static function injectCustomJavascript($file, $delete = false)
249
    {
250
        self::requireContext(__FUNCTION__, func_get_args());
251
    }
252
253
    /**
254
     * {@inheritdoc}
255
     */
256
    public static function drupalGetFilename($type, $name, $filename = null)
257
    {
258
        return drupal_get_filename($type, $name, $filename);
259
    }
260
261
    /**
262
     * {@inheritdoc}
263
     */
264
    public static function fileUnmanagedDelete($path)
265
    {
266
        return file_unmanaged_delete($path);
267
    }
268
269
    /**
270
     * {@inheritdoc}
271
     */
272
    public static function fileUnmanagedCopy($source, $destination = null, $replace = FILE_EXISTS_RENAME)
273
    {
274
        return file_unmanaged_copy($source, $destination, $replace);
275
    }
276
277
    /**
278
     * @param int $count
279
     *   Number of entries to fetch.
280
     * @param string[] $types
281
     *   Any set of Watchdog error types.
282
     *
283
     * @return array[]
284
     */
285
    public static function getWatchdogStackTrace($count = 10, array $types = ['php'])
286
    {
287
        return array_map('unserialize', static::selectQuery('watchdog', 'w')
288
            ->fields('w', ['variables'])
289
            ->condition('type', $types, 'IN')
290
            ->range(0, $count)
291
            ->execute()
292
            ->fetchCol());
293
    }
294
295
    /**
296
     * Require method execution from context.
297
     *
298
     * @param string $method
299
     *   The name of method.
300
     * @param array $arguments
301
     *   Method's arguments.
302
     *
303
     * @return mixed
304
     */
305
    private static function requireContext($method, array $arguments)
306
    {
307
        $context = str_replace('Kernel', DRUPAL_CORE, __CLASS__);
308
309
        if (method_exists($context, $method)) {
310
            return call_user_func_array([$context, $method], $arguments);
311
        }
312
313
        throw new \BadMethodCallException(sprintf('Method "%s" is not implemented in "%s".', $method, $context));
314
    }
315
}
316