Merge pull request #16753 from agh1/consolidated-php-version
[civicrm-core.git] / tests / phpunit / api / v4 / Mock / MockEntityDataStorage.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
11 */
12
13 /**
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 * $Id$
18 *
19 */
20
21
22 namespace api\v4\Mock;
23
24 /**
25 * Simple data backend for mock basic api.
26 */
27 class MockEntityDataStorage {
28
29 private static $data = [];
30
31 private static $nextId = 1;
32
33 public static function get() {
34 return self::$data;
35 }
36
37 public static function write($record) {
38 if (empty($record['id'])) {
39 $record['id'] = self::$nextId++;
40 self::$data[$record['id']] = $record;
41 }
42 else {
43 self::$data[$record['id']] = $record + self::$data[$record['id']];
44 }
45 return $record;
46 }
47
48 public static function delete($record) {
49 unset(self::$data[$record['id']]);
50 return $record;
51 }
52
53 }