-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ACMS-3658: More PHPUnit tests added.
- Loading branch information
1 parent
408bbdb
commit 0dea087
Showing
8 changed files
with
406 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace Acquia\Drupal\RecommendedSettings\Tests; | ||
|
||
use Acquia\Drupal\RecommendedSettings\Robo\Config\ConfigAwareTrait; | ||
use Acquia\Drupal\RecommendedSettings\Tests\Helpers\NullLogOutputStylers; | ||
use Consolidation\Log\Logger; | ||
use League\Container\Container; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Container\ContainerInterface; | ||
use Robo\Collection\CollectionBuilder; | ||
use Robo\Common\BuilderAwareTrait; | ||
use Robo\Common\OutputAwareTrait; | ||
use Robo\Config\Config; | ||
use Robo\Robo; | ||
use Robo\Tasks; | ||
use Symfony\Component\Console\Output\NullOutput; | ||
|
||
/** | ||
* Base commands to test drush commands/tasks. | ||
*/ | ||
abstract class CommandsTestBase extends TestCase { | ||
use BuilderAwareTrait; | ||
use OutputAwareTrait; | ||
use ConfigAwareTrait; | ||
|
||
/** | ||
* Stores an instance of container object. | ||
*/ | ||
protected ContainerInterface $container; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp(): void { | ||
parent::setUp(); | ||
$this->createContainer(); | ||
} | ||
|
||
/** | ||
* Initialize the Container. | ||
* | ||
* @param ContainerInterface|null $container | ||
* An instance of container object or NULL. | ||
*/ | ||
protected function createContainer(?ContainerInterface $container = NULL): void { | ||
if (!$container) { | ||
$container = new Container(); | ||
$output = new NullOutput(); | ||
$this->setOutput($output); | ||
|
||
$config = new Config(); | ||
$this->setConfig($config); | ||
$logger = new Logger($this->output()); | ||
$null_log_output = new NullLogOutputStylers; | ||
$logger->setLogOutputStyler($null_log_output); | ||
$container->add("logger", $logger); | ||
|
||
$app = Robo::createDefaultApplication("acquia/drupal-recommended-settings", "1.0.0"); | ||
Robo::configureContainer($container, $app, $this->getConfig()); | ||
|
||
$tasks = new Tasks(); | ||
$builder = CollectionBuilder::create($container, $tasks); | ||
$this->setBuilder($builder); | ||
$container->add("builder", $builder); | ||
} | ||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* Returns an instance of container object. | ||
*/ | ||
protected function getContainer(): ContainerInterface { | ||
return $this->container; | ||
} | ||
|
||
} |
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,19 @@ | ||
<?php | ||
|
||
namespace Acquia\Drupal\RecommendedSettings\Tests\Helpers; | ||
|
||
use Consolidation\Log\SymfonyLogOutputStyler; | ||
|
||
/** | ||
* Class for not logging any error. | ||
*/ | ||
class NullLogOutputStylers extends SymfonyLogOutputStyler { | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
#[Override] | ||
public function error($symfonyStyle, $level, $message, $context): void { | ||
} | ||
|
||
} |
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,24 @@ | ||
<?php | ||
|
||
namespace Acquia\Drupal\RecommendedSettings\Tests\Helpers; | ||
|
||
use Acquia\Drupal\RecommendedSettings\Robo\Tasks\DrushTask; | ||
use Robo\ResultData; | ||
|
||
class TestDrushTask extends DrushTask { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
#[Override] | ||
protected function execute($process, $output_callback = NULL): ResultData { | ||
$command = $process->getCommandLine(); | ||
$command_arr = explode(" ", $command); | ||
$process->disableOutput(); | ||
if (in_array("--error", $command_arr)) { | ||
return new ResultData(ResultData::EXITCODE_ERROR, $command, []); | ||
} | ||
return new ResultData(ResultData::EXITCODE_OK, $command, []); | ||
} | ||
|
||
} |
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,35 @@ | ||
<?php | ||
|
||
namespace Acquia\Drupal\RecommendedSettings\Tests\Unit\Robo\Config; | ||
|
||
use Acquia\Drupal\RecommendedSettings\Config\DefaultDrushConfig; | ||
use Acquia\Drupal\RecommendedSettings\Robo\Config\ConfigAwareTrait; | ||
use Drush\Config\DrushConfig; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Unit test for the ConfigAwareTrait trait. | ||
* | ||
* @covers \Acquia\Drupal\RecommendedSettings\Robo\Config\ConfigAwareTrait | ||
*/ | ||
class ConfigAwareTraitTest extends TestCase { | ||
|
||
use ConfigAwareTrait; | ||
|
||
/** | ||
* Tests the getConfigValue() for ConfigAwareTrait trait. | ||
*/ | ||
public function testGetConfigValue(): void { | ||
$this->assertEquals( | ||
"/var/www/html/acms.prod/vendor", | ||
$this->getConfigValue("composer.bin", "/var/www/html/acms.prod/vendor"), | ||
); | ||
$config = new DrushConfig(); | ||
$config->set("runtime.project", "/var/www/html/acms.prod"); | ||
$config->set("options.root", "/var/www/html/acms.prod/docroot"); | ||
$drush_config = new DefaultDrushConfig($config); | ||
$this->setConfig($drush_config); | ||
$this->assertEquals("/var/www/html/acms.prod", $this->getConfigValue("repo.root")); | ||
} | ||
|
||
} |
Oops, something went wrong.