comparison core/modules/migrate/tests/src/Unit/TestMigrateExecutable.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\Tests\migrate\Unit;
4
5 use Drupal\Core\StringTranslation\TranslationInterface;
6 use Drupal\migrate\MigrateExecutable;
7
8 /**
9 * Tests MigrateExecutable.
10 */
11 class TestMigrateExecutable extends MigrateExecutable {
12
13 /**
14 * The fake memory usage in bytes.
15 *
16 * @var int
17 */
18 protected $memoryUsage;
19
20 /**
21 * The cleared memory usage.
22 *
23 * @var int
24 */
25 protected $clearedMemoryUsage;
26
27 /**
28 * Sets the string translation service.
29 *
30 * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
31 * The translation manager.
32 */
33 public function setStringTranslation(TranslationInterface $string_translation) {
34 $this->stringTranslation = $string_translation;
35 }
36
37 /**
38 * Allows access to set protected source property.
39 *
40 * @param \Drupal\migrate\Plugin\MigrateSourceInterface $source
41 * The value to set.
42 */
43 public function setSource($source) {
44 $this->source = $source;
45 }
46
47 /**
48 * Allows access to protected sourceIdValues property.
49 *
50 * @param array $source_id_values
51 * The values to set.
52 */
53 public function setSourceIdValues($source_id_values) {
54 $this->sourceIdValues = $source_id_values;
55 }
56
57 /**
58 * {@inheritdoc}
59 */
60 public function handleException(\Exception $exception, $save = TRUE) {
61 $message = $exception->getMessage();
62 if ($save) {
63 $this->saveMessage($message);
64 }
65 $this->message->display($message);
66 }
67
68 /**
69 * Allows access to the protected memoryExceeded method.
70 *
71 * @return bool
72 * The memoryExceeded value.
73 */
74 public function memoryExceeded() {
75 return parent::memoryExceeded();
76 }
77
78 /**
79 * {@inheritdoc}
80 */
81 protected function attemptMemoryReclaim() {
82 return $this->clearedMemoryUsage;
83 }
84
85 /**
86 * {@inheritdoc}
87 */
88 protected function getMemoryUsage() {
89 return $this->memoryUsage;
90 }
91
92 /**
93 * Sets the fake memory usage.
94 *
95 * @param int $memory_usage
96 * The fake memory usage value.
97 * @param int $cleared_memory_usage
98 * (optional) The fake cleared memory value. Defaults to NULL.
99 */
100 public function setMemoryUsage($memory_usage, $cleared_memory_usage = NULL) {
101 $this->memoryUsage = $memory_usage;
102 $this->clearedMemoryUsage = $cleared_memory_usage;
103 }
104
105 /**
106 * Sets the memory limit.
107 *
108 * @param int $memory_limit
109 * The memory limit.
110 */
111 public function setMemoryLimit($memory_limit) {
112 $this->memoryLimit = $memory_limit;
113 }
114
115 /**
116 * Sets the memory threshold.
117 *
118 * @param float $threshold
119 * The new threshold.
120 */
121 public function setMemoryThreshold($threshold) {
122 $this->memoryThreshold = $threshold;
123 }
124
125 /**
126 * {@inheritdoc}
127 */
128 protected function formatSize($size) {
129 return $size;
130 }
131
132 }