Skip to content

Commit 35d57a0

Browse files
committed
feat: Implements Docker container operations and tests.
1 parent 8828d2a commit 35d57a0

21 files changed

+285
-342
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"phpmd": "phpmd ./src text phpmd.xml --suffixes php --ignore-violations-on-exit",
5959
"phpstan": "phpstan analyse -c phpstan.neon.dist --quiet --no-progress",
6060
"test": "phpunit --log-junit=report/coverage/junit.xml --coverage-xml=report/coverage/coverage-xml --coverage-html=report/coverage/coverage-html tests",
61-
"unit-test": "phpunit --no-coverage -c phpunit.xml --testsuite unit",
61+
"unit-test": "phpunit -c phpunit.xml --coverage-html=report/coverage/coverage-html --testsuite unit",
6262
"test-no-coverage": "phpunit --no-coverage",
6363
"review": [
6464
"@phpcs",

src/Contracts/ContainerStarted.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ public function getId(): string;
2727
*/
2828
public function getName(): string;
2929

30-
/**
31-
* Retrieves the logs of the running container.
32-
*
33-
* @return string The container's logs as a string.
34-
* @throws DockerCommandExecutionFailed If the command to retrieve logs fails.
35-
*/
36-
public function getLogs(): string;
37-
3830
/**
3931
* Returns the network address of the running container.
4032
*

src/Internal/Commands/DockerLogs.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/Internal/Containers/Drivers/MySQL/MySQLCommands.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,6 @@
88
{
99
private const string USER_ROOT = 'root';
1010

11-
public static function createDatabase(string $database, string $rootPassword): string
12-
{
13-
$query = sprintf(
14-
<<<SQL
15-
CREATE DATABASE IF NOT EXISTS %s;
16-
SQL,
17-
$database
18-
);
19-
20-
return sprintf('mysql -u%s -p%s -e "%s;"', self::USER_ROOT, $rootPassword, $query);
21-
}
22-
2311
public static function grantPrivilegesToRoot(string $host, string $rootPassword): string
2412
{
2513
$query = sprintf(

src/Internal/Containers/Factories/ContainerFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function buildFrom(ContainerId $id, Container $container): Container
2929

3030
$payload = (array)json_decode($executionCompleted->getOutput(), true);
3131

32-
if (empty($payload)) {
32+
if (empty(array_filter($payload))) {
3333
throw new DockerContainerNotFound(name: $container->name);
3434
}
3535

src/Internal/Containers/Started.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use TinyBlocks\DockerContainer\Contracts\EnvironmentVariables;
1010
use TinyBlocks\DockerContainer\Contracts\ExecutionCompleted;
1111
use TinyBlocks\DockerContainer\Internal\Commands\DockerExecute;
12-
use TinyBlocks\DockerContainer\Internal\Commands\DockerLogs;
1312
use TinyBlocks\DockerContainer\Internal\Commands\DockerStop;
1413
use TinyBlocks\DockerContainer\Internal\ContainerHandler;
1514
use TinyBlocks\DockerContainer\Internal\Containers\Models\Container;
@@ -30,15 +29,6 @@ public function getName(): string
3029
return $this->container->name->value;
3130
}
3231

33-
public function getLogs(): string
34-
{
35-
$command = DockerLogs::from(id: $this->container->id);
36-
37-
return $this->containerHandler
38-
->execute(command: $command)
39-
->getOutput();
40-
}
41-
4232
public function getAddress(): Address
4333
{
4434
return $this->container->address;

src/MySQLDockerContainer.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,13 @@ public function run(
2222
$containerStarted = parent::run(commands: $commands);
2323
$environmentVariables = $containerStarted->getEnvironmentVariables();
2424

25-
$database = $environmentVariables->getValueBy(key: 'MYSQL_DATABASE');
2625
$rootPassword = $environmentVariables->getValueBy(key: 'MYSQL_ROOT_PASSWORD');
2726

2827
if (!empty($this->grantedHosts)) {
2928
$condition = MySQLReady::from(container: $containerStarted);
3029
$waitForDependency = ContainerWaitForDependency::untilReady(condition: $condition);
3130
$waitForDependency->waitBefore();
3231

33-
$command = MySQLCommands::createDatabase(database: $database, rootPassword: $rootPassword);
34-
$containerStarted->executeAfterStarted(commands: [$command]);
35-
3632
foreach ($this->grantedHosts as $host) {
3733
$command = MySQLCommands::grantPrivilegesToRoot(host: $host, rootPassword: $rootPassword);
3834
$containerStarted->executeAfterStarted(commands: [$command]);

src/Waits/Conditions/ExecutionCompleted.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/Waits/Conditions/Generic/LogContains.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/Waits/ContainerWait.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TinyBlocks\DockerContainer\Waits;
6+
7+
/**
8+
* Defines the strategy for waiting conditions that ensure a Docker container meets a specific requirement
9+
* before proceeding with further actions.
10+
*/
11+
interface ContainerWait
12+
{
13+
/**
14+
* The default wait time in whole seconds.
15+
*
16+
* This constant represents the default amount of time the system will wait when no specific condition is set.
17+
* It can be overridden or used directly in waiting mechanisms.
18+
*/
19+
public const int WAIT_TIME_IN_WHOLE_SECONDS = 1;
20+
}

0 commit comments

Comments
 (0)