-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathArgumentObject.php
122 lines (110 loc) · 2.86 KB
/
ArgumentObject.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\FunctionalTestingFramework\Test\Objects;
/**
* Class ArgumentObject
*/
class ArgumentObject
{
const ARGUMENT_NAME = 'name';
const ARGUMENT_DEFAULT_VALUE = 'defaultValue';
const ARGUMENT_DATA_TYPE = 'type';
const ARGUMENT_DATA_ENTITY = 'entity';
const ARGUMENT_DATA_STRING = 'string';
/**
* Name of the argument.
* @var string
*/
private $name;
/**
* Value of the argument. DefaultValue on argument creation
* @var string
*/
private $value;
/**
* Data type of the argument.
* @var string
*/
private $dataType;
/**
* ArgumentObject constructor.
* @param string $name
* @param string $value
* @param string $dataType
*/
public function __construct($name, $value, $dataType)
{
$this->name = $name;
$this->value = $value;
$this->dataType = $dataType;
}
/**
* Function to return string property name.
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Function to return string property value.
* @return string
*/
public function getValue()
{
return $this->value;
}
/**
* Function to return string property dataType.
* @return string
*/
public function getDataType()
{
return $this->dataType;
}
/**
* Override's private string property value.
* @param string $value
* @return void
*/
public function overrideValue($value)
{
$this->value = $value;
}
/**
* Returns the resolved value that the argument needs to have, depending on scope of where argument is referenced.
* @param boolean $isInnerArgument
* @return string
*/
public function getResolvedValue($isInnerArgument)
{
if ($this->dataType === ArgumentObject::ARGUMENT_DATA_ENTITY) {
return $this->value;
} else {
return $this->resolveStringArgument($isInnerArgument);
}
}
/**
* Resolves simple string arguments and returns the appropriate format for simple replacement.
* Takes in boolean to determine if the replacement is being done with an inner argument (as in if it's a parameter)
*
* Example Type Non Inner Inner
* {{XML.DATA}}: {{XML.DATA}} XML.DATA
* $TEST.DATA$: $TEST.DATA$ $TEST.DATA$
* stringLiteral stringLiteral 'stringLiteral'
*
* @param boolean $isInnerArgument
* @return string
*/
private function resolveStringArgument($isInnerArgument)
{
if ($isInnerArgument) {
return "'" . $this->value . "'";
} else {
return $this->value;
}
}
}