Skip to content

Commit

Permalink
chore: Code cleanup and small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Huber committed Feb 3, 2025
1 parent 18801a3 commit ebd0996
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/Configuration/HostConfigAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Phabalicious\Configuration;

use ArrayAccess;
use Phabalicious\Configuration\Storage\Node;
use Phabalicious\Method\BaseMethod;
use Phabalicious\ShellProvider\ShellProviderInterface;
Expand Down
7 changes: 4 additions & 3 deletions src/Method/ArtifactsGitMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function getDefaultConfig(ConfigurationService $configuration_service, No
],
];

$return['gitRootFolder'] = $configuration_service->getFabfilePath();
$return['deployMethod'] = 'git-sync';

return $parent->merge(new Node($return, $this->getName().' method defaults'));
Expand Down Expand Up @@ -186,7 +187,7 @@ protected function pullTargetRepository(HostConfig $host_config, TaskContextInte
$shell = $context->get('outerShell', $host_config->shell());
$branch_exists = $shell->run(
sprintf('#!git ls-remote -h --exit-code %s %s', $target_repository, $target_branch),
true
RunOptions::CAPTURE_AND_HIDE_OUTPUT
)->succeeded();
$branch_to_clone = $branch_exists ? $target_branch : $host_config[self::PREFS_KEY]['baseBranch'] ?? 'master';
$clone_options = $host_config[self::PREFS_KEY]['gitOptions']['clone'] ?? [];
Expand All @@ -205,7 +206,7 @@ protected function pullTargetRepository(HostConfig $host_config, TaskContextInte
$shell->run(sprintf('#!git push --set-upstream origin %s', $target_branch));
}

$log = $shell->run('#!git log --format="%H|%s"', true);
$log = $shell->run('#!git log --format="%H|%s"', RunOptions::CAPTURE_AND_HIDE_OUTPUT);
$found = false;
$last_successful_deployment_hash = false;
$new_commits_since_last_deployment = [];
Expand All @@ -231,7 +232,7 @@ protected function pullTargetRepository(HostConfig $host_config, TaskContextInte
'#!git diff %s..%s --name-only',
$last_successful_deployment_hash,
$new_commits_since_last_deployment[0]['hash']
), true);
), RunOptions::CAPTURE_AND_HIDE_OUTPUT);
$context->io()->note('Changed files:');
$context->io()->listing($affected_files->getOutput());
}
Expand Down
3 changes: 2 additions & 1 deletion src/Scaffolder/TwigExtensions/GetSecretExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Phabalicious\Utilities\PasswordManagerInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class GetSecretExtension extends AbstractExtension
{
Expand All @@ -20,7 +21,7 @@ public function __construct(PasswordManagerInterface $password_manager)
public function getFunctions(): array
{
return [
new \Twig\TwigFunction('secret', [$this, 'getSecret']),
new TwigFunction('secret', [$this, 'getSecret']),
];
}

Expand Down
3 changes: 2 additions & 1 deletion src/Scaffolder/TwigExtensions/Md5Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace Phabalicious\Scaffolder\TwigExtensions;

use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

class Md5Extension extends AbstractExtension
{
public function getFilters(): array
{
return [
new \Twig\TwigFilter('md5', 'md5'),
new TwigFilter('md5', 'md5'),
];
}

Expand Down
1 change: 1 addition & 0 deletions src/Utilities/PluginDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Composer\Autoload\ClassLoader;
use Composer\Semver\Comparator;
use Exception;
use Phabalicious\Configuration\ConfigurationService;
use Phabalicious\Exception\MismatchedVersionException;
use Psr\Container\ContainerInterface;
Expand Down
8 changes: 5 additions & 3 deletions tests/ConfigurationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Phabalicious\Configuration\ConfigurationService;
use Phabalicious\Configuration\Storage\Node;
use Phabalicious\Exception\FabfileNotFoundException;
use Phabalicious\Exception\MismatchedVersionException;
use Phabalicious\Method\DrushMethod;
use Phabalicious\Method\LocalMethod;
use Phabalicious\Method\MethodFactory;
Expand Down Expand Up @@ -60,7 +62,7 @@ public function testCustomFabfile()

public function testNonExistingCustomFabfile()
{
$this->expectException(\Phabalicious\Exception\FabfileNotFoundException::class);
$this->expectException(FabfileNotFoundException::class);
$result = $this->config->readConfiguration(
__DIR__,
__DIR__.'/assets/custom__not_existing.yaml'
Expand Down Expand Up @@ -99,15 +101,15 @@ public function testRegularFabfileInSubSubSubFolder()

public function testNonExistingFabfile()
{
$this->expectException(\Phabalicious\Exception\FabfileNotFoundException::class);
$this->expectException(FabfileNotFoundException::class);
$result = $this->config->readConfiguration(
__DIR__.'/assets/non-existing-fabfile-tests/one/two/three'
);
}

public function testNonMatchingVersion()
{
$this->expectException(\Phabalicious\Exception\MismatchedVersionException::class);
$this->expectException(MismatchedVersionException::class);
$application = $this->getMockBuilder(Application::class)
->setMethods(['getVersion'])
->getMock();
Expand Down
3 changes: 2 additions & 1 deletion tests/GitMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Phabalicious\Method\TaskContext;
use Phabalicious\ShellProvider\ShellProviderInterface;
use Psr\Log\AbstractLogger;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -35,7 +36,7 @@ class GitMethodTest extends PhabTestCase
public function setUp(): void
{
$logger = $this->getMockBuilder(AbstractLogger::class)->getMock();
$app = $this->getMockBuilder(\Symfony\Component\Console\Application::class)->getMock();
$app = $this->getMockBuilder(Application::class)->getMock();
$this->method = new GitMethod($logger);
$this->configurationService = new ConfigurationService($app, $logger);

Expand Down
3 changes: 2 additions & 1 deletion tests/WebhookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Phabalicious\Method\TaskContext;
use Phabalicious\Method\WebhookMethod;
use Psr\Log\AbstractLogger;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -27,7 +28,7 @@ class WebhookTest extends PhabTestCase
public function setup(): void
{
$logger = $this->getMockBuilder(AbstractLogger::class)->getMock();
$app = $this->getMockBuilder(\Symfony\Component\Console\Application::class)->getMock();
$app = $this->getMockBuilder(Application::class)->getMock();
$this->method = new WebhookMethod($logger);
$this->configurationService = new ConfigurationService($app, $logger);

Expand Down

0 comments on commit ebd0996

Please sign in to comment.