-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inherit attributes/annotations from parent classes
- Loading branch information
Showing
19 changed files
with
262 additions
and
31 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
31 changes: 31 additions & 0 deletions
31
src/ConfigurationProvider/AbstractConfigurationProvider.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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bizkit\LoggableCommandBundle\ConfigurationProvider; | ||
|
||
abstract class AbstractConfigurationProvider implements ConfigurationProviderInterface | ||
{ | ||
/** | ||
* Appends configuration options from the second configuration to the first configuration | ||
* while not overwriting the options from the first configuration. | ||
*/ | ||
protected static function mergeConfigurations(array $firstConfiguration, array $secondConfiguration): array | ||
{ | ||
$extraOptions = $firstConfiguration['extra_options'] ?? []; | ||
unset($firstConfiguration['extra_options']); | ||
|
||
if (isset($secondConfiguration['extra_options'])) { | ||
$extraOptions += $secondConfiguration['extra_options']; | ||
unset($secondConfiguration['extra_options']); | ||
} | ||
|
||
$firstConfiguration += $secondConfiguration; | ||
|
||
if (!empty($extraOptions)) { | ||
$firstConfiguration['extra_options'] = $extraOptions; | ||
} | ||
|
||
return $firstConfiguration; | ||
} | ||
} |
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
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
64 changes: 64 additions & 0 deletions
64
tests/ConfigurationProvider/AbstractConfigurationProviderTest.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,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bizkit\LoggableCommandBundle\Tests\ConfigurationProvider; | ||
|
||
use Bizkit\LoggableCommandBundle\ConfigurationProvider\AbstractConfigurationProvider; | ||
use Bizkit\LoggableCommandBundle\LoggableOutput\LoggableOutputInterface; | ||
use Bizkit\LoggableCommandBundle\Tests\ConfigurationProvider\Fixtures\DummyLoggableOutput; | ||
use Bizkit\LoggableCommandBundle\Tests\TestCase; | ||
|
||
/** | ||
* @covers \Bizkit\LoggableCommandBundle\ConfigurationProvider\AbstractConfigurationProvider | ||
*/ | ||
final class AbstractConfigurationProviderTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider configurationsToMerge | ||
*/ | ||
public function testConfigurationsAreMergedAsExpected(array $config1, array $config2, array $mergedConfig): void | ||
{ | ||
$configurationProvider = new class($config1, $config2) extends AbstractConfigurationProvider { | ||
private $config1; | ||
private $config2; | ||
|
||
public function __construct(array $config1, array $config2) | ||
{ | ||
$this->config1 = $config1; | ||
$this->config2 = $config2; | ||
} | ||
|
||
public function __invoke(LoggableOutputInterface $loggableOutput): array | ||
{ | ||
return self::mergeConfigurations($this->config1, $this->config2); | ||
} | ||
}; | ||
|
||
$this->assertSame($mergedConfig, $configurationProvider(new DummyLoggableOutput())); | ||
} | ||
|
||
public function configurationsToMerge(): iterable | ||
{ | ||
yield 'Extra options in none' => [ | ||
['opt1' => 'opt1val', 'opt2' => 'opt2val'], | ||
['opt1' => 'opt1otherVal', 'opt3' => 'opt3otherVal'], | ||
['opt1' => 'opt1val', 'opt2' => 'opt2val', 'opt3' => 'opt3otherVal'], | ||
]; | ||
yield 'Extra options in first' => [ | ||
['opt1' => 'opt1val', 'opt2' => 'opt2val', 'extra_options' => ['extra1' => 'extra1val', 'extra2' => 'extra2val']], | ||
['opt1' => 'opt1otherVal', 'opt3' => 'opt3otherVal'], | ||
['opt1' => 'opt1val', 'opt2' => 'opt2val', 'opt3' => 'opt3otherVal', 'extra_options' => ['extra1' => 'extra1val', 'extra2' => 'extra2val']], | ||
]; | ||
yield 'Extra options in second' => [ | ||
['opt1' => 'opt1val', 'opt2' => 'opt2val'], | ||
['opt1' => 'opt1otherVal', 'opt3' => 'opt3otherVal', 'extra_options' => ['extra1' => 'extra1val', 'extra2' => 'extra2val']], | ||
['opt1' => 'opt1val', 'opt2' => 'opt2val', 'opt3' => 'opt3otherVal', 'extra_options' => ['extra1' => 'extra1val', 'extra2' => 'extra2val']], | ||
]; | ||
yield 'Extra options in both' => [ | ||
['opt1' => 'opt1val', 'opt2' => 'opt2val', 'extra_options' => ['extra1' => 'extra1val', 'extra2' => 'extra2val']], | ||
['opt1' => 'opt1otherVal', 'opt3' => 'opt3otherVal', 'extra_options' => ['extra1' => 'extra1otherVal', 'extra3' => 'extra3otherVal']], | ||
['opt1' => 'opt1val', 'opt2' => 'opt2val', 'opt3' => 'opt3otherVal', 'extra_options' => ['extra1' => 'extra1val', 'extra2' => 'extra2val', 'extra3' => 'extra3otherVal']], | ||
]; | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
tests/ConfigurationProvider/Fixtures/DummyChildLoggableOutputWithAnnotation.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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bizkit\LoggableCommandBundle\Tests\ConfigurationProvider\Fixtures; | ||
|
||
use Bizkit\LoggableCommandBundle\ConfigurationProvider\Attribute\LoggableOutput; | ||
|
||
/** | ||
* @LoggableOutput(filename="child-annotation-test") | ||
*/ | ||
class DummyChildLoggableOutputWithAnnotation extends DummyLoggableOutputWithAnnotation | ||
{ | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/ConfigurationProvider/Fixtures/DummyChildLoggableOutputWithAttribute.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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bizkit\LoggableCommandBundle\Tests\ConfigurationProvider\Fixtures; | ||
|
||
use Bizkit\LoggableCommandBundle\ConfigurationProvider\Attribute\LoggableOutput; | ||
|
||
#[LoggableOutput(filename: 'child-attribute-test')] | ||
class DummyChildLoggableOutputWithAttribute extends DummyLoggableOutputWithAttribute | ||
{ | ||
} |
9 changes: 9 additions & 0 deletions
9
tests/ConfigurationProvider/Fixtures/DummyChildLoggableOutputWithParentAnnotation.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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bizkit\LoggableCommandBundle\Tests\ConfigurationProvider\Fixtures; | ||
|
||
class DummyChildLoggableOutputWithParentAnnotation extends DummyLoggableOutputWithAnnotation | ||
{ | ||
} |
9 changes: 9 additions & 0 deletions
9
tests/ConfigurationProvider/Fixtures/DummyChildLoggableOutputWithParentAttribute.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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bizkit\LoggableCommandBundle\Tests\ConfigurationProvider\Fixtures; | ||
|
||
class DummyChildLoggableOutputWithParentAttribute extends DummyLoggableOutputWithAttribute | ||
{ | ||
} |
Oops, something went wrong.