Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 58927f1

Browse files
committedMay 18, 2021
Add ref operators.
1 parent 46a9eda commit 58927f1

File tree

8 files changed

+148
-1
lines changed

8 files changed

+148
-1
lines changed
 

‎src/Parsing/Logging/LogParserTarget.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public function columnCalculatedDefault($tableName, $columnName, $content, $cont
169169
* @param integer $firstColumnNameStartColumn The column number on which the column which contains references started.
170170
* @param integer $firstColumnNameEndLine The line number on which the column which contains references ended.
171171
* @param integer $firstColumnNameEndColumn The column number on which the column which contains references ended.
172+
* @param integer $operator The operator of the ref (see RefOperator::*).
172173
* @param string $secondTableNameOrAlias The name or an alias of the table which contains the column to be referred to.
173174
* @param integer $secondTableNameOrAliasStartLine The line number on which the name or an alias of the table which contains the column to be referred to started.
174175
* @param integer $secondTableNameOrAliasStartColumn The column number on which the name or an alias of the table which contains the column to be referred to started.
@@ -191,6 +192,7 @@ public function ref(
191192
$firstColumnNameStartColumn,
192193
$firstColumnNameEndLine,
193194
$firstColumnNameEndColumn,
195+
$operator,
194196
$secondTableNameOrAlias,
195197
$secondTableNameOrAliasStartLine,
196198
$secondTableNameOrAliasStartColumn,
@@ -213,6 +215,7 @@ public function ref(
213215
$firstColumnNameStartColumn,
214216
$firstColumnNameEndLine,
215217
$firstColumnNameEndColumn,
218+
$operator,
216219
$secondTableNameOrAlias,
217220
$secondTableNameOrAliasStartLine,
218221
$secondTableNameOrAliasStartColumn,

‎src/Parsing/Logging/RefEvent.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ final class RefEvent
6262
*/
6363
public $secondTableNameOrAlias;
6464

65+
/**
66+
* @var integer $operator The operator of the ref (see RefOperator::*).
67+
*/
68+
public $operator;
69+
6570
/**
6671
* @var integer $secondTableNameOrAliasStartLine The line number on which the name or an alias of the table which contains the column to be referred to started.
6772
*/
@@ -118,6 +123,7 @@ final class RefEvent
118123
* @param integer $firstColumnNameStartColumn The column number on which the column which contains references started.
119124
* @param integer $firstColumnNameEndLine The line number on which the column which contains references ended.
120125
* @param integer $firstColumnNameEndColumn The column number on which the column which contains references ended.
126+
* @param integer $operator The operator of the ref (see RefOperator::*).
121127
* @param string $secondTableNameOrAlias The name or an alias of the table which contains the column to be referred to.
122128
* @param integer $secondTableNameOrAliasStartLine The line number on which the name or an alias of the table which contains the column to be referred to started.
123129
* @param integer $secondTableNameOrAliasStartColumn The column number on which the name or an alias of the table which contains the column to be referred to started.
@@ -140,6 +146,7 @@ function __construct(
140146
$firstColumnNameStartColumn,
141147
$firstColumnNameEndLine,
142148
$firstColumnNameEndColumn,
149+
$operator,
143150
$secondTableNameOrAlias,
144151
$secondTableNameOrAliasStartLine,
145152
$secondTableNameOrAliasStartColumn,
@@ -161,6 +168,7 @@ function __construct(
161168
$this->firstColumnNameStartColumn = $firstColumnNameStartColumn;
162169
$this->firstColumnNameEndLine = $firstColumnNameEndLine;
163170
$this->firstColumnNameEndColumn = $firstColumnNameEndColumn;
171+
$this->operator = $operator;
164172
$this->secondTableNameOrAlias = $secondTableNameOrAlias;
165173
$this->secondTableNameOrAliasStartLine = $secondTableNameOrAliasStartLine;
166174
$this->secondTableNameOrAliasStartColumn = $secondTableNameOrAliasStartColumn;

‎src/Parsing/MultiParserTarget.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ public function columnCalculatedDefault($tableName, $columnName, $content, $cont
197197
* @param integer $firstColumnNameStartColumn The column number on which the column which contains references started.
198198
* @param integer $firstColumnNameEndLine The line number on which the column which contains references ended.
199199
* @param integer $firstColumnNameEndColumn The column number on which the column which contains references ended.
200+
* @param integer $operator The operator of the ref (see RefOperator::*).
200201
* @param string $secondTableNameOrAlias The name or an alias of the table which contains the column to be referred to.
201202
* @param integer $secondTableNameOrAliasStartLine The line number on which the name or an alias of the table which contains the column to be referred to started.
202203
* @param integer $secondTableNameOrAliasStartColumn The column number on which the name or an alias of the table which contains the column to be referred to started.
@@ -219,6 +220,7 @@ public function ref(
219220
$firstColumnNameStartColumn,
220221
$firstColumnNameEndLine,
221222
$firstColumnNameEndColumn,
223+
$operator,
222224
$secondTableNameOrAlias,
223225
$secondTableNameOrAliasStartLine,
224226
$secondTableNameOrAliasStartColumn,
@@ -242,6 +244,7 @@ public function ref(
242244
$firstColumnNameStartColumn,
243245
$firstColumnNameEndLine,
244246
$firstColumnNameEndColumn,
247+
$operator,
245248
$secondTableNameOrAlias,
246249
$secondTableNameOrAliasStartLine,
247250
$secondTableNameOrAliasStartColumn,

‎src/Parsing/ParserTarget.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public function columnCalculatedDefault($tableName, $columnName, $content, $cont
132132
* @param integer $firstColumnNameStartColumn The column number on which the column which contains references started.
133133
* @param integer $firstColumnNameEndLine The line number on which the column which contains references ended.
134134
* @param integer $firstColumnNameEndColumn The column number on which the column which contains references ended.
135+
* @param integer $operator The operator of the ref (see RefOperator::*).
135136
* @param string $secondTableNameOrAlias The name or an alias of the table which contains the column to be referred to.
136137
* @param integer $secondTableNameOrAliasStartLine The line number on which the name or an alias of the table which contains the column to be referred to started.
137138
* @param integer $secondTableNameOrAliasStartColumn The column number on which the name or an alias of the table which contains the column to be referred to started.
@@ -154,6 +155,7 @@ public function ref(
154155
$firstColumnNameStartColumn,
155156
$firstColumnNameEndLine,
156157
$firstColumnNameEndColumn,
158+
$operator,
157159
$secondTableNameOrAlias,
158160
$secondTableNameOrAliasStartLine,
159161
$secondTableNameOrAliasStartColumn,

‎src/Parsing/RefOperator.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace JamesWildDev\DBMLParser\Parsing;
4+
5+
/**
6+
* Values which identify the operator of a ref.
7+
*/
8+
class RefOperator
9+
{
10+
/**
11+
* The first table/column refers to the second table/column. For each row in the second table, there can be any number in the first.
12+
*/
13+
const MANY_TO_ONE = 0;
14+
15+
/**
16+
* The second table/column refers to the first table/column. For each row in the first table, there can be any number in the second.
17+
*/
18+
const ONE_TO_MANY = 1;
19+
20+
/**
21+
* The first table/column and second table/column share a one-to-one relationship.
22+
*/
23+
const ONE_TO_ONE = 2;
24+
}

‎tests/Unit/Parsing/Logging/LogParserTargetTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use JamesWildDev\DBMLParser\Parsing\Logging\TableAliasEvent;
1919
use JamesWildDev\DBMLParser\Parsing\Logging\TableEvent;
2020
use JamesWildDev\DBMLParser\Parsing\Logging\TableNoteEvent;
21+
use JamesWildDev\DBMLParser\Parsing\RefOperator;
2122
use PHPUnit\Framework\TestCase;
2223

2324
final class LogParserTargetTest extends TestCase
@@ -107,6 +108,7 @@ public function test_logs_all_events()
107108
92,
108109
25,
109110
70,
111+
RefOperator::ONE_TO_ONE,
110112
'Test Ref Second Table Name Or Alias',
111113
104,
112114
160,
@@ -259,6 +261,7 @@ public function test_logs_all_events()
259261
92,
260262
25,
261263
70,
264+
RefOperator::ONE_TO_ONE,
262265
'Test Ref Second Table Name Or Alias',
263266
104,
264267
160,

‎tests/Unit/Parsing/Logging/RefEventTest.php

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace JamesWildDev\DBMLParser\Tests\Unit\Parsing\Logging;
44

55
use JamesWildDev\DBMLParser\Parsing\Logging\RefEvent;
6+
use JamesWildDev\DBMLParser\Parsing\RefOperator;
67
use PHPUnit\Framework\TestCase;
78

89
final class RefEventTest extends TestCase
910
{
10-
public function test()
11+
public function test_one_to_many()
1112
{
1213
$refEvent = new RefEvent(
1314
'Test First Table Name Or Alias',
@@ -20,6 +21,7 @@ public function test()
2021
88,
2122
54,
2223
21,
24+
RefOperator::ONE_TO_MANY,
2325
'Test Second Table Name Or Alias',
2426
22,
2527
46,
@@ -42,6 +44,105 @@ public function test()
4244
$this->assertEquals(88, $refEvent->firstColumnNameStartColumn);
4345
$this->assertEquals(54, $refEvent->firstColumnNameEndLine);
4446
$this->assertEquals(21, $refEvent->firstColumnNameEndColumn);
47+
$this->assertEquals(RefOperator::ONE_TO_MANY, $refEvent->operator);
48+
$this->assertEquals('Test Second Table Name Or Alias', $refEvent->secondTableNameOrAlias);
49+
$this->assertEquals(22, $refEvent->secondTableNameOrAliasStartLine);
50+
$this->assertEquals(46, $refEvent->secondTableNameOrAliasStartColumn);
51+
$this->assertEquals(73, $refEvent->secondTableNameOrAliasEndLine);
52+
$this->assertEquals(47, $refEvent->secondTableNameOrAliasEndColumn);
53+
$this->assertEquals('Test Second Column Name', $refEvent->secondColumnName);
54+
$this->assertEquals(12, $refEvent->secondColumnNameStartLine);
55+
$this->assertEquals(54, $refEvent->secondColumnNameStartColumn);
56+
$this->assertEquals(33, $refEvent->secondColumnNameEndLine);
57+
$this->assertEquals(72, $refEvent->secondColumnNameEndColumn);
58+
}
59+
60+
public function test_one_to_one()
61+
{
62+
$refEvent = new RefEvent(
63+
'Test First Table Name Or Alias',
64+
24,
65+
84,
66+
37,
67+
11,
68+
'Test First Column Name',
69+
101,
70+
88,
71+
54,
72+
21,
73+
RefOperator::ONE_TO_ONE,
74+
'Test Second Table Name Or Alias',
75+
22,
76+
46,
77+
73,
78+
47,
79+
'Test Second Column Name',
80+
12,
81+
54,
82+
33,
83+
72
84+
);
85+
86+
$this->assertEquals('Test First Table Name Or Alias', $refEvent->firstTableNameOrAlias);
87+
$this->assertEquals(24, $refEvent->firstTableNameOrAliasStartLine);
88+
$this->assertEquals(84, $refEvent->firstTableNameOrAliasStartColumn);
89+
$this->assertEquals(37, $refEvent->firstTableNameOrAliasEndLine);
90+
$this->assertEquals(11, $refEvent->firstTableNameOrAliasEndColumn);
91+
$this->assertEquals('Test First Column Name', $refEvent->firstColumnName);
92+
$this->assertEquals(101, $refEvent->firstColumnNameStartLine);
93+
$this->assertEquals(88, $refEvent->firstColumnNameStartColumn);
94+
$this->assertEquals(54, $refEvent->firstColumnNameEndLine);
95+
$this->assertEquals(21, $refEvent->firstColumnNameEndColumn);
96+
$this->assertEquals(RefOperator::ONE_TO_ONE, $refEvent->operator);
97+
$this->assertEquals('Test Second Table Name Or Alias', $refEvent->secondTableNameOrAlias);
98+
$this->assertEquals(22, $refEvent->secondTableNameOrAliasStartLine);
99+
$this->assertEquals(46, $refEvent->secondTableNameOrAliasStartColumn);
100+
$this->assertEquals(73, $refEvent->secondTableNameOrAliasEndLine);
101+
$this->assertEquals(47, $refEvent->secondTableNameOrAliasEndColumn);
102+
$this->assertEquals('Test Second Column Name', $refEvent->secondColumnName);
103+
$this->assertEquals(12, $refEvent->secondColumnNameStartLine);
104+
$this->assertEquals(54, $refEvent->secondColumnNameStartColumn);
105+
$this->assertEquals(33, $refEvent->secondColumnNameEndLine);
106+
$this->assertEquals(72, $refEvent->secondColumnNameEndColumn);
107+
}
108+
109+
public function test_many_to_one()
110+
{
111+
$refEvent = new RefEvent(
112+
'Test First Table Name Or Alias',
113+
24,
114+
84,
115+
37,
116+
11,
117+
'Test First Column Name',
118+
101,
119+
88,
120+
54,
121+
21,
122+
RefOperator::MANY_TO_ONE,
123+
'Test Second Table Name Or Alias',
124+
22,
125+
46,
126+
73,
127+
47,
128+
'Test Second Column Name',
129+
12,
130+
54,
131+
33,
132+
72
133+
);
134+
135+
$this->assertEquals('Test First Table Name Or Alias', $refEvent->firstTableNameOrAlias);
136+
$this->assertEquals(24, $refEvent->firstTableNameOrAliasStartLine);
137+
$this->assertEquals(84, $refEvent->firstTableNameOrAliasStartColumn);
138+
$this->assertEquals(37, $refEvent->firstTableNameOrAliasEndLine);
139+
$this->assertEquals(11, $refEvent->firstTableNameOrAliasEndColumn);
140+
$this->assertEquals('Test First Column Name', $refEvent->firstColumnName);
141+
$this->assertEquals(101, $refEvent->firstColumnNameStartLine);
142+
$this->assertEquals(88, $refEvent->firstColumnNameStartColumn);
143+
$this->assertEquals(54, $refEvent->firstColumnNameEndLine);
144+
$this->assertEquals(21, $refEvent->firstColumnNameEndColumn);
145+
$this->assertEquals(RefOperator::MANY_TO_ONE, $refEvent->operator);
45146
$this->assertEquals('Test Second Table Name Or Alias', $refEvent->secondTableNameOrAlias);
46147
$this->assertEquals(22, $refEvent->secondTableNameOrAliasStartLine);
47148
$this->assertEquals(46, $refEvent->secondTableNameOrAliasStartColumn);

‎tests/Unit/Parsing/MultiParserTargetTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use JamesWildDev\DBMLParser\Parsing\Logging\TableEvent;
2020
use JamesWildDev\DBMLParser\Parsing\Logging\TableNoteEvent;
2121
use JamesWildDev\DBMLParser\Parsing\MultiParserTarget;
22+
use JamesWildDev\DBMLParser\Parsing\RefOperator;
2223
use PHPUnit\Framework\TestCase;
2324

2425
final class MultiParserTargetTest extends TestCase
@@ -125,6 +126,7 @@ public function test_replicates_all_events()
125126
92,
126127
25,
127128
70,
129+
RefOperator::ONE_TO_ONE,
128130
'Test Ref Second Table Name Or Alias',
129131
104,
130132
160,
@@ -277,6 +279,7 @@ public function test_replicates_all_events()
277279
92,
278280
25,
279281
70,
282+
RefOperator::ONE_TO_ONE,
280283
'Test Ref Second Table Name Or Alias',
281284
104,
282285
160,

0 commit comments

Comments
 (0)
Please sign in to comment.