-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TesterBundle] PHPUnit SetUpAutowire extension refactoring and suppor…
…t AutowireParameter
- Loading branch information
Showing
10 changed files
with
298 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/tester-bundle/PHPUnit/Extension/SetUpAutowire/AutowireInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Draw\Bundle\TesterBundle\PHPUnit\Extension\SetUpAutowire; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
interface AutowireInterface | ||
{ | ||
public static function getPriority(): int; | ||
|
||
public function autowire(TestCase $testCase, \ReflectionProperty $reflectionProperty); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/tester-bundle/PHPUnit/Extension/SetUpAutowire/AutowireParameter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Draw\Bundle\TesterBundle\PHPUnit\Extension\SetUpAutowire; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class AutowireParameter implements AutowireInterface | ||
{ | ||
public static function getPriority(): int | ||
{ | ||
return 0; | ||
} | ||
|
||
public function __construct(private string $parameter) | ||
{ | ||
} | ||
|
||
public function getParameter(): string | ||
{ | ||
return $this->parameter; | ||
} | ||
|
||
public function autowire(TestCase $testCase, \ReflectionProperty $reflectionProperty): void | ||
{ | ||
\assert($testCase instanceof KernelTestCase); | ||
|
||
$container = (new \ReflectionMethod($testCase, 'getContainer'))->invoke($testCase); | ||
|
||
$reflectionProperty->setValue( | ||
$testCase, | ||
$container->get(ParameterBagInterface::class)->resolveValue($this->getParameter()) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.