magallanes/tests/MageTest/Command/AbstractCommandTest.php

271 lines
11 KiB
PHP
Raw Normal View History

2015-02-19 21:34:30 +01:00
<?php
namespace MageTest\Command;
2015-02-19 21:34:30 +01:00
use Mage\Command\AbstractCommand;
use MageTest\TestHelper\BaseTest;
2015-02-19 21:34:30 +01:00
use PHPUnit_Framework_MockObject_MockObject;
/**
* Class AbstractCommandTest
* @package MageTest\Command
2015-02-20 16:16:18 +01:00
* @author Jakub Turek <ja@kubaturek.pl>
2015-02-19 21:34:30 +01:00
* @coversDefaultClass Mage\Command\AbstractCommand
*/
class AbstractCommandTest extends BaseTest
2015-02-19 21:34:30 +01:00
{
/**
* @var AbstractCommand|PHPUnit_Framework_MockObject_MockObject
*/
private $abstractCommand;
/**
* @before
*/
public function before()
{
$this->abstractCommand = $this->getMockForAbstractClass('Mage\Command\AbstractCommand');
}
/**
* @covers ::setConfig
*/
public function testSetConfig()
{
$configMock = $this->getMock('Mage\Config');
$this->doTestSetter($this->abstractCommand, 'config', $configMock);
2015-02-19 21:34:30 +01:00
}
/**
* @covers ::getConfig
*/
public function testGetConfig()
{
$configMock = $this->getMock('Mage\Config');
$this->doTestGetter($this->abstractCommand, 'config', $configMock);
2015-02-19 21:34:30 +01:00
}
2015-03-07 23:08:52 +01:00
public function infoMessageProvider()
{
2015-03-08 12:24:21 +01:00
return array(
'happy_path' => array(
2015-03-08 12:23:42 +01:00
'name' => 'Example command',
2015-03-07 23:08:52 +01:00
'helpMessage' => 'This command does everything you want to',
2015-03-08 12:24:21 +01:00
'examples' => array(
array(
2015-03-07 23:08:52 +01:00
'snippet' => 'mage example',
'description' => 'Default command'
2015-03-08 12:24:21 +01:00
),
array(
2015-03-07 23:08:52 +01:00
'snippet' => 'mage example light',
'description' => 'Runs the command with lights'
2015-03-08 12:24:21 +01:00
)
),
2015-03-07 23:08:52 +01:00
'syntax' => 'mage example [light]',
'output' => "\n"
2015-03-08 12:23:42 +01:00
. "<cyan><bold>Command: </bold></cyan>Example command\n"
. "<light_blue>This command does everything you want to</light_blue>\n"
2015-03-07 23:08:52 +01:00
. "\n"
. "<light_gray><bold>Syntax:</bold></light_gray>\n"
. " <light_green>mage example [light]</light_green>\n"
2015-03-07 23:08:52 +01:00
. "\n"
. "<light_gray><bold>Usage examples:</bold></light_gray>\n"
2015-03-07 23:08:52 +01:00
. " * Default command:\n"
. " <green>mage example</green>\n"
2015-03-07 23:08:52 +01:00
. " * Runs the command with lights:\n"
. " <green>mage example light</green>\n"
2015-03-08 12:24:21 +01:00
),
'no_help_message' => array(
2015-03-08 12:23:42 +01:00
'name' => 'Example command',
2015-03-07 23:08:52 +01:00
'helpMessage' => '',
2015-03-08 12:24:21 +01:00
'examples' => array(
array(
2015-03-07 23:08:52 +01:00
'snippet' => 'mage example',
'description' => 'Default command'
2015-03-08 12:24:21 +01:00
),
array(
2015-03-07 23:08:52 +01:00
'snippet' => 'mage example light',
'description' => 'Runs the command with lights'
2015-03-08 12:24:21 +01:00
)
),
2015-03-07 23:08:52 +01:00
'syntax' => 'mage example [light]',
'output' => "\n"
2015-03-08 12:23:42 +01:00
. "<cyan><bold>Command: </bold></cyan>Example command\n"
. "<light_gray><bold>Syntax:</bold></light_gray>\n"
. " <light_green>mage example [light]</light_green>\n"
2015-03-07 23:08:52 +01:00
. "\n"
. "<light_gray><bold>Usage examples:</bold></light_gray>\n"
2015-03-07 23:08:52 +01:00
. " * Default command:\n"
. " <green>mage example</green>\n"
2015-03-07 23:08:52 +01:00
. " * Runs the command with lights:\n"
. " <green>mage example light</green>\n"
2015-03-08 12:24:21 +01:00
),
'no_examples' => array(
2015-03-08 12:23:42 +01:00
'name' => 'Example command',
2015-03-07 23:08:52 +01:00
'helpMessage' => 'This command does everything you want to',
2015-03-08 12:24:21 +01:00
'examples' => array(),
2015-03-07 23:08:52 +01:00
'syntax' => 'mage example [light]',
'output' => "\n"
2015-03-08 12:23:42 +01:00
. "<cyan><bold>Command: </bold></cyan>Example command\n"
. "<light_blue>This command does everything you want to</light_blue>\n"
2015-03-07 23:08:52 +01:00
. "\n"
. "<light_gray><bold>Syntax:</bold></light_gray>\n"
. " <light_green>mage example [light]</light_green>\n"
2015-03-08 12:24:21 +01:00
),
"no_syntax" => array(
2015-03-08 12:23:42 +01:00
'name' => 'Example command',
2015-03-07 23:08:52 +01:00
'helpMessage' => 'This command does everything you want to',
2015-03-08 12:24:21 +01:00
'examples' => array(
array(
2015-03-07 23:08:52 +01:00
'snippet' => 'mage example',
'description' => 'Default command'
2015-03-08 12:24:21 +01:00
),
array(
2015-03-07 23:08:52 +01:00
'snippet' => 'mage example light',
'description' => 'Runs the command with lights'
2015-03-08 12:24:21 +01:00
)
),
2015-03-07 23:08:52 +01:00
'syntax' => '',
'output' => "\n"
2015-03-08 12:23:42 +01:00
. "<cyan><bold>Command: </bold></cyan>Example command\n"
. "<light_blue>This command does everything you want to</light_blue>\n"
2015-03-07 23:08:52 +01:00
. "\n"
. "<light_gray><bold>Usage examples:</bold></light_gray>\n"
2015-03-07 23:08:52 +01:00
. " * Default command:\n"
. " <green>mage example</green>\n"
2015-03-07 23:08:52 +01:00
. " * Runs the command with lights:\n"
. " <green>mage example light</green>\n"
2015-03-08 12:24:21 +01:00
),
"stripping_colons" => array(
2015-03-08 12:23:42 +01:00
'name' => 'Example command',
2015-03-07 23:08:52 +01:00
'helpMessage' => 'This command does everything you want to',
2015-03-08 12:24:21 +01:00
'examples' => array(
array(
2015-03-07 23:08:52 +01:00
'snippet' => 'mage example',
2015-03-08 12:23:42 +01:00
'description' => 'Default command : '
2015-03-08 12:24:21 +01:00
),
array(
2015-03-07 23:08:52 +01:00
'snippet' => 'mage example light',
2015-03-08 12:23:42 +01:00
'description' => 'Runs the command with lights: '
2015-03-08 12:24:21 +01:00
)
),
2015-03-07 23:08:52 +01:00
'syntax' => 'mage example [light]',
'output' => "\n"
2015-03-08 12:23:42 +01:00
. "<cyan><bold>Command: </bold></cyan>Example command\n"
. "<light_blue>This command does everything you want to</light_blue>\n"
2015-03-07 23:08:52 +01:00
. "\n"
. "<light_gray><bold>Syntax:</bold></light_gray>\n"
. " <light_green>mage example [light]</light_green>\n"
2015-03-07 23:08:52 +01:00
. "\n"
. "<light_gray><bold>Usage examples:</bold></light_gray>\n"
2015-03-07 23:08:52 +01:00
. " * Default command:\n"
. " <green>mage example</green>\n"
2015-03-07 23:08:52 +01:00
. " * Runs the command with lights:\n"
. " <green>mage example light</green>\n"
2015-03-08 12:24:21 +01:00
),
"only_help" => array(
2015-03-08 12:23:42 +01:00
'name' => 'Example command',
2015-03-07 23:08:52 +01:00
'helpMessage' => 'This command does everything you want to',
2015-03-08 12:24:21 +01:00
'examples' => array(),
2015-03-07 23:08:52 +01:00
'syntax' => '',
'output' => "\n"
2015-03-08 12:23:42 +01:00
. "<cyan><bold>Command: </bold></cyan>Example command\n"
. "<light_blue>This command does everything you want to</light_blue>\n"
2015-03-08 12:24:21 +01:00
),
"only_examples" => array(
2015-03-08 12:23:42 +01:00
'name' => 'Example command',
2015-03-07 23:08:52 +01:00
'helpMessage' => '',
2015-03-08 12:24:21 +01:00
'examples' => array(
array(
2015-03-07 23:08:52 +01:00
'snippet' => 'mage example',
'description' => 'Default command'
2015-03-08 12:24:21 +01:00
),
array(
2015-03-07 23:08:52 +01:00
'snippet' => 'mage example light',
'description' => 'Runs the command with lights'
2015-03-08 12:24:21 +01:00
)
),
2015-03-07 23:08:52 +01:00
'syntax' => '',
'output' => "\n"
2015-03-08 12:23:42 +01:00
. "<cyan><bold>Command: </bold></cyan>Example command\n"
. "<light_gray><bold>Usage examples:</bold></light_gray>\n"
2015-03-07 23:08:52 +01:00
. " * Default command:\n"
. " <green>mage example</green>\n"
2015-03-07 23:08:52 +01:00
. " * Runs the command with lights:\n"
. " <green>mage example light</green>\n"
2015-03-08 12:24:21 +01:00
),
"only_syntax" => array(
2015-03-08 12:23:42 +01:00
'name' => 'Example command',
2015-03-07 23:08:52 +01:00
'helpMessage' => '',
2015-03-08 12:24:21 +01:00
'examples' => array(),
2015-03-07 23:08:52 +01:00
'syntax' => 'mage example [light]',
'output' => "\n"
2015-03-08 12:23:42 +01:00
. "<cyan><bold>Command: </bold></cyan>Example command\n"
. "<light_gray><bold>Syntax:</bold></light_gray>\n"
. " <light_green>mage example [light]</light_green>\n"
2015-03-08 12:24:21 +01:00
),
"no_name" => array(
2015-03-08 12:23:42 +01:00
'name' => '',
'helpMessage' => 'This command does everything you want to',
2015-03-08 12:24:21 +01:00
'examples' => array(
array(
2015-03-08 12:23:42 +01:00
'snippet' => 'mage example',
'description' => 'Default command'
2015-03-08 12:24:21 +01:00
),
array(
2015-03-08 12:23:42 +01:00
'snippet' => 'mage example light',
'description' => 'Runs the command with lights'
2015-03-08 12:24:21 +01:00
)
),
2015-03-08 12:23:42 +01:00
'syntax' => 'mage example [light]',
'output' => "\n"
. "<light_blue>This command does everything you want to</light_blue>\n"
. "\n"
. "<light_gray><bold>Syntax:</bold></light_gray>\n"
. " <light_green>mage example [light]</light_green>\n"
. "\n"
. "<light_gray><bold>Usage examples:</bold></light_gray>\n"
. " * Default command:\n"
. " <green>mage example</green>\n"
. " * Runs the command with lights:\n"
. " <green>mage example light</green>\n"
),
"no_info_at_all" => array(
'name' => '',
'helpMessage' => '',
'examples' => array(),
'syntax' => '',
'output' => "\n"
. "<red><bold>Sorry, there's no help for this command at the moment.</bold></red>\n"
2015-03-08 12:24:21 +01:00
)
);
2015-03-07 23:08:52 +01:00
}
/**
* @covers ::getInfoMessage
* @covers ::setHelpMessage
* @covers ::addUsageExample
* @covers ::setSyntaxMessage
2015-03-08 12:44:37 +01:00
* @covers ::setName
2015-03-07 23:08:52 +01:00
*
* @dataProvider infoMessageProvider
*/
2015-03-08 12:23:42 +01:00
public function testGetInfoMessage($name, $helpMessage, $examples, $syntax, $expectedMessage)
2015-03-07 23:08:52 +01:00
{
/** @var AbstractCommand $command */
$command = $this->getMockForAbstractClass('Mage\Command\AbstractCommand');
2015-03-08 12:23:42 +01:00
$command->setName($name);
2015-03-07 23:08:52 +01:00
foreach ($examples as $example) {
$command->addUsageExample($example['snippet'], $example['description']);
}
$command->setHelpMessage($helpMessage);
$command->setSyntaxMessage($syntax);
$actualMessage = $command->getInfoMessage();
$this->assertEquals($expectedMessage, $actualMessage);
}
2015-02-19 21:34:30 +01:00
}