Skip to content

Commit

Permalink
fix: Crash when doing copyFrom because of uninitialized vars, fix tes…
Browse files Browse the repository at this point in the history
…t code style
  • Loading branch information
Stephan Huber committed Jan 6, 2025
1 parent 8609c35 commit fcf29f6
Show file tree
Hide file tree
Showing 46 changed files with 588 additions and 715 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php → .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
$finder = (new PhpCsFixer\Finder())
->in(__DIR__)
->exclude('var')
->exclude(dirs:'node_modules')
;

return (new PhpCsFixer\Config())
Expand Down
2 changes: 1 addition & 1 deletion src/Method/DrushMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private function runDrush(ShellProviderInterface $shell, bool $throw_exception_o

return $shell->run(
$command,
false,
RunOptions::NONE,
$throw_exception_on_failure && $this->useStrictErrorHandling($shell->getHostConfig())
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/ShellProvider/DockerExecOverSshShellProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class DockerExecOverSshShellProvider extends SshShellProvider
{
public const PROVIDER_NAME = 'docker-exec-over-ssh';

protected DockerExecShellProvider $dockerExec;
protected ?DockerExecShellProvider $dockerExec = null;

/**
* Shell to run docker commands on host.
*/
protected ShellProviderInterface $sshShell;
protected ?ShellProviderInterface $sshShell = null;

public function __construct(LoggerInterface $logger)
{
Expand Down
16 changes: 8 additions & 8 deletions tests/AppCreateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AppCreateCommandTest extends PhabTestCase
/** @var Application */
protected $application;

/** @var \Phabalicious\Configuration\ConfigurationService */
/** @var ConfigurationService */
protected $configuration;

public function setup(): void
Expand All @@ -33,7 +33,7 @@ public function setup(): void
$method_factory->addMethod(new ScriptMethod($logger));
$method_factory->addMethod(new DockerMethod($logger));

$configuration->readConfiguration(__DIR__ . '/assets/app-create-tests/fabfile.yaml');
$configuration->readConfiguration(__DIR__.'/assets/app-create-tests/fabfile.yaml');
$this->configuration = $configuration;

$this->application->add(new AppCreateCommand($configuration, $method_factory));
Expand Down Expand Up @@ -61,10 +61,10 @@ public function testAppCreateWithoutPrepare()
/** @var AppCreateCommand $command */
$command = $this->application->find('app:create');
$commandTester = new CommandTester($command);
$commandTester->execute(array(
'--config' => 'test',
$commandTester->execute([
'--config' => 'test',
'--force' => 1,
));
]);

// the output of the command in the console
$output = $commandTester->getDisplay();
Expand Down Expand Up @@ -92,10 +92,10 @@ public function testAppCreateWithPrepare()

/** @var AppCreateCommand $command */
$commandTester = new CommandTester($command);
$commandTester->execute(array(
'--config' => 'testWithPrepare',
$commandTester->execute([
'--config' => 'testWithPrepare',
'--force' => 1,
));
]);

// the output of the command in the console
$output = $commandTester->getDisplay();
Expand Down
95 changes: 45 additions & 50 deletions tests/AppScaffoldCommandTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

/**
* Created by PhpStorm.
* User: stephan
* Date: 05.10.18
* Time: 12:27
* Time: 12:27.
*/

namespace Phabalicious\Tests;
Expand Down Expand Up @@ -46,13 +47,13 @@ public function testAppScaffolder()

$command = $this->application->find('app:scaffold');
$commandTester = new CommandTester($command);
$commandTester->execute(array(
'--short-name' => 'TST',
$commandTester->execute([
'--short-name' => 'TST',
'--name' => 'Test',
'--output' => $target_folder,
'--override' => true,
'scaffold-url' => __DIR__ . '/assets/scaffold-tests/scaffold-drupal-commerce.yml'
));
'scaffold-url' => __DIR__.'/assets/scaffold-tests/scaffold-drupal-commerce.yml',
]);

$this->checkScaffoldResults($target_folder);
}
Expand All @@ -67,13 +68,13 @@ public function testScaffoldWithRelativeFolder()

$command = $this->application->find('app:scaffold');
$commandTester = new CommandTester($command);
$commandTester->execute(array(
'--short-name' => 'TST',
$commandTester->execute([
'--short-name' => 'TST',
'--name' => 'Test',
'--output' => '..',
'--override' => true,
'scaffold-url' => __DIR__ . '/assets/scaffold-tests/scaffold-drupal-commerce.yml'
));
'scaffold-url' => __DIR__.'/assets/scaffold-tests/scaffold-drupal-commerce.yml',
]);

$this->checkScaffoldResults($target_folder);
}
Expand All @@ -85,13 +86,13 @@ public function testScaffoldQuestions()

$command = $this->application->find('app:scaffold');
$commandTester = new CommandTester($command);
$commandTester->execute(array(
'--short-name' => 'TST',
$commandTester->execute([
'--short-name' => 'TST',
'--name' => 'Test',
'--output' => '..',
'--override' => true,
'scaffold-url' => __DIR__ . '/assets/scaffold-tests/scaffold-simple.yml'
));
'scaffold-url' => __DIR__.'/assets/scaffold-tests/scaffold-simple.yml',
]);

// the output of the command in the console
$output = $commandTester->getDisplay();
Expand All @@ -102,7 +103,7 @@ public function testScaffoldQuestions()
public function testScaffoldSubfolder()
{
$root = $this->getTmpDir();
$target_folder = $root . '/tmp/here';
$target_folder = $root.'/tmp/here';
if (!is_dir($target_folder)) {
mkdir($target_folder, 0777, true);
}
Expand All @@ -111,73 +112,73 @@ public function testScaffoldSubfolder()

$command = $this->application->find('app:scaffold');
$commandTester = new CommandTester($command);
$commandTester->execute(array(
'--short-name' => 'TST',
$commandTester->execute([
'--short-name' => 'TST',
'--name' => 'Test',
'--output' => '.',
'--override' => true,
'scaffold-url' => __DIR__ . '/assets/scaffold-tests/scaffold-subfolder.yml'
));
'scaffold-url' => __DIR__.'/assets/scaffold-tests/scaffold-subfolder.yml',
]);

$this->checkFileContent(
$target_folder . '/test/web/modules/custom/tst_utils/tst_utils.info.yml',
$target_folder.'/test/web/modules/custom/tst_utils/tst_utils.info.yml',
'name: Test utils module'
);
$this->checkFileContent(
$target_folder . '/test/web/modules/custom/tst_utils/tst_utils.install',
$target_folder.'/test/web/modules/custom/tst_utils/tst_utils.install',
'function tst_utils_install()'
);
}

public function testScaffoldExistingProjectFolder()
{
$root = $this->getTmpDir();
$target_folder = $root . '/tmp/tst-test';
$target_folder = $root.'/tmp/tst-test';
if (!is_dir($target_folder)) {
mkdir($target_folder, 0777, true);
}

chdir($root . '/tmp');
chdir($root.'/tmp');

$command = $this->application->find('app:scaffold');
$commandTester = new CommandTester($command);
$commandTester->execute(array(
'--short-name' => 'TST',
$commandTester->execute([
'--short-name' => 'TST',
'--name' => 'Test',
'--override' => true,
'scaffold-url' => __DIR__ . '/assets/scaffold-tests/scaffold-projectfolder.yml'
));
'scaffold-url' => __DIR__.'/assets/scaffold-tests/scaffold-projectfolder.yml',
]);

$this->checkFileContent(
$target_folder . '/web/modules/custom/tst_utils/tst_utils.info.yml',
$target_folder.'/web/modules/custom/tst_utils/tst_utils.info.yml',
'name: Test utils module'
);
$this->checkFileContent(
$target_folder . '/web/modules/custom/tst_utils/tst_utils.install',
$target_folder.'/web/modules/custom/tst_utils/tst_utils.install',
'function tst_utils_install()'
);
}

public function testErrorWhileScaffolding()
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage("Scaffolding failed with exit-code 42");
$this->expectExceptionMessage('Scaffolding failed with exit-code 42');
$root = $this->getTmpDir();
$target_folder = $root . '/tmp/tst-test';
$target_folder = $root.'/tmp/tst-test';
if (!is_dir($target_folder)) {
mkdir($target_folder, 0777, true);
}

chdir($root . '/tmp');
chdir($root.'/tmp');

$command = $this->application->find('app:scaffold');
$commandTester = new CommandTester($command);
$commandTester->execute(array(
'--short-name' => 'TST',
$commandTester->execute([
'--short-name' => 'TST',
'--name' => 'Test',
'--override' => true,
'scaffold-url' => __DIR__ . '/assets/scaffold-tests/scaffold-provoke-error.yml'
));
'scaffold-url' => __DIR__.'/assets/scaffold-tests/scaffold-provoke-error.yml',
]);

// the output of the command in the console
$output = $commandTester->getDisplay();
Expand All @@ -186,40 +187,34 @@ public function testErrorWhileScaffolding()
$this->assertStringNotContainsString('Shortname: tst', $output);
}

/**
* @param string $root
*/
protected function prepareTargetFolder(string $root): string
{
$target_folder = $root . '/tmp';
$target_folder = $root.'/tmp';
if (!is_dir($target_folder)) {
mkdir($target_folder, 0777, true);
mkdir($target_folder . '/here');
mkdir($target_folder.'/here');
}

chdir($target_folder . '/here');
chdir($target_folder.'/here');

return $target_folder;
}

/**
* @param string $target_folder
*/
protected function checkScaffoldResults(string $target_folder): void
{
$this->checkFileContent($target_folder . '/test/.fabfile.yaml', 'name: Test');
$this->checkFileContent($target_folder . '/test/.fabfile.yaml', 'key: tst');
$this->checkFileContent($target_folder . '/test/.fabfile.yaml', 'host: test.test');
$this->checkFileContent($target_folder.'/test/.fabfile.yaml', 'name: Test');
$this->checkFileContent($target_folder.'/test/.fabfile.yaml', 'key: tst');
$this->checkFileContent($target_folder.'/test/.fabfile.yaml', 'host: test.test');
$this->checkFileContent(
$target_folder . '/test/web/modules/custom/tst_deploy/tst_deploy.info.yml',
$target_folder.'/test/web/modules/custom/tst_deploy/tst_deploy.info.yml',
'name: Test deployment module'
);
$this->checkFileContent(
$target_folder . '/test/web/modules/custom/tst_deploy/tst_deploy.info.yml',
$target_folder.'/test/web/modules/custom/tst_deploy/tst_deploy.info.yml',
'name: Test deployment module'
);
$this->checkFileContent(
$target_folder . '/test/web/modules/custom/tst_deploy/tst_deploy.install',
$target_folder.'/test/web/modules/custom/tst_deploy/tst_deploy.install',
'function tst_deploy_install()'
);
}
Expand Down
44 changes: 22 additions & 22 deletions tests/ArtifactBasedDeploymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function setup(): void
$method_factory->addMethod(new ArtifactsCustomMethod($logger));
$method_factory->addMethod(new ScriptMethod($logger));

$configuration->readConfiguration(__DIR__ . '/assets/artifact-based-deployment/fabfile.yaml');
$configuration->readConfiguration(__DIR__.'/assets/artifact-based-deployment/fabfile.yaml');

$this->application->add(new DeployCommand($configuration, $method_factory));
}
Expand All @@ -39,9 +39,9 @@ public function testBrokenConfig()
{
$command = $this->application->find('deploy');
$commandTester = new CommandTester($command);
$commandTester->execute(array(
'--config' => 'broken',
));
$commandTester->execute([
'--config' => 'broken',
]);

// the output of the command in the console
$output = $commandTester->getDisplay();
Expand All @@ -55,37 +55,37 @@ public function testMessageActions()
{
$command = $this->application->find('deploy');
$commandTester = new CommandTester($command);
$commandTester->execute(array(
'--config' => 'messages',
));
$commandTester->execute([
'--config' => 'messages',
]);

// the output of the command in the console
$output = $commandTester->getDisplay();
$this->assertStringContainsStringIgnoringCase("Hello world error", $output);
$this->assertStringContainsStringIgnoringCase("Hello world warning", $output);
$this->assertStringContainsStringIgnoringCase("Hello world success", $output);
$this->assertStringContainsStringIgnoringCase("Hello world note", $output);
$this->assertStringContainsStringIgnoringCase("Hello world comment", $output);
$this->assertStringContainsStringIgnoringCase("", $output);
$this->assertStringContainsStringIgnoringCase('Hello world error', $output);
$this->assertStringContainsStringIgnoringCase('Hello world warning', $output);
$this->assertStringContainsStringIgnoringCase('Hello world success', $output);
$this->assertStringContainsStringIgnoringCase('Hello world note', $output);
$this->assertStringContainsStringIgnoringCase('Hello world comment', $output);
$this->assertStringContainsStringIgnoringCase('', $output);
$this->assertEquals(0, $commandTester->getStatusCode());
}

public function testLogActions()
{
$command = $this->application->find('deploy');
$commandTester = new CommandTester($command);
$commandTester->execute(array(
'--config' => 'logs',
'-vv' # everything including info.
));
$commandTester->execute([
'--config' => 'logs',
'-vv', // everything including info.
]);

// the output of the command in the console
$output = $commandTester->getDisplay();
$this->assertEquals(0, $commandTester->getStatusCode());
$this->assertTrue($this->logger->containsMessage("error", "hello world error"));
$this->assertTrue($this->logger->containsMessage("warning", "hello world warning"));
$this->assertTrue($this->logger->containsMessage("notice", "hello world notice"));
$this->assertTrue($this->logger->containsMessage("info", "hello world info"));
$this->assertTrue($this->logger->containsMessage("debug", "hello world debug"));
$this->assertTrue($this->logger->containsMessage('error', 'hello world error'));
$this->assertTrue($this->logger->containsMessage('warning', 'hello world warning'));
$this->assertTrue($this->logger->containsMessage('notice', 'hello world notice'));
$this->assertTrue($this->logger->containsMessage('info', 'hello world info'));
$this->assertTrue($this->logger->containsMessage('debug', 'hello world debug'));
}
}
Loading

0 comments on commit fcf29f6

Please sign in to comment.