Skip to content

Commit e87f134

Browse files
committed
add failing fixture for setup only used property
1 parent 9a2221b commit e87f134

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\Issues\MockToStubSetupCombined\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\UseSpecificWillMethodRector\Fixture\SomeClass;
7+
use Rector\PHPUnit\Tests\Issues\MockToStubSetupCombined\Source\SomeClassWithArguments;
8+
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
9+
10+
final class SomeTest extends TestCase
11+
{
12+
private \PHPUnit\Framework\MockObject\MockObject $someMock;
13+
14+
protected function setUp(): void
15+
{
16+
$this->someMock = $this->createMock(SomeClass::class);
17+
18+
$generator = new RewindableGenerator(fn () => yield from [
19+
$this->someMock,
20+
], 2);
21+
}
22+
23+
public function testSomething(): void
24+
{
25+
}
26+
27+
public function testAnother(): void
28+
{
29+
}
30+
}
31+
32+
?>
33+
-----
34+
<?php
35+
36+
namespace Rector\PHPUnit\Tests\Issues\MockToStubSetupCombined\Fixture;
37+
38+
use PHPUnit\Framework\TestCase;
39+
use Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\UseSpecificWillMethodRector\Fixture\SomeClass;
40+
use Rector\PHPUnit\Tests\Issues\MockToStubSetupCombined\Source\SomeClassWithArguments;
41+
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
42+
43+
final class SomeTest extends TestCase
44+
{
45+
protected function setUp(): void
46+
{
47+
$someMock = $this->createMock(SomeClass::class);
48+
49+
$generator = new RewindableGenerator(fn () => yield from [
50+
$someMock,
51+
], 2);
52+
}
53+
54+
public function testSomething(): void
55+
{
56+
}
57+
58+
public function testAnother(): void
59+
{
60+
}
61+
}
62+
63+
?>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\PHPUnit\Tests\Issues\MockToStubSetupCombined;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class MockToStubSetupCombinedTest extends AbstractRectorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
22+
}
23+
24+
public function provideConfigFilePath(): string
25+
{
26+
return __DIR__ . '/config/configured_rule.php';
27+
}
28+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\PHPUnit\Tests\Issues\MockToStubSetupCombined\Source;
6+
7+
final class SomeClassWithArguments
8+
{
9+
public function __construct($argument)
10+
{
11+
}
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\PHPUnit\CodeQuality\Rector\Class_\NarrowUnusedSetUpDefinedPropertyRector;
7+
use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\BareCreateMockAssignToDirectUseRector;
8+
9+
return RectorConfig::configure()
10+
->withRules(rules: [
11+
NarrowUnusedSetUpDefinedPropertyRector::class,
12+
BareCreateMockAssignToDirectUseRector::class,
13+
]);

0 commit comments

Comments
 (0)