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

DrupalKernelPlaceholder::beforeFeature()   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 1
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
     * @return string
73
     */
74
    public static function sitePath()
75
    {
76
        return self::requireContext(__FUNCTION__, func_get_args());
77
    }
78
79
    /**
80
     * @param mixed $data
81
     *
82
     * @return string
83
     */
84
    public static function jsonEncode($data)
85
    {
86
        return self::requireContext(__FUNCTION__, func_get_args());
87
    }
88
89
    /**
90
     * @return object
91
     */
92
    public static function getCurrentUser()
93
    {
94
        return self::requireContext(__FUNCTION__, func_get_args());
95
    }
96
97
    public static function setCurrentUser($user)
98
    {
99
        self::requireContext(__FUNCTION__, func_get_args());
100
    }
101
102
    public static function setCurrentPath($path)
103
    {
104
        self::requireContext(__FUNCTION__, func_get_args());
105
    }
106
107
    /**
108
     * Locate user ID by its name.
109
     *
110
     * @param string $username
111
     *
112
     * @return int
113
     */
114
    public static function getUidByName($username)
115
    {
116
        return self::requireContext(__FUNCTION__, func_get_args());
117
    }
118
119
    /**
120
     * @param int $user_id
121
     */
122
    public static function deleteUser($user_id)
123
    {
124
        self::requireContext(__FUNCTION__, func_get_args());
125
    }
126
127
    /**
128
     * @param string $table
129
     * @param string $alias
130
     * @param array $options
131
     *
132
     * @return object
133
     */
134
    public static function selectQuery($table, $alias = null, array $options = [])
135
    {
136
        return self::requireContext(__FUNCTION__, func_get_args());
137
    }
138
139
    /**
140
     * @param string $entityType
141
     * @param string $bundle
142
     *
143
     * @return array[]
144
     *   An associative array where key - machine-name of a field and
145
     *   value - an array with two keys: "label" and "required".
146
     */
147
    public static function getFieldDefinitions($entityType, $bundle)
148
    {
149
        return self::requireContext(__FUNCTION__, func_get_args());
150
    }
151
152
    /**
153
     * Get information about database connections.
154
     *
155
     * Impossible to use $GLOBALS['databases'] in Drupal 8 since {@link https://www.drupal.org/node/2176621}.
156
     *
157
     * @param string $connection
158
     *   Connection name.
159
     *
160
     * @return array[]
161
     */
162
    public static function getDatabaseConnectionInfo($connection)
163
    {
164
        return self::requireContext(__FUNCTION__, func_get_args());
165
    }
166
167
    /**
168
     * @param string $entityType
169
     *   The type of entity.
170
     * @param array $values
171
     *   Values for entity creation.
172
     *
173
     * @return string[]
174
     *   List with three items in order: entity ID, type and bundle.
175
     */
176
    public static function entityCreate($entityType, array $values)
177
    {
178
        return self::requireContext(__FUNCTION__, func_get_args());
179
    }
180
181
    /**
182
     * @param string $entityType
183
     *   The type of entity.
184
     * @param int $id
185
     *
186
     * @return object|null
187
     */
188
    public static function entityLoad($entityType, $id)
189
    {
190
        return self::requireContext(__FUNCTION__, func_get_args());
191
    }
192
193
    /**
194
     * @param object $entity
195
     * @param string $fieldName
196
     *
197
     * @return bool
198
     */
199
    public static function entityHasField($entity, $fieldName)
200
    {
201
        return self::requireContext(__FUNCTION__, func_get_args());
202
    }
203
204
    /**
205
     * @param object $entity
206
     * @param string $fieldName
207
     *
208
     * @return mixed
209
     */
210
    public static function entityFieldValue($entity, $fieldName)
211
    {
212
        return self::requireContext(__FUNCTION__, func_get_args());
213
    }
214
215
    /**
216
     * Switching the mail system.
217
     *
218
     * @param bool $useTesting
219
     *   Whether testing or standard mail system should be used.
220
     */
221
    public static function switchMailSystem($useTesting)
222
    {
223
        self::requireContext(__FUNCTION__, func_get_args());
224
    }
225
226
    /**
227
     * Get a list of emails, collected by testing mail system.
228
     *
229
     * @return array
230
     */
231
    public static function getEmailMessages()
232
    {
233
        return self::requireContext(__FUNCTION__, func_get_args());
234
    }
235
236
    /**
237
     * Check existence of the content type by its machine name or title.
238
     *
239
     * @param string $contentType
240
     *   Machine name or title of the content type.
241
     *
242
     * @return string
243
     *   Machine name.
244
     */
245
    public static function getContentTypeName($contentType)
246
    {
247
        return self::requireContext(__FUNCTION__, func_get_args());
248
    }
249
250
    /**
251
     * @param string $file
252
     *   Existing file from "src/JavaScript" without ".js" extension.
253
     * @param bool $delete
254
     *   Whether injection should be deleted.
255
     */
256
    public static function injectCustomJavascript($file, $delete = false)
257
    {
258
        self::requireContext(__FUNCTION__, func_get_args());
259
    }
260
261
    /**
262
     * {@inheritdoc}
263
     */
264
    public static function drupalGetFilename($type, $name, $filename = null)
265
    {
266
        return drupal_get_filename($type, $name, $filename);
267
    }
268
269
    /**
270
     * {@inheritdoc}
271
     */
272
    public static function fileUnmanagedDelete($path)
273
    {
274
        return file_unmanaged_delete($path);
275
    }
276
277
    /**
278
     * {@inheritdoc}
279
     */
280
    public static function fileUnmanagedCopy($source, $destination = null, $replace = FILE_EXISTS_RENAME)
281
    {
282
        return file_unmanaged_copy($source, $destination, $replace);
283
    }
284
285
    /**
286
     * Require method execution from context.
287
     *
288
     * @param string $method
289
     *   The name of method.
290
     * @param array $arguments
291
     *   Method's arguments.
292
     *
293
     * @return mixed
294
     */
295
    private static function requireContext($method, array $arguments)
296
    {
297
        $context = str_replace('Kernel', DRUPAL_CORE, __CLASS__);
298
299
        if (method_exists($context, $method)) {
300
            return call_user_func_array([$context, $method], $arguments);
301
        }
302
303
        throw new \BadMethodCallException(sprintf('Method "%s" is not implemented in "%s".', $method, $context));
304
    }
305
}
306