Skip to content

Commit

Permalink
unwrap array (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored Sep 29, 2024
1 parent 1fdbd38 commit 3995add
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class SingleMatch extends TestCase
$someServiceMock = $this->createMock(SomeMockedClass::class);
$someServiceMock->expects($matcher)
->method('prepare')
->with([1]);
->with(1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ final class WithMatchReturn extends TestCase

$someMockedClass->expects($matcher)
->method('prepare')
->with([
'some_value',
])->willReturn(4);
->with('some_value')->willReturn(4);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function run()
$matcher = $this->exactly(1);
$this->personServiceMock->expects($matcher)
->with([1], $parameters);
->with(1, $parameters);
}
}
CODE_SAMPLE
Expand Down Expand Up @@ -122,8 +122,14 @@ public function refactor(Node $node): MethodCall|null
// we look for $this->assertSame(...)
$expectedExpr = $matchAndReturnMatch->getConsecutiveMatchExpr();

if ($expectedExpr instanceof Expr\Array_) {
$args = $this->nodeFactory->createArgs($expectedExpr->items);
} else {
$args = [new Arg($expectedExpr)];
}

$node->name = new Identifier('with');
$node->args = [new Arg($expectedExpr)];
$node->args = $args;

// remove the returnCallback if present
if ($matchAndReturnMatch->getWillReturnMatch() instanceof Match_) {
Expand Down

0 comments on commit 3995add

Please sign in to comment.