Merge "Rewrite ReferenceStackTest::provideRollbackRefs for readability"

This commit is contained in:
jenkins-bot 2020-01-09 12:53:34 +00:00 committed by Gerrit Code Review
commit d18fbcffef

View file

@ -832,133 +832,130 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
public function testRollbackRefs(
array $initialCallStack,
array $initialRefs,
int $count,
?array $expectedRedo,
?array $expectedRefs,
?string $expectedException
int $rollbackCount,
$expectedResult,
array $expectedRefs = []
) {
$stack = $this->newStack();
$stack->refCallStack = $initialCallStack;
$stack->refs = $initialRefs;
if ( $expectedException ) {
if ( is_string( $expectedResult ) ) {
$this->expectException( LogicException::class );
$this->expectExceptionMessage( $expectedException );
$this->expectExceptionMessage( $expectedResult );
}
$redo = $stack->rollbackRefs( $count );
$this->assertSame( $expectedRedo, $redo );
$redoStack = $stack->rollbackRefs( $rollbackCount );
$this->assertSame( $expectedResult, $redoStack );
$this->assertSame( $expectedRefs, $stack->refs );
}
public function provideRollbackRefs() {
return [
'Empty stack' => [ [], [], 0, [], [], null ],
'Attempt to overflow stack bounds' => [ [], [], 1, [], [], null ],
'Skip invalid refs' => [ [ false ], [], 1, [], [], null ],
'Empty stack' => [
'initialCallStack' => [],
'initialRefs' => [],
'rollbackCount' => 0,
'expectedResult' => [],
'expectedRefs' => [],
],
'Attempt to overflow stack bounds' => [
'initialCallStack' => [],
'initialRefs' => [],
'rollbackCount' => 1,
'expectedResult' => [],
'expectedRefs' => [],
],
'Skip invalid refs' => [
'initialCallStack' => [ false ],
'initialRefs' => [],
'rollbackCount' => 1,
'expectedResult' => [],
'expectedRefs' => [],
],
'Missing group' => [
[
'initialCallStack' => [
[ 'new', 1, 'foo', null, null, 'text', [] ],
],
[],
1,
null,
null,
'Cannot roll back ref with unknown group "foo".',
'initialRefs' => [],
'rollbackCount' => 1,
'expectedResult' => 'Cannot roll back ref with unknown group "foo".',
],
'Find anonymous ref by key' => [
[
'initialCallStack' => [
[ 'new', 1, 'foo', null, null, 'text', [] ],
],
[
'foo' => [
'initialRefs' => [ 'foo' => [
[
'key' => 1,
]
]
],
1,
[
[ 'text', [] ]
] ],
'rollbackCount' => 1,
'expectedResult' => [
[ 'text', [] ],
],
[],
null
'expectedRefs' => [],
],
'Missing anonymous ref' => [
[
'initialCallStack' => [
[ 'new', 1, 'foo', null, null, 'text', [] ],
],
[
'foo' => [
'initialRefs' => [ 'foo' => [
[
'key' => 2,
]
]
],
1,
null,
null,
'Cannot roll back unknown ref by key 1.',
] ],
'rollbackCount' => 1,
'expectedResult' => 'Cannot roll back unknown ref by key 1.',
],
'Assign text' => [
[
'initialCallStack' => [
[ 'assign', 1, 'foo', null, null, 'text-2', [] ],
],
[
'foo' => [
'initialRefs' => [ 'foo' => [
[
'count' => 2,
'key' => 1,
'text' => 'text-1',
]
]
],
1,
[
[ 'text-2', [] ]
] ],
'rollbackCount' => 1,
'expectedResult' => [
[ 'text-2', [] ],
],
[
'foo' => [
'expectedRefs' => [ 'foo' => [
[
'count' => 1,
'key' => 1,
'text' => null,
]
]
],
null
] ],
],
'Increment' => [
[
'initialCallStack' => [
[ 'increment', 1, 'foo', null, null, null, [] ],
],
[
'foo' => [
'initialRefs' => [ 'foo' => [
[
'count' => 2,
'key' => 1,
]
]
],
1,
[
[ null, [] ]
] ],
'rollbackCount' => 1,
'expectedResult' => [
[ null, [] ],
],
[
'foo' => [
'expectedRefs' => [ 'foo' => [
[
'count' => 1,
'key' => 1,
]
]
],
null
] ],
],
'Safely ignore placeholder' => [
[
'initialCallStack' => [
[ 'increment', 1, 'foo', null, null, null, [] ],
],
[
'foo' => [
'initialRefs' => [ 'foo' => [
[
'placeholder' => true,
'number' => 10,
@ -966,15 +963,13 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
[
'count' => 2,
'key' => 1,
]
]
],
1,
[
[ null, [] ]
] ],
'rollbackCount' => 1,
'expectedResult' => [
[ null, [] ],
],
[
'foo' => [
'expectedRefs' => [ 'foo' => [
[
'placeholder' => true,
'number' => 10,
@ -982,10 +977,8 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
[
'count' => 1,
'key' => 1,
]
]
],
null
] ],
],
];
}