Commit b67e1f86 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Fixed testsuite after CLI refactorings, Removed Symfony YAML Autoloader Hack

parent c98543c1
......@@ -29,7 +29,6 @@ class AllTests
$suite->addTest(Collections\AllTests::suite());
$suite->addTest(Annotations\AllTests::suite());
$suite->addTest(Cache\AllTests::suite());
$suite->addTest(CLI\AllTests::suite());
return $suite;
}
......
<?php
namespace Doctrine\Tests\Common\CLI;
if (!defined('PHPUnit_MAIN_METHOD')) {
define('PHPUnit_MAIN_METHOD', 'Common_Cli_AllTests::main');
}
require_once __DIR__ . '/../../TestInit.php';
class AllTests
{
public static function main()
{
\PHPUnit_TextUI_TestRunner::run(self::suite());
}
public static function suite()
{
$suite = new \Doctrine\Tests\DoctrineTestSuite('Doctrine Common CLI Tests');
$suite->addTestSuite('Doctrine\Tests\Common\CLI\ConfigurationTest');
$suite->addTestSuite('Doctrine\Tests\Common\CLI\OptionTest');
$suite->addTestSuite('Doctrine\Tests\Common\CLI\OptionGroupTest');
$suite->addTestSuite('Doctrine\Tests\Common\CLI\StyleTest');
//$suite->addTestSuite('Doctrine\Tests\Common\CLI\CLIControllerTest');
return $suite;
}
}
if (PHPUnit_MAIN_METHOD == 'Common_CLI_AllTests::main') {
AllTests::main();
}
\ No newline at end of file
<?php
namespace Doctrine\Tests\Common\CLI;
use Doctrine\Tests\Mocks\TaskMock;
use Doctrine\Common\CLI\Configuration;
use Doctrine\Common\CLI\CliController;
require_once __DIR__ . '/../../TestInit.php';
/**
* @author Nils Adermann <naderman@naderman.de>
*/
class CLIControllerTest extends \Doctrine\Tests\DoctrineTestCase
{
private $cli;
/**
* Sets up a CLIController instance with a task referencing the TaskMock
* class. Instances of that class created by the CLIController can be
* inspected for correctness.
*/
function setUp()
{
$config = $this->getMock('\Doctrine\Common\CLI\Configuration');
$printer = $this->getMockForAbstractClass('\Doctrine\Common\CLI\Printers\AbstractPrinter');
$this->cli = new CLIController($config, $printer);
TaskMock::$instances = array();
$this->cli->addTask('task-mock', '\Doctrine\Tests\Mocks\TaskMock');
}
/**
* Data provider with a bunch of task-mock calls with different arguments
* and their expected parsed format.
*/
static public function dataCLIControllerArguments()
{
return array(
array(
array('doctrine', 'Core:task-mock', '--bool'),
array('bool' => true),
'Bool option'
),
array(
array('doctrine', 'Core:task-mock', '--option=value'),
array('option' => 'value'),
'Option with string value'
),
array(
array('doctrine', 'Core:task-mock', '--option=value, with additional, info'),
array('option' => 'value, with additional, info'),
'Option with string value containing space and comma'
),
array(
array('doctrine', 'Core:task-mock', '--option='),
array('option' => array()),
'Empty option value'
),
array(
array('doctrine', 'Core:task-mock', '--option=value1,value2,value3'),
array('option' => array('value1', 'value2', 'value3')),
'Option with list of string values'
),
);
}
/**
* Checks whether the arguments coming from the data provider are correctly
* parsed by the CLIController and passed to the task to be run.
*
* @dataProvider dataCLIControllerArguments
* @param array $rawArgs
* @param array $parsedArgs
* @param string $message
*/
public function testArgumentParsing($rawArgs, $parsedArgs, $message)
{
$this->cli->run($rawArgs);
$this->assertEquals(count(TaskMock::$instances), 1);
$task = TaskMock::$instances[0];
$this->assertEquals($task->getArguments(), $parsedArgs, $message);
}
/**
* Checks whether multiple tasks in one command are correctly run with
* their respective options.
*/
public function testMultipleTaskExecution()
{
$this->cli->run(array(
'doctrine',
'Core:task-mock',
'--option=',
'Core:task-mock',
'--bool'
));
$this->assertEquals(count(TaskMock::$instances), 2);
$task0 = TaskMock::$instances[0];
$task1 = TaskMock::$instances[1];
$this->assertEquals($task0->getRunCounter(), 1);
$this->assertEquals($task1->getRunCounter(), 1);
$this->assertEquals($task0->getArguments(), array('option' => array()));
$this->assertEquals($task1->getArguments(), array('bool' => true));
}
}
<?php
namespace Doctrine\Tests\Common\CLI;
use Doctrine\Common\CLI\Configuration;
require_once __DIR__ . '/../../TestInit.php';
class ConfigurationTest extends \Doctrine\Tests\DoctrineTestCase
{
public function testConfiguration()
{
$config = new Configuration();
$config->setAttribute('name', 'value');
$this->assertTrue($config->hasAttribute('name'));
$this->assertEquals('value', $config->hasAttribute('name'));
$config->setAttribute('name');
$this->assertFalse($config->hasAttribute('name'));
}
}
\ No newline at end of file
<?php
namespace Doctrine\Tests\Common\CLI;
use Doctrine\Common\CLI\Printers\NormalPrinter,
Doctrine\Common\CLI\OptionGroup,
Doctrine\Common\CLI\Option;
require_once __DIR__ . '/../../TestInit.php';
class OptionGroupTest extends \Doctrine\Tests\DoctrineTestCase
{
private $_options = array();
public function setUp()
{
$this->_printer = new NormalPrinter();
$this->_options[0] = new Option('name', null, 'First option description');
$this->_options[1] = new Option('another-name', 'value', 'Second option description');
$this->_options[2] = new Option('third-name', array('value1', 'value2'), 'Third option description');
}
public function testCommonFunctionality()
{
$optionGroup = new OptionGroup(OptionGroup::CARDINALITY_0_N, $this->_options);
$this->assertEquals(3, count($optionGroup->getOptions()));
$this->assertEquals(
'--name First option description' . PHP_EOL . PHP_EOL .
'--another-name=value Second option description' . PHP_EOL . PHP_EOL .
'--third-name=value1,value2 Third option description' . PHP_EOL . PHP_EOL,
$optionGroup->formatWithDescription($this->_printer)
);
$optionGroup->clear();
$this->assertEquals(0, count($optionGroup->getOptions()));
$this->assertEquals('', $optionGroup->formatPlain($this->_printer));
$this->assertEquals(
'No available options' . PHP_EOL . PHP_EOL,
$optionGroup->formatWithDescription($this->_printer)
);
$optionGroup->addOption($this->_options[0]);
$optionGroup->addOption($this->_options[1]);
$this->assertEquals(2, count($optionGroup->getOptions()));
}
public function testCardinality0toN()
{
$optionGroup = new OptionGroup(OptionGroup::CARDINALITY_0_N, $this->_options);
$this->assertEquals(OptionGroup::CARDINALITY_0_N, $optionGroup->getCardinality());
$this->assertEquals(
'[--name] [--another-name=value] [--third-name=value1,value2]',
$optionGroup->formatPlain($this->_printer)
);
}
public function testCardinality0to1()
{
$optionGroup = new OptionGroup(OptionGroup::CARDINALITY_0_1, $this->_options);
$this->assertEquals(OptionGroup::CARDINALITY_0_1, $optionGroup->getCardinality());
$this->assertEquals(
'[--name | --another-name=value | --third-name=value1,value2]',
$optionGroup->formatPlain($this->_printer)
);
}
public function testCardinality1to1()
{
$optionGroup = new OptionGroup(OptionGroup::CARDINALITY_1_1, $this->_options);
$this->assertEquals(OptionGroup::CARDINALITY_1_1, $optionGroup->getCardinality());
$this->assertEquals(
'(--name | --another-name=value | --third-name=value1,value2)',
$optionGroup->formatPlain($this->_printer)
);
}
public function testCardinality1toN()
{
$optionGroup = new OptionGroup(OptionGroup::CARDINALITY_1_N, $this->_options);
$this->assertEquals(OptionGroup::CARDINALITY_1_N, $optionGroup->getCardinality());
$this->assertEquals(
'(--name --another-name=value --third-name=value1,value2)',
$optionGroup->formatPlain($this->_printer)
);
}
public function testCardinalityNtoN()
{
$optionGroup = new OptionGroup(OptionGroup::CARDINALITY_N_N, $this->_options);
$this->assertEquals(OptionGroup::CARDINALITY_N_N, $optionGroup->getCardinality());
$this->assertEquals(
'--name --another-name=value --third-name=value1,value2',
$optionGroup->formatPlain($this->_printer)
);
}
public function testCardinalityMtoN()
{
$optionGroup = new OptionGroup(OptionGroup::CARDINALITY_M_N, $this->_options);
$this->assertEquals(OptionGroup::CARDINALITY_M_N, $optionGroup->getCardinality());
$this->assertEquals(
'--name --another-name=value --third-name=value1,value2',
$optionGroup->formatPlain($this->_printer)
);
}
}
\ No newline at end of file
<?php
namespace Doctrine\Tests\Common\CLI;
use Doctrine\Common\CLI\Option;
require_once __DIR__ . '/../../TestInit.php';
class OptionTest extends \Doctrine\Tests\DoctrineTestCase
{
public function testGetMethods()
{
$option = new Option('name', 'value', 'Description');
$this->assertEquals('name', $option->getName());
$this->assertEquals('value', $option->getDefaultValue());
$this->assertEquals('Description', $option->getDescription());
}
public function testStringCastWithDefaultValue()
{
$option = new Option('name', 'value', 'Description');
$this->assertEquals('--name=value', (string) $option);
}
public function testStringCastWithoutDefaultValue()
{
$option = new Option('name', null, 'Description');
$this->assertEquals('--name', (string) $option);
}
public function testStringCastWithArrayDefaultValue()
{
$option = new Option('name', array('value1', 'value2'), 'Description');
$this->assertEquals('--name=value1,value2', (string) $option);
}
}
\ No newline at end of file
<?php
namespace Doctrine\Tests\Common\CLI;
use Doctrine\Common\CLI\Style;
require_once __DIR__ . '/../../TestInit.php';
class StyleTest extends \Doctrine\Tests\DoctrineTestCase
{
public function testGetMethods()
{
$style = new Style('BLACK', 'WHITE', array('BOLD' => true));
$this->assertEquals('BLACK', $style->getForeground());
$this->assertEquals('WHITE', $style->getBackground());
$this->assertEquals(array('BOLD' => true), $style->getOptions());
}
}
\ No newline at end of file
......@@ -13,6 +13,9 @@ require_once __DIR__ . '/../../../lib/Doctrine/Common/ClassLoader.php';
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Symfony', __DIR__ . "/../../../lib/vendor");
$classLoader->register();
if (!file_exists(__DIR__."/Proxies")) {
if (!mkdir(__DIR__."/Proxies")) {
throw new Exception("Could not create " . __DIR__."/Proxies Folder.");
......@@ -24,15 +27,6 @@ if (!file_exists(__DIR__."/ORM/Proxy/generated")) {
}
}
spl_autoload_register(function($class) {
if (strpos($class, 'Symfony') === 0) {
$file = str_replace("\\", "/", $class);
if (@fopen($class, "r")) {
require_once ($file);
}
}
});
set_include_path(
__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lib'
. PATH_SEPARATOR .
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment