Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class NestedCallback extends TestCase
$this->someMock->expects($matcher)
->method('prepare')
->willReturnCallback(
function (...$parameters) use ($matcher) {
function (...$parameters) use ($matcher, $item) {
if ($matcher->numberOfInvocations() === 1) {
$this->assertEquals(50, $parameters[0]);
$this->assertSame(5, $parameters[1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class SkipNestedVariableFromUses extends TestCase
$this->someMock->expects($matcher)
->method('prepare')
->willReturnCallback(
function (...$parameters) use ($matcher) {
function (...$parameters) use ($matcher, $item) {
$this->assertSame(5, $parameters[0]);
},
);
Expand Down
63 changes: 63 additions & 0 deletions tests/Issues/MockToStubSetupCombined/Fixture/some_test.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Rector\PHPUnit\Tests\Issues\MockToStubSetupCombined\Fixture;

use PHPUnit\Framework\TestCase;
use Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\UseSpecificWillMethodRector\Fixture\SomeClass;
use Rector\PHPUnit\Tests\Issues\MockToStubSetupCombined\Source\MockedClass;
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;

final class SomeTest extends TestCase
{
private \PHPUnit\Framework\MockObject\MockObject $someMock;

protected function setUp(): void
{
$this->someMock = $this->createMock(MockedClass::class);

$generator = new RewindableGenerator(fn () => yield from [
$this->someMock,
], 2);
}

public function testSomething(): void
{
}

public function testAnother(): void
{
}
}

?>
-----
<?php

namespace Rector\PHPUnit\Tests\Issues\MockToStubSetupCombined\Fixture;

use PHPUnit\Framework\TestCase;
use Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\UseSpecificWillMethodRector\Fixture\SomeClass;
use Rector\PHPUnit\Tests\Issues\MockToStubSetupCombined\Source\MockedClass;
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;

final class SomeTest extends TestCase
{
protected function setUp(): void
{
$someMock = $this->createMock(MockedClass::class);

$generator = new RewindableGenerator(fn () => yield from [
$someMock,
], 2);
}

public function testSomething(): void
{
}

public function testAnother(): void
{
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Rector\PHPUnit\Tests\Issues\MockToStubSetupCombined;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class MockToStubSetupCombinedTest extends AbstractRectorTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public static function provideData(): Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
7 changes: 7 additions & 0 deletions tests/Issues/MockToStubSetupCombined/Source/MockedClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Rector\PHPUnit\Tests\Issues\MockToStubSetupCombined\Source;

final class MockedClass
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Rector\PHPUnit\Tests\Issues\MockToStubSetupCombined\Source;

final class SomeClassWithArguments
{
public function __construct($argument)
{
}
}
13 changes: 13 additions & 0 deletions tests/Issues/MockToStubSetupCombined/config/configured_rule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\PHPUnit\CodeQuality\Rector\Class_\NarrowUnusedSetUpDefinedPropertyRector;
use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\BareCreateMockAssignToDirectUseRector;

return RectorConfig::configure()
->withRules(rules: [
NarrowUnusedSetUpDefinedPropertyRector::class,
BareCreateMockAssignToDirectUseRector::class,
]);