-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAGETWO-41938: Creation of M2 Sample Command: Demonstrate how to add …
…new Commands to Command line interface - addressed review feedback
- Loading branch information
Showing
11 changed files
with
173 additions
and
117 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
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
53 changes: 53 additions & 0 deletions
53
...tom-deployment-config/Test/Unit/Console/Command/ShowCustomDeploymentConfigCommandTest.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,53 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\CustomDeploymentConfigExample\Test\Unit\Console\Command; | ||
|
||
use Magento\CustomDeploymentConfigExample\Console\Command\ShowCustomDeploymentConfigCommand; | ||
use Magento\CustomDeploymentConfigExample\Setup\ConfigOptionsList; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
class ShowCustomDeploymentConfigCommandTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $deploymentConfigMock; | ||
|
||
/** | ||
* @var CommandTester|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $commandTester; | ||
|
||
public function setUp() | ||
{ | ||
$this->deploymentConfigMock = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); | ||
$command = new ShowCustomDeploymentConfigCommand($this->deploymentConfigMock); | ||
$this->commandTester = new CommandTester($command); | ||
} | ||
|
||
public function testExecute() | ||
{ | ||
|
||
$this->deploymentConfigMock->expects($this->once()) | ||
->method('get') | ||
->with(ConfigOptionsList::CONFIG_PATH_CUSTOM_OPTION) | ||
->willReturn('value'); | ||
|
||
$this->commandTester->execute([]); | ||
$this->assertContains('value', $this->commandTester->getDisplay()); | ||
} | ||
|
||
public function testExecuteNoValue() | ||
{ | ||
$this->deploymentConfigMock->expects($this->once()) | ||
->method('get') | ||
->with(ConfigOptionsList::CONFIG_PATH_CUSTOM_OPTION) | ||
->willReturn(null); | ||
|
||
$this->commandTester->execute([]); | ||
$this->assertContains('is not set', $this->commandTester->getDisplay()); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
sample-module-custom-deployment-config/Test/Unit/Setup/ConfigOptionsListTest.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,89 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\CustomDeploymentConfigExample\Test\Unit\Setup; | ||
|
||
use Magento\CustomDeploymentConfigExample\Setup\ConfigOptionsList; | ||
|
||
class ConfigOptionsListTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var ConfigOptionsList | ||
*/ | ||
private $configOptionsList; | ||
|
||
/** | ||
* @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $deploymentConfigMock; | ||
|
||
public function setUp() | ||
{ | ||
$this->configOptionsList = new ConfigOptionsList(); | ||
$this->deploymentConfigMock = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); | ||
} | ||
|
||
public function testGetOptions() | ||
{ | ||
$this->assertInstanceOf( | ||
'Magento\Framework\Setup\Option\TextConfigOption', | ||
$this->configOptionsList->getOptions()[0] | ||
); | ||
} | ||
|
||
public function testCreateConfig() | ||
{ | ||
$data = $this->configOptionsList->createConfig( | ||
[ConfigOptionsList::INPUT_KEY_CUSTOM_OPTION => 'value'], | ||
$this->deploymentConfigMock | ||
); | ||
$this->assertCount(1, $data); | ||
$this->assertEquals(['example' => ['custom-option' => 'value']], $data[0]->getData()); | ||
} | ||
|
||
public function testCreateConfigNoValue() | ||
{ | ||
$this->deploymentConfigMock->expects($this->once()) | ||
->method('get') | ||
->with(ConfigOptionsList::CONFIG_PATH_CUSTOM_OPTION) | ||
->willReturn('some value'); | ||
$data = $this->configOptionsList->createConfig([], $this->deploymentConfigMock); | ||
$this->assertEquals([], $data[0]->getData()); | ||
} | ||
|
||
public function testCreateConfigNoValueDefault() | ||
{ | ||
$this->deploymentConfigMock->expects($this->once()) | ||
->method('get') | ||
->with(ConfigOptionsList::CONFIG_PATH_CUSTOM_OPTION) | ||
->willReturn(null); | ||
$data = $this->configOptionsList->createConfig([], $this->deploymentConfigMock); | ||
$this->assertEquals(['example' => ['custom-option' => 'default custom value']], $data[0]->getData()); | ||
} | ||
|
||
public function testValidate() | ||
{ | ||
$configOptionsList = new ConfigOptionsList(); | ||
$this->assertEquals( | ||
[], | ||
$configOptionsList->validate( | ||
[ConfigOptionsList::INPUT_KEY_CUSTOM_OPTION => 'value'], | ||
$this->deploymentConfigMock | ||
) | ||
); | ||
} | ||
|
||
public function testValidateInvalid() | ||
{ | ||
$configOptionsList = new ConfigOptionsList(); | ||
$this->assertEquals( | ||
['Invalid custom option value'], | ||
$configOptionsList->validate( | ||
[ConfigOptionsList::INPUT_KEY_CUSTOM_OPTION => 'invalid'], | ||
$this->deploymentConfigMock | ||
) | ||
); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ule-custom-deploymentconfig/composer.json → ...le-custom-deployment-config/composer.json
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
File renamed without changes.
39 changes: 0 additions & 39 deletions
39
...stom-deploymentconfig/Test/Unit/Console/Command/ShowCustomDeploymentConfigCommandTest.php
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.