Skip to content

Commit

Permalink
chore: Code style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stmh committed Nov 3, 2024
1 parent f35af96 commit d294857
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 141 deletions.
15 changes: 8 additions & 7 deletions tests/GitMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@
use Phabalicious\Method\MethodFactory;
use Phabalicious\Method\ScriptMethod;
use Phabalicious\Method\TaskContext;
use Phabalicious\ShellProvider\ShellProviderInterface;
use Psr\Log\AbstractLogger;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class GitMethodTest extends PhabTestCase
{
/** @var GitMethod */
private $method;
private GitMethod $method;

/** @var ConfigurationService */
private $configurationService;
private ConfigurationService $configurationService;

/** @var TaskContext */
private $context;
private TaskContext $context;

/**
* @throws \Phabalicious\Exception\BlueprintTemplateNotFoundException
Expand Down Expand Up @@ -54,7 +55,7 @@ public function setUp(): void
$this->context->setConfigurationService($this->configurationService);
}

private function setupRepo(HostConfig $host_config)
private function setupRepo(HostConfig $host_config): ShellProviderInterface
{
$shell = $host_config->shell();
$shell->cd($host_config['gitRootFolder']);
Expand All @@ -68,14 +69,14 @@ private function setupRepo(HostConfig $host_config)
return $shell;
}

private function cleanupRepo(HostConfig $host_config)
private function cleanupRepo(HostConfig $host_config): void
{
$shell = $host_config->shell();
$shell->cd($host_config['gitRootFolder']);
$shell->run('rm -rf .git');
}

public function testGetVersion()
public function testGetVersion(): void
{
$host_config = $this->configurationService->getHostConfig('hostA');
$this->setupRepo($host_config);
Expand All @@ -84,7 +85,7 @@ public function testGetVersion()
$this->assertTrue($this->method->isWorkingcopyClean($host_config, $this->context));
}

public function testDirtyWorkingCopy()
public function testDirtyWorkingCopy(): void
{
$host_config = $this->configurationService->getHostConfig('hostA');
$shell = $this->setupRepo($host_config);
Expand Down
20 changes: 8 additions & 12 deletions tests/K8sScaffoldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Phabalicious\Method\MethodFactory;
use Phabalicious\Method\ScriptMethod;
use Phabalicious\Utilities\Utilities;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\ConsoleOutput;
Expand All @@ -24,21 +25,16 @@
class K8sScaffoldTest extends PhabTestCase
{
/** @var Application */
protected $application;
protected Application $application;

/** @var ConfigurationService */
protected $configuration;

/**
* @var \PHPUnit\Framework\MockObject\MockObject|\Psr\Log\LoggerInterface
*/
private $logger;
protected ConfigurationService $configuration;

public function setup(): void
{
$this->application = new Application();
$this->application->setVersion(Utilities::FALLBACK_VERSION);
$this->logger = $logger = new ConsoleLogger(new ConsoleOutput());
$logger = new ConsoleLogger(new ConsoleOutput());

$this->configuration = new ConfigurationService($this->application, $logger);
$method_factory = new MethodFactory($this->configuration, $logger);
Expand All @@ -52,7 +48,7 @@ public function setup(): void
}


public function testK8sScaffold()
public function testK8sScaffold(): void
{
chdir($this->configuration->getFabfilePath());
system('echo "hello world" > kube/should-not-exist.yml');
Expand All @@ -67,10 +63,10 @@ public function testK8sScaffold()
$this->assertEquals('foo', $yaml['data']['valueA']);
$this->assertEquals('bar', $yaml['data']['valueB']);

$this->assertFalse(file_exists('kube/should-not-exist.yml'));
$this->assertFileDoesNotExist('kube/should-not-exist.yml');
}

public function testK8sScaffoldOverridden()
public function testK8sScaffoldOverridden(): void
{
chdir($this->configuration->getFabfilePath());
$command = $this->application->find('k8s');
Expand All @@ -86,7 +82,7 @@ public function testK8sScaffoldOverridden()
}


public function testK8sScaffoldWithNameiInQuestion()
public function testK8sScaffoldWithNameiInQuestion(): void
{
chdir($this->configuration->getFabfilePath());
$command = $this->application->find('k8s');
Expand Down
13 changes: 7 additions & 6 deletions tests/LaravelMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Phabalicious\Configuration\ConfigurationService;
use Phabalicious\Configuration\Storage\Node;
use Phabalicious\Method\DrushMethod;
use Phabalicious\Method\LaravelMethod;
use Phabalicious\Method\MethodFactory;
use Phabalicious\Method\MysqlMethod;
Expand All @@ -13,11 +14,11 @@

class LaravelMethodTest extends PhabTestCase
{
/** @var \Phabalicious\Method\DrushMethod */
private $method;
/** @var \Phabalicious\Method\LaravelMethod */
private LaravelMethod $method;

/** @var ConfigurationService */
private $configurationService;
private ConfigurationService $configurationService;

public function setup(): void
{
Expand All @@ -34,7 +35,7 @@ public function setup(): void
$this->configurationService->readConfiguration(__DIR__ . '/assets/laravel-tests/fabfile.yaml');
}

public function testGetDefaultConfig()
public function testGetDefaultConfig(): void
{
$host_config = [
'rootFolder' => '.',
Expand All @@ -50,7 +51,7 @@ public function testGetDefaultConfig()
$this->assertEquals(['mycustomresettask'], $result['artisanTasks']['reset']);
}

public function testCustomArtisanTasks()
public function testCustomArtisanTasks(): void
{
$result = $this->configurationService->getHostConfig('test-custom-artisan-tasks');
$this->assertArrayHasKey('reset', $result['artisanTasks']);
Expand All @@ -59,7 +60,7 @@ public function testCustomArtisanTasks()
$this->assertEquals(['mycustominstalltask'], $result['artisanTasks']['install']);
}

public function testDefaultCustomArtisanTasks()
public function testDefaultCustomArtisanTasks(): void
{
$result = $this->configurationService->getHostConfig('test-default-custom-artisan-tasks');
$this->assertArrayHasKey('reset', $result['artisanTasks']);
Expand Down
42 changes: 23 additions & 19 deletions tests/LocalShellProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Phabalicious\Configuration\Storage\Node;
use Phabalicious\Method\TaskContext;
use Phabalicious\ShellProvider\LocalShellProvider;
use Phabalicious\ShellProvider\ShellProviderInterface;
use Phabalicious\Utilities\PasswordManager;
use Phabalicious\Validation\ValidationErrorBag;
use PHPUnit\Framework\TestCase;
Expand All @@ -18,22 +19,25 @@
class LocalShellProviderTest extends PhabTestCase
{
/** @var \Phabalicious\ShellProvider\ShellProviderInterface */
private $shellProvider;
private ShellProviderInterface $shellProvider;

private $config;
private ConfigurationService $config;

/**
* @var \Phabalicious\Method\TaskContext
*/
private $context;
private TaskContext $context;

public function setUp(): void
{
$this->config = $this->getMockBuilder(ConfigurationService::class)
->disableOriginalConstructor()
->getMock();

$this->config->method("getPasswordManager")->will($this->returnValue(new PasswordManager()));
$this
->config
->method("getPasswordManager")
->willReturn(new PasswordManager());

$logger = $this->getMockBuilder(AbstractLogger::class)->getMock();

Expand All @@ -47,13 +51,13 @@ public function setUp(): void
$this->context->setConfigurationService($this->config);
}

public function testGetDefaultConfig()
public function testGetDefaultConfig(): void
{
$config = $this->shellProvider->getDefaultConfig($this->config, new Node([], ''));
$this->assertArrayHasKey('rootFolder', $config);
}

public function testValidateConfig()
public function testValidateConfig(): void
{
$errors = new ValidationErrorBag();
$this->shellProvider->validateConfig(new Node([], ''), $errors);
Expand All @@ -63,7 +67,7 @@ public function testValidateConfig()
);
}

public function testValidateConfigRootFolder()
public function testValidateConfigRootFolder(): void
{
$errors = new ValidationErrorBag();
$config = new Node(['rootFolder' => '/var/www/', 'shellExecutable' => '/bin/bash'], '');
Expand All @@ -74,19 +78,19 @@ public function testValidateConfigRootFolder()
);
}

public function testGetName()
public function testGetName(): void
{
$this->assertEquals('local', $this->shellProvider->getName());
}

public function testRun()
public function testRun(): void
{
$host_config = new HostConfig([
'shellExecutable' => '/bin/sh',
'rootFolder' => dirname(__FILE__)
'rootFolder' => __DIR__
], $this->shellProvider, $this->config);

$test_dir = dirname(__FILE__) . '/assets/local-shell-provider';
$test_dir = __DIR__ . '/assets/local-shell-provider';

$this->shellProvider->setHostConfig($host_config);

Expand All @@ -106,14 +110,14 @@ public function testRun()
$this->assertEquals($test_dir, trim($result->getOutput()[0]));
}

public function testFailedRun()
public function testFailedRun(): void
{
$host_config = new HostConfig([
'shellExecutable' => '/bin/bash',
'rootFolder' => dirname(__FILE__)
'rootFolder' => __DIR__
], $this->shellProvider, $this->config);

$test_dir = dirname(__FILE__) . '/assets/local-shell-providerxxx';
$test_dir = __DIR__ . '/assets/local-shell-providerxxx';

$this->shellProvider->setHostConfig($host_config);

Expand All @@ -126,11 +130,11 @@ public function testFailedRun()
$this->assertStringNotContainsString(LocalShellProvider::RESULT_IDENTIFIER, $output);
}

public function testHostEnvironment()
public function testHostEnvironment(): void
{
$host_config = new HostConfig([
'shellExecutable' => '/bin/bash',
'rootFolder' => dirname(__FILE__),
'rootFolder' => __DIR__,
'varC' => 'variable_c',
'environment' => [
'VAR_A' => 'variable_a',
Expand All @@ -139,7 +143,7 @@ public function testHostEnvironment()
],
], $this->shellProvider, $this->config);

$test_dir = dirname(__FILE__) . '/assets/local-shell-provider';
$test_dir = __DIR__ . '/assets/local-shell-provider';

$this->shellProvider->setHostConfig($host_config);

Expand Down Expand Up @@ -167,15 +171,15 @@ public function testHostEnvironment()
$this->assertStringContainsString('XXvariable_cXX', $output);
}

public function testFileGetContents()
public function testFileGetContents(): void
{
$file = __FILE__;
$test = $this->shellProvider->getFileContents($file, $this->context);
$original = file_get_contents($file);
$this->assertEquals($original, $test);
}

public function testFilePutContents()
public function testFilePutContents(): void
{
$content = 'helloworld';
$result = $this->shellProvider->putFileContents('/tmp/test_put_file_content', $content, $this->context);
Expand Down
13 changes: 6 additions & 7 deletions tests/MethodFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ class MethodFactoryTest extends PhabTestCase
/**
* @var MethodFactory
*/
private $methods;
private MethodFactory $methods;

public function setUp(): void
{
parent::setUp(); // TODO: Change the autogenerated stub

$application = $this->getMockBuilder(Application::class)->getMock();
$logger = $this->getMockBuilder(AbstractLogger::class)->getMock();
$config_factory = $this->getMockBuilder(ConfigurationService::class)
->disableOriginalConstructor()
Expand All @@ -29,18 +28,18 @@ public function setUp(): void
$this->methods = new MethodFactory($config_factory, $logger);
}

public function testGetMethod()
public function testGetMethod(): void
{
$method = $this->getMockBuilder(BaseMethod::class)
->setMethods(['getName', 'supports'])
->disableOriginalConstructor()
->getMock();
$method->expects($this->any())
$method
->method('getName')
->will($this->returnValue('mocked_method'));
$method->expects($this->any())
->willReturn('mocked_method');
$method
->method('supports')
->will($this->returnValue(true));
->willReturn(true);

$this->methods->addMethod($method);

Expand Down
Loading

0 comments on commit d294857

Please sign in to comment.