Hoa central
Public Member Functions | List of all members
Hoa\Ruler\Test\Unit\Documentation Class Reference
Inheritance diagram for Hoa\Ruler\Test\Unit\Documentation:

Public Member Functions

 case_classical ()
 
 next_case_classical ($ruler, $rule)
 
 case_new_operators ()
 
 case_interpret ()
 
 case_compile ()
 
- Public Member Functions inherited from Hoa\Test\Unit\Suite
 __construct ()
 
 getTestedClassName ()
 
 getTestedClassNamespace ()
 
 beforeTestMethod ($methodName)
 

Detailed Description

Class .

Test suite of the examples in the documentation.

Definition at line 50 of file Documentation.php.

Member Function Documentation

Hoa\Ruler\Test\Unit\Documentation::case_classical ( )

Definition at line 52 of file Documentation.php.

53  {
54  $this
55  ->given(
56  $ruler = new LUT(),
57  $rule = 'group in ["customer", "guest"] and points > 30'
58  );
59 
60  $this->next_case_classical($ruler, $rule);
61  }

Here is the call graph for this function:

Hoa\Ruler\Test\Unit\Documentation::case_compile ( )

Definition at line 136 of file Documentation.php.

137  {
138  $expectedResult = <<<'RESULT'
139 $model = new \Hoa\Ruler\Model();
140 $model->expression =
141  $model->and(
142  $model->func(
143  'logged',
144  $model->variable('user')
145  ),
146  $model->and(
147  $model->in(
148  $model->variable('group'),
149  [
150  'customer',
151  'guest'
152  ]
153  ),
154  $model->{'>'}(
155  $model->variable('points'),
156  30
157  )
158  )
159  );
160 RESULT;
161 
162  $this
163  ->when($result = LUT::interpret(
164  'logged(user) and group in ["customer", "guest"] and points > 30'
165  ) . '')
166  ->then
167  ->string($result)
168  ->isEqualTo($expectedResult);
169  }
Hoa\Ruler\Test\Unit\Documentation::case_interpret ( )

Definition at line 122 of file Documentation.php.

123  {
124  $this
125  ->given(
126  $model = LUT::interpret('group in ["customer", "guest"] and points > 30')
127  )
128  ->when($ledom = unserialize(serialize($model)))
129  ->then
130  ->object($model)
131  ->isEqualTo($ledom);
132 
133  $this->next_case_classical(new LUT(), $model);
134  }

Here is the call graph for this function:

Hoa\Ruler\Test\Unit\Documentation::case_new_operators ( )

Definition at line 87 of file Documentation.php.

88  {
89  $this
90  ->given(
91  $user = new \Mock\StdClass(),
92  $user->group = 'customer',
93  $user->points = 42,
94  $user->status = true,
95  $ruler = new LUT(),
96  $rule = 'logged(user) and group in ["customer", "guest"] and points > 30',
97  $context = new LUT\Context(),
98  $context['user'] = function () use ($user, $context) {
99  $context['group'] = $user->group;
100  $context['points'] = $user->points;
101 
102  return $user;
103  }
104  )
105  ->when(
106  $ruler->getDefaultAsserter()->setOperator('logged', function ($user) {
107  return $user->status;
108  }),
109  $result = $ruler->assert($rule, $context)
110  )
111  ->then
112  ->boolean($result)
113  ->isTrue()
114 
115  ->given($user->status = false)
116  ->when($result = $ruler->assert($rule, $context))
117  ->then
118  ->boolean($result)
119  ->isFalse();
120  }
Hoa\Ruler\Test\Unit\Documentation::next_case_classical (   $ruler,
  $rule 
)

Definition at line 63 of file Documentation.php.

64  {
65  $this
66  ->given(
67  $context = new LUT\Context(),
68  $context['group'] = $this->sample(
69  $this->realdom->regex('/customer|guest/')
70  ),
71  $context['points'] = function () {
72  return 42;
73  }
74  )
75  ->when($result = $ruler->assert($rule, $context))
76  ->then
77  ->boolean($result)
78  ->isTrue()
79 
80  ->given($context['points'] = 29)
81  ->when($result = $ruler->assert($rule, $context))
82  ->then
83  ->boolean($result)
84  ->isFalse();
85  }

Here is the caller graph for this function:


The documentation for this class was generated from the following file: