Skip to content

Commit fad4926

Browse files
authored
[TypeDeclaration] Add TypedPropertyFromContainerGetSetUpRector (#8120)
1 parent a5f53cc commit fad4926

14 files changed

Lines changed: 522 additions & 0 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Source\SomeService;
7+
8+
final class SkipNoDocblock extends TestCase
9+
{
10+
private $someService;
11+
12+
protected function setUp(): void
13+
{
14+
$this->someService = static::getContainer()->get(SomeService::class);
15+
}
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Fixture;
4+
5+
use Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Source\SomeService;
6+
7+
final class SkipNoTestCase
8+
{
9+
/**
10+
* @var SomeService
11+
*/
12+
private $someService;
13+
14+
protected function setUp(): void
15+
{
16+
$this->someService = static::getContainer()->get(SomeService::class);
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class SkipNonExistingClass extends TestCase
8+
{
9+
/**
10+
* @var \Some\Non\Existing\Service
11+
*/
12+
private $someService;
13+
14+
protected function setUp(): void
15+
{
16+
$this->someService = static::getContainer()->get('some_service');
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Source\SomeService;
7+
8+
final class SkipNotContainerFetch extends TestCase
9+
{
10+
/**
11+
* @var SomeService
12+
*/
13+
private $someService;
14+
15+
protected function setUp(): void
16+
{
17+
$this->someService = new SomeService();
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Source\SomeService;
7+
8+
final class SkipPublicProperty extends TestCase
9+
{
10+
/**
11+
* @var SomeService
12+
*/
13+
public $someService;
14+
15+
protected function setUp(): void
16+
{
17+
$this->someService = static::getContainer()->get(SomeService::class);
18+
}
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class SkipScalarType extends TestCase
8+
{
9+
/**
10+
* @var string
11+
*/
12+
private $value;
13+
14+
protected function setUp(): void
15+
{
16+
$this->value = static::getContainer()->get('some_parameter');
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Source\SomeService;
7+
8+
final class StaticGetContainerGet extends TestCase
9+
{
10+
/**
11+
* @var SomeService
12+
*/
13+
private $someService;
14+
15+
protected function setUp(): void
16+
{
17+
parent::setUp();
18+
19+
$this->someService = static::getContainer()->get(SomeService::class);
20+
}
21+
}
22+
23+
?>
24+
-----
25+
<?php
26+
27+
namespace Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Fixture;
28+
29+
use PHPUnit\Framework\TestCase;
30+
use Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Source\SomeService;
31+
32+
final class StaticGetContainerGet extends TestCase
33+
{
34+
private \Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Source\SomeService $someService;
35+
36+
protected function setUp(): void
37+
{
38+
parent::setUp();
39+
40+
$this->someService = static::getContainer()->get(SomeService::class);
41+
}
42+
}
43+
44+
?>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Source\SomeService;
7+
8+
final class ThisContainerGet extends TestCase
9+
{
10+
/**
11+
* @var SomeService
12+
*/
13+
private $someService;
14+
15+
protected function setUp(): void
16+
{
17+
$this->someService = $this->container->get('some_service');
18+
}
19+
}
20+
21+
?>
22+
-----
23+
<?php
24+
25+
namespace Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Fixture;
26+
27+
use PHPUnit\Framework\TestCase;
28+
use Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Source\SomeService;
29+
30+
final class ThisContainerGet extends TestCase
31+
{
32+
private \Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Source\SomeService $someService;
33+
34+
protected function setUp(): void
35+
{
36+
$this->someService = $this->container->get('some_service');
37+
}
38+
}
39+
40+
?>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Source\SomeService;
7+
8+
final class ThisGet extends TestCase
9+
{
10+
/**
11+
* @var SomeService
12+
*/
13+
private $someService;
14+
15+
protected function setUp(): void
16+
{
17+
$this->someService = $this->get(SomeService::class);
18+
}
19+
}
20+
21+
?>
22+
-----
23+
<?php
24+
25+
namespace Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Fixture;
26+
27+
use PHPUnit\Framework\TestCase;
28+
use Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Source\SomeService;
29+
30+
final class ThisGet extends TestCase
31+
{
32+
private \Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Source\SomeService $someService;
33+
34+
protected function setUp(): void
35+
{
36+
$this->someService = $this->get(SomeService::class);
37+
}
38+
}
39+
40+
?>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromContainerGetSetUpRector\Source;
6+
7+
final class SomeService
8+
{
9+
}

0 commit comments

Comments
 (0)