Skip to content
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

[WIP] Added Config Testing Case #27

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"doctrine/phpcr-bundle": "1.0.*",
"doctrine/data-fixtures": "1.0.*",
"jackalope/jackalope": "1.0.*",
"jackalope/jackalope-doctrine-dbal": "1.0.*"
"jackalope/jackalope-doctrine-dbal": "1.0.*",
"matthiasnoback/symfony-config-test": "0.*"
},
"autoload": {
"psr-0": { "Symfony\\Cmf\\Component\\Testing": "src/" }
Expand Down
97 changes: 97 additions & 0 deletions src/Symfony/Cmf/Component/Testing/Unit/ConfigurationTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

namespace Symfony\Cmf\Component\Testing\Unit;

use Matthias\SymfonyConfigTest\PhpUnit\AbstractConfigurationTestCase;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;

abstract class ConfigurationTestCase extends AbstractConfigurationTestCase
{
abstract protected function getFilenames();
abstract protected function getExpectedResult();
abstract protected function getExtension();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these methods are what users implement in their testing code, so i think they really should have phpdoc on expected return values and semantics.


public function testYamlConfig()
{
$filenames = $this->getFilenames();

if (!isset($filenames['yaml'])) {
$this->markTestSkipped('No Yaml configuration fixture configured');
}

$files = $filenames['yaml'];
if (!is_array($files)) {
$files = array($files);
}

foreach ($files as $file) {
$this->assertProcessedConfigurationEquals($this->loadYamlFile($file), $this->getExpectedResult());
}
}

public function testXmlConfig()
{
$filenames = $this->getFilenames();

if (!isset($filenames['xml'])) {
$this->markTestSkipped('No XML configuration fixture configured');
}

$files = $filenames['xml'];
if (!is_array($files)) {
$files = array($files);
}

foreach ($files as $file) {
$this->assertProcessedConfigurationEquals($this->loadXmlFile($file), $this->getExpectedResult());
}
}

public function testXmlConfig()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is meant to be testPhpConfig(), its a name clash with above, and in the body you do stuff on php

{
$filenames = $this->getFilenames();

if (!isset($filenames['php'])) {
$this->markTestSkipped('No PHP configuration fixture configured');
}

$files = $filenames['php'];
if (!is_array($files)) {
$files = array($files);
}

foreach ($files as $file) {
$this->assertProcessedConfigurationEquals($this->loadPhpFile($file), $this->getExpectedResult());
}
}

protected function loadXmlFile($file)
{
return $this->doLoadFile($file, 'XmlFileLoader');
}

protected function loadYamlFile($file)
{
return $this->doLoadFile($file, 'YamlFileLoader');
}

protected function loadPhpFile($file)
{
return $this->doLoadFile($file, 'PhpFileLoader');
}

private function doLoadFile($file, $loader)
{
$container = new ContainerBuilder();

$extension = $this->getExtension();
$container->registerExtension($extension);

$loader = 'Symfony\Component\DependencyInjection\Loader\\'.$loader;
$loader = new $loader($container, new FileLocator(dirname($file)));
$loader->load(basename($file));

return $container->getExtensionConfig($extension->getAlias());
}
}