Skip to content

Commit

Permalink
Copy tests from symplify/autowire-array-parameter (#3152)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Dec 4, 2022
1 parent 58069c3 commit 4e9214f
Show file tree
Hide file tree
Showing 20 changed files with 411 additions and 4 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ parameters:
- '#Callable callable\(PHPStan\\Type\\Type\)\: PHPStan\\Type\\Type invoked with 2 parameters, 1 required#'

# PHPStan 1.4.7
- '#Call to static method Webmozart\\Assert\\Assert\:\:allIsAOf|isAOf\(\) with .* will always evaluate to true#'
- '#Call to static method Webmozart\\Assert\\Assert\:\:allIsAOf|isAOf|assertInstanceOf\(\) with .* will always evaluate to true#'

-
message: '#Make callable type explicit#'
Expand Down
9 changes: 6 additions & 3 deletions rules/Php80/Rector/FunctionLike/MixedTypeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,15 @@ public function refactor(Node $node): ?Node

$this->refactorParamTypes($node, $phpDocInfo);
$hasChanged = $this->paramTagRemover->removeParamTagsIfUseless($phpDocInfo, $node);
if ($this->hasChanged) {
return $node;
}

if (! $this->hasChanged && ! $hasChanged) {
return null;
if ($hasChanged) {
return $node;
}

return $node;
return null;
}

public function provideMinPhpVersion(): int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/**
* @inspiration https://github.com/nette/di/pull/178
* @see \Rector\Core\Tests\DependencyInjection\CompilerPass\AutowireArrayParameterCompilerPassTest
*/
final class AutowireArrayParameterCompilerPass implements CompilerPassInterface
{
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/DefinitionFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

/**
* @api
* @see \Rector\Core\Tests\DependencyInjection\DefinitionFinderTest
*/
final class DefinitionFinder
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace Rector\Core\Tests\DependencyInjection\CompilerPass;

use Rector\Core\Tests\DependencyInjection\CompilerPass\Source\ArrayShapeCollector;
use Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Contract\FirstCollectedInterface;
use Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Contract\SecondCollectedInterface;
use Rector\Core\Tests\DependencyInjection\CompilerPass\Source\IterableCollector;
use Rector\Core\Tests\DependencyInjection\CompilerPass\Source\SomeCollector;
use Rector\Core\Tests\DependencyInjection\HttpKernel\AutowireArrayParameterHttpKernel;
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;

final class AutowireArrayParameterCompilerPassTest extends AbstractKernelTestCase
{
protected function setUp(): void
{
$this->bootKernel(AutowireArrayParameterHttpKernel::class);
}

public function test(): void
{
/** @var SomeCollector $someCollector */
$someCollector = $this->getService(SomeCollector::class);
$this->assertCount(3, $someCollector->getFirstCollected());
$this->assertCount(2, $someCollector->getSecondCollected());

$this->assertInstanceOf(FirstCollectedInterface::class, $someCollector->getFirstCollected()[0]);
$this->assertInstanceOf(SecondCollectedInterface::class, $someCollector->getSecondCollected()[0]);
}

public function testArrayShape(): void
{
$arrayShapeCollector = $this->getService(ArrayShapeCollector::class);
$this->assertCount(3, $arrayShapeCollector->getFirstCollected());
$this->assertCount(2, $arrayShapeCollector->getSecondCollected());

$this->assertInstanceOf(FirstCollectedInterface::class, $arrayShapeCollector->getFirstCollected()[0]);
$this->assertInstanceOf(SecondCollectedInterface::class, $arrayShapeCollector->getSecondCollected()[0]);
}

public function testIterable(): void
{
$iterableCollector = $this->getService(IterableCollector::class);

$this->assertCount(3, $iterableCollector->getFirstCollected());
$this->assertCount(2, $iterableCollector->getSecondCollected());

$this->assertInstanceOf(FirstCollectedInterface::class, $iterableCollector->getFirstCollected()[0]);
$this->assertInstanceOf(SecondCollectedInterface::class, $iterableCollector->getSecondCollected()[0]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace Rector\Core\Tests\DependencyInjection\CompilerPass\Source;

use Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Contract\FirstCollectedInterface;
use Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Contract\SecondCollectedInterface;

final class ArrayShapeCollector
{
/**
* @var array<FirstCollectedInterface>
*/
private $firstCollected = [];

/**
* @var array<SecondCollectedInterface>
*/
private $secondCollected = [];

/**
* @param array<FirstCollectedInterface> $firstCollected
* @param array<SecondCollectedInterface> $secondCollected
*/
public function __construct(array $firstCollected, array $secondCollected)
{
$this->firstCollected = $firstCollected;
$this->secondCollected = $secondCollected;
}

/**
* @return array<FirstCollectedInterface>
*/
public function getFirstCollected(): array
{
return $this->firstCollected;
}

/**
* @return array<SecondCollectedInterface>
*/
public function getSecondCollected(): array
{
return $this->secondCollected;
}

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

declare(strict_types=1);

namespace Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Collected;

use Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Contract\FirstCollectedInterface;

final class FirstServiceOfFirstCollected implements FirstCollectedInterface
{

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

declare(strict_types=1);

namespace Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Collected;

use Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Contract\SecondCollectedInterface;

final class FirstServiceOfSecondCollected implements SecondCollectedInterface
{

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

declare(strict_types=1);

namespace Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Collected;

use Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Contract\FirstCollectedInterface;

final class SecondServiceOfFirstCollected implements FirstCollectedInterface
{

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

declare(strict_types=1);

namespace Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Collected;

use Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Contract\SecondCollectedInterface;

final class SecondServiceOfSecondCollected implements SecondCollectedInterface
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Collected;

use Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Contract\FirstCollectedInterface;

final class SomeCollectedPromoted implements FirstCollectedInterface
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Contract;

interface FirstCollectedInterface
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Contract;

interface SecondCollectedInterface
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Rector\Core\Tests\DependencyInjection\CompilerPass\Source;

use Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Contract\FirstCollectedInterface;
use Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Contract\SecondCollectedInterface;

final class IterableCollector
{
/**
* @var iterable<FirstCollectedInterface>
*/
private $firstCollected = [];

/**
* @var iterable<SecondCollectedInterface>
*/
private $secondCollected = [];

/**
* @param iterable<FirstCollectedInterface> $firstCollected
* @param iterable<SecondCollectedInterface> $secondCollected
*/
public function __construct(array $firstCollected, array $secondCollected)
{
$this->firstCollected = $firstCollected;
$this->secondCollected = $secondCollected;
}

/**
* @return iterable<FirstCollectedInterface>
*/
public function getFirstCollected(): array
{
return $this->firstCollected;
}

/**
* @return iterable<SecondCollectedInterface>
*/
public function getSecondCollected(): array
{
return $this->secondCollected;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Rector\Core\Tests\DependencyInjection\CompilerPass\Source;

use Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Contract\FirstCollectedInterface;

final class PromotedPropertyCollector
{
/**
* @param FirstCollectedInterface[] $firstCollected
*/
public function __construct(
private array $firstCollected
) {
}

/**
* @return FirstCollectedInterface[]
*/
public function getFirstCollected(): array
{
return $this->firstCollected;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Rector\Core\Tests\DependencyInjection\CompilerPass\Source\SkipMe;

use Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Contract\FirstCollectedInterface;
use Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Contract\SecondCollectedInterface;

final class SkipUnionTypes
{
public function __construct(
public FirstCollectedInterface|SecondCollectedInterface $collectedInterface
) {
}
}
47 changes: 47 additions & 0 deletions tests/DependencyInjection/CompilerPass/Source/SomeCollector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Rector\Core\Tests\DependencyInjection\CompilerPass\Source;

use Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Contract\FirstCollectedInterface;
use Rector\Core\Tests\DependencyInjection\CompilerPass\Source\Contract\SecondCollectedInterface;

final class SomeCollector
{
/**
* @var FirstCollectedInterface[]
*/
private $firstCollected = [];

/**
* @var SecondCollectedInterface[]
*/
private $secondCollected = [];

/**
* @param FirstCollectedInterface[] $firstCollected
* @param SecondCollectedInterface[] $secondCollected
*/
public function __construct(array $firstCollected, array $secondCollected)
{
$this->firstCollected = $firstCollected;
$this->secondCollected = $secondCollected;
}

/**
* @return FirstCollectedInterface[]
*/
public function getFirstCollected(): array
{
return $this->firstCollected;
}

/**
* @return SecondCollectedInterface[]
*/
public function getSecondCollected(): array
{
return $this->secondCollected;
}
}

0 comments on commit 4e9214f

Please sign in to comment.