New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a way to define configuration in atoum/*-edition packages #604
Conversation
thanks |
https://github.com/agallou/atoum-standard-edition has been updated to ease the configuration of the xUnit report. With this, for example, the configuration in Jenkins will be a lot easier. No config file will be needed. only an environnement variable will be needed :
and to xml file will be created (so as the directory if it does not) :
|
This solution makes atoum coupled to eventual editions: I'm not really comfortable with that. Here what I would like to propose as an alternative: edition would push their configuration to atoum using autoloader. Here is how. The extension will have to declare an autoloader file: {
...
"autoloaders: {
"files": [
"configuration.php"
]
}
} Inside this <?php
use mageekguy\atoum;
use mageekguy\atoum\scripts;
if (defined('mageekguy\atoum\scripts\runner') === true) {
scripts\runner::configureRunner(function(atoum\runner $runner) {
$runner->addExtension(new atoum\blackfire\extension());
//...
});
} Then in the project's <?php
use mageekguy\atoum;
$runner->getExtension(atoum\blackfire\extension::class)
->setClientConfiguration(/*...*/)
; This would require less coupling but some work has to be done in atoum:
What do you think ? |
The getExtension could be very usefull. I will add this. But using composer's autoloader will be problematic (i've also tried it when working on this PR). The issue there is that atoum does not uses (yet?) composer's autoloader. Samll change on your proposal, instead of passing a callback, i've tested by adding an array of files that will by loaded by the enableAutorun method : Like this :
the standard edition file has be changed to add an autoloader containing this :
This allows us to have configuration files similar to the .atoum.php ones. By it doesn't work as is. In order to make this work we need to add
in the (or apply the patch of the #523 PR) Without that, atoum will never load composer's autoloader, and the configuration will not be loaded. So, about the autoloader :
What's your thought's about that ? |
2e3db4b
to
437eac2
Compare
@@ -652,6 +657,11 @@ public static function disableAutorun() | |||
static::$autorunner = false; | |||
} | |||
|
|||
public static function addAutorunnerConfigurationFile($file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addConfigurationFile
437eac2
to
710d8d7
Compare
} | ||
|
||
if (1 != count($extensions)) { | ||
throw new \Exception(sprintf("Extension '%s' Not found", $classname)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Not/not/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@agallou use a more specific exception, invalidArgument for example ;)
710d8d7
to
cd3f6cc
Compare
public function getExtension($classname) | ||
{ | ||
$extensions = array(); | ||
foreach ($this->getExtensions() as $extension) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{
should be on its on line ;)
cd3f6cc
to
b5448dd
Compare
|
||
if (1 != count($extensions)) | ||
{ | ||
throw new \InvalidArgumentException(sprintf("Extension '%s' not found", $classname)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please, can you throw the mageekguy\atoum\exceptions\logic\invalidArgument
d311585
to
0ee9f32
Compare
$extensions[] = $extension; | ||
} | ||
|
||
if (1 != count($extensions)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should improve the addExtension
method and move this check there: atoum should refuse to load an extension twice.
The addExtension
already checks for an already existing extension instance but it should also check if an extension of the same class is already loaded.
Doing this, we could make the code in getExtension
simpler: return early in the foreach loop and throw if we exit the loop without any matching extension.
One last comment in the code. Would you mind adding the |
0ee9f32
to
25670b7
Compare
This simplifies the getExtension method
Could be called for example like this : ``` $runner->removeExtensionByClassName(mageekguy\atoum\visibility\extension::class); ```
@jubianchi PR updated :
|
This is a partial port of what @agallou did in atoum#604: extensions are indexed by class name. * We can load an extension the way we already did: ```php <?php $extension = new mageekguy\atoum\blackfire\extension($script); $extension ->setClientConfiguration(new \Blackfire\ClientConfiguration( $_ENV['BLACKFIRE_CLIENT_ID'], $_ENV['BLACKFIRE_CLIENT_TOKEN'] )) ->addToRunner($runner) ; ``` * If we later try to re-register the same extension, only its configuration will be updated: ```php <?php $extension = new mageekguy\atoum\blackfire\extension($script); $extension ->setClientConfiguration(new \Blackfire\ClientConfiguration( 'foo', 'bar' )) ->addToRunner($runner) ; ``` * We can also unload an extension, either using an instance or its class name: ```php $extension = new mageekguy\atoum\blackfire\extension($script); $extension->addToRunner($runner); $runner->removeExtension($extension); $runner->removeExtension(new mageekguy\atoum\blackfire\extension()); $runner->removeExtension(mageekguy\atoum\blackfire\extension::class); ```
This is a partial port of what @agallou did in atoum#604: extensions are indexed by class name. * We can load an extension the way we already did: ```php <?php $extension = new mageekguy\atoum\blackfire\extension($script); $extension ->setClientConfiguration(new \Blackfire\ClientConfiguration( $_ENV['BLACKFIRE_CLIENT_ID'], $_ENV['BLACKFIRE_CLIENT_TOKEN'] )) ->addToRunner($runner) ; ``` * If we later try to re-register the same extension, only its configuration will be updated: ```php <?php $extension = new mageekguy\atoum\blackfire\extension($script); $extension ->setClientConfiguration(new \Blackfire\ClientConfiguration( 'foo', 'bar' )) ->addToRunner($runner) ; ``` * We can also unload an extension, either using an instance or its class name: ```php $extension = new mageekguy\atoum\blackfire\extension($script); $extension->addToRunner($runner); $runner->removeExtension($extension); $runner->removeExtension(new mageekguy\atoum\blackfire\extension()); $runner->removeExtension(mageekguy\atoum\blackfire\extension::class); ```
This will allow us to create "editions" of atoum, will extensions preloaded and some stuff configured.
For example : https://github.com/agallou/atoum-standard-edition
By requirering only atoum/standard-edition this will :
we could also imagine
you can see an example of usage here : https://github.com/agallou/atoum-std-edition-example (the repositories and atoum/atoum in the require section should not be here. They won't be if diffrent PR are merged).
This standard edition will help users set-up atoum.
This will also :
For now we still need to define manually a .bootstrap.atoum.php file, but if the PR #523 is also merged, the installation/configuration will even be easier.