Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F120278338
PhabricatorOwnersPackageTestCase.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Jul 3, 05:19
Size
5 KB
Mime Type
text/x-php
Expires
Sat, Jul 5, 05:19 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
27123992
Attached To
rPH Phabricator
PhabricatorOwnersPackageTestCase.php
View Options
<?php
final
class
PhabricatorOwnersPackageTestCase
extends
PhabricatorTestCase
{
public
function
testFindLongestPathsPerPackage
()
{
$rows
=
array
(
array
(
'id'
=>
1
,
'excluded'
=>
0
,
'dominion'
=>
PhabricatorOwnersPackage
::
DOMINION_STRONG
,
'path'
=>
'src/'
,
),
array
(
'id'
=>
1
,
'excluded'
=>
1
,
'dominion'
=>
PhabricatorOwnersPackage
::
DOMINION_STRONG
,
'path'
=>
'src/releeph/'
,
),
array
(
'id'
=>
2
,
'excluded'
=>
0
,
'dominion'
=>
PhabricatorOwnersPackage
::
DOMINION_STRONG
,
'path'
=>
'src/releeph/'
,
),
);
$paths
=
array
(
'src/'
=>
array
(
'src/a.php'
=>
true
,
'src/releeph/b.php'
=>
true
),
'src/releeph/'
=>
array
(
'src/releeph/b.php'
=>
true
),
);
$this
->
assertEqual
(
array
(
1
=>
strlen
(
'src/'
),
2
=>
strlen
(
'src/releeph/'
),
),
PhabricatorOwnersPackage
::
findLongestPathsPerPackage
(
$rows
,
$paths
));
$paths
=
array
(
'src/'
=>
array
(
'src/releeph/b.php'
=>
true
),
'src/releeph/'
=>
array
(
'src/releeph/b.php'
=>
true
),
);
$this
->
assertEqual
(
array
(
2
=>
strlen
(
'src/releeph/'
),
),
PhabricatorOwnersPackage
::
findLongestPathsPerPackage
(
$rows
,
$paths
));
// Test packages with weak dominion. Here, only package #2 should own the
// path. Package #1's claim is ceded to Package #2 because it uses weak
// rules. Package #2 gets the claim even though it also has weak rules
// because there is no more-specific package.
$rows
=
array
(
array
(
'id'
=>
1
,
'excluded'
=>
0
,
'dominion'
=>
PhabricatorOwnersPackage
::
DOMINION_WEAK
,
'path'
=>
'src/'
,
),
array
(
'id'
=>
2
,
'excluded'
=>
0
,
'dominion'
=>
PhabricatorOwnersPackage
::
DOMINION_WEAK
,
'path'
=>
'src/applications/'
,
),
);
$pvalue
=
array
(
'src/applications/main/main.c'
=>
true
);
$paths
=
array
(
'src/'
=>
$pvalue
,
'src/applications/'
=>
$pvalue
,
);
$this
->
assertEqual
(
array
(
2
=>
strlen
(
'src/applications/'
),
),
PhabricatorOwnersPackage
::
findLongestPathsPerPackage
(
$rows
,
$paths
));
// Now, add a more specific path to Package #1. This tests nested ownership
// in packages with weak dominion rules. This time, Package #1 should end
// up back on top, with Package #2 ceding control to its more specific
// path.
$rows
[]
=
array
(
'id'
=>
1
,
'excluded'
=>
0
,
'dominion'
=>
PhabricatorOwnersPackage
::
DOMINION_WEAK
,
'path'
=>
'src/applications/main/'
,
);
$paths
[
'src/applications/main/'
]
=
$pvalue
;
$this
->
assertEqual
(
array
(
1
=>
strlen
(
'src/applications/main/'
),
),
PhabricatorOwnersPackage
::
findLongestPathsPerPackage
(
$rows
,
$paths
));
// Test cases where multiple packages own the same path, with various
// dominion rules.
$main_c
=
'src/applications/main/main.c'
;
$rules
=
array
(
// All claims strong.
array
(
PhabricatorOwnersPackage
::
DOMINION_STRONG
,
PhabricatorOwnersPackage
::
DOMINION_STRONG
,
PhabricatorOwnersPackage
::
DOMINION_STRONG
,
),
// All claims weak.
array
(
PhabricatorOwnersPackage
::
DOMINION_WEAK
,
PhabricatorOwnersPackage
::
DOMINION_WEAK
,
PhabricatorOwnersPackage
::
DOMINION_WEAK
,
),
// Mixture of strong and weak claims, strong first.
array
(
PhabricatorOwnersPackage
::
DOMINION_STRONG
,
PhabricatorOwnersPackage
::
DOMINION_STRONG
,
PhabricatorOwnersPackage
::
DOMINION_WEAK
,
),
// Mixture of strong and weak claims, weak first.
array
(
PhabricatorOwnersPackage
::
DOMINION_WEAK
,
PhabricatorOwnersPackage
::
DOMINION_STRONG
,
PhabricatorOwnersPackage
::
DOMINION_STRONG
,
),
);
foreach
(
$rules
as
$rule_idx
=>
$rule
)
{
$rows
=
array
(
array
(
'id'
=>
1
,
'excluded'
=>
0
,
'dominion'
=>
$rule
[
0
],
'path'
=>
$main_c
,
),
array
(
'id'
=>
2
,
'excluded'
=>
0
,
'dominion'
=>
$rule
[
1
],
'path'
=>
$main_c
,
),
array
(
'id'
=>
3
,
'excluded'
=>
0
,
'dominion'
=>
$rule
[
2
],
'path'
=>
$main_c
,
),
);
$paths
=
array
(
$main_c
=>
$pvalue
,
);
// If one or more packages have strong dominion, they should own the
// path. If not, all the packages with weak dominion should own the
// path.
$strong
=
array
();
$weak
=
array
();
foreach
(
$rule
as
$idx
=>
$dominion
)
{
if
(
$dominion
==
PhabricatorOwnersPackage
::
DOMINION_STRONG
)
{
$strong
[]
=
$idx
+
1
;
}
else
{
$weak
[]
=
$idx
+
1
;
}
}
if
(
$strong
)
{
$expect
=
$strong
;
}
else
{
$expect
=
$weak
;
}
$expect
=
array_fill_keys
(
$expect
,
strlen
(
$main_c
));
$actual
=
PhabricatorOwnersPackage
::
findLongestPathsPerPackage
(
$rows
,
$paths
);
ksort
(
$actual
);
$this
->
assertEqual
(
$expect
,
$actual
,
pht
(
'Ruleset "%s" for Identical Ownership'
,
$rule_idx
));
}
}
}
Event Timeline
Log In to Comment