Skip to content

Commit

Permalink
5.3.1: Issue/91/wp db import working dir (#92)
Browse files Browse the repository at this point in the history
* Refactor Config to accept and make available the docker workdir

* Pass workdir with wp proxy commands

* Fix Wp command tests

* Update Config tests to pass, add workdir test

* Fix ConfigExceptionTest.php

* Bump to version 5.3.1
  • Loading branch information
defunctl authored Nov 14, 2021
1 parent 3693aff commit 1a6beb4
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 15 deletions.
2 changes: 2 additions & 0 deletions app/Commands/LocalDocker/Wp.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public function handle( Config $config, XdebugValidator $xdebugValidator ): ?int
'--project-name',
$config->getProjectName(),
'exec',
'-w',
$config->getWorkdir(),
];

if ( $this->option( 'notty' ) ) {
Expand Down
5 changes: 5 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public function register(): void {
$bootstrap->boot();

$this->app->singleton( ResultRecorder::class );

$this->app->when( Config::class )
->needs( '$workdir' )
->give( config( 'squareone.docker.workdir' ) );

$this->app->singleton( Config::class );

$this->app->bind(
Expand Down
25 changes: 22 additions & 3 deletions app/Services/Docker/Local/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Services\Docker\Local;

use RuntimeException;
use App\Contracts\Runner;
use RuntimeException;

/**
* Local Docker Config
Expand Down Expand Up @@ -38,13 +38,23 @@ class Config {
*/
protected $path = '';

/**
* The working directory in the docker container where the application
* files live.
*
* @var string
*/
protected $workdir = '';

/**
* Config constructor.
*
* @param \App\Contracts\Runner $runner
* @param string $workdir
*/
public function __construct( Runner $runner ) {
$this->runner = $runner;
public function __construct( Runner $runner, string $workdir ) {
$this->runner = $runner;
$this->workdir = $workdir;
}

/**
Expand Down Expand Up @@ -186,4 +196,13 @@ public function getProjectUrl( string $tld = 'tribe', string $scheme = 'https' )
return $scheme . '://' . $this->getProjectDomain( $tld );
}

/**
* The server path to the application inside the docker container.
*
* @return string
*/
public function getWorkdir(): string {
return $this->workdir;
}

}
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/

//'version' => app('git.version'),
'version' => '5.3.0',
'version' => '5.3.1',

/*
|--------------------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions tests/Feature/Commands/LocalDocker/WpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@

class WpTest extends LocalDockerCommand {

private $workdir = '/application/www';

public function test_it_calls_local_wp_command() {
$this->config->shouldReceive( 'getProjectName' )->andReturn( $this->project );
$this->config->shouldReceive( 'getDockerDir' )->andReturn( $this->dockerDir );
$this->config->shouldReceive( 'getWorkdir' )->andReturn( $this->workdir );

$this->dockerCompose->shouldReceive( 'call' )->with( DockerCompose::class, [
'--project-name',
$this->project,
'exec',
'-w',
'/application/www',
'--env',
'WP_CLI_PHP_ARGS',
'php-fpm',
Expand Down Expand Up @@ -48,12 +53,15 @@ public function test_it_calls_local_wp_command_with_options() {

$this->config->shouldReceive( 'getProjectName' )->andReturn( $this->project );
$this->config->shouldReceive( 'getDockerDir' )->andReturn( $this->dockerDir );
$this->config->shouldReceive( 'getWorkdir' )->andReturn( $this->workdir );
$this->config->shouldReceive( 'getPhpIni' )->andReturn( storage_path( 'tests/dev/docker/php/php-ini-overrides.ini' ) );

$this->dockerCompose->shouldReceive( 'call' )->with( DockerCompose::class, [
'--project-name',
$this->project,
'exec',
'-w',
'/application/www',
'-T',
'--env',
BaseCommand::XDEBUG_ENV,
Expand Down Expand Up @@ -88,12 +96,15 @@ public function test_it_warns_the_user_if_xdebug_is_not_correctly_configured() {

$this->config->shouldReceive( 'getProjectName' )->andReturn( $this->project );
$this->config->shouldReceive( 'getDockerDir' )->andReturn( $this->dockerDir );
$this->config->shouldReceive( 'getWorkdir' )->andReturn( $this->workdir );
$this->config->shouldReceive( 'getPhpIni' )->andReturn( storage_path( 'tests/dev/docker/php/php-ini-overrides.ini' ) );

$this->dockerCompose->shouldReceive( 'call' )->with( DockerCompose::class, [
'--project-name',
$this->project,
'exec',
'-w',
'/application/www',
'-T',
'--env',
BaseCommand::XDEBUG_ENV,
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Services/Docker/Local/ConfigExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function test_it_throws_exception_on_invalid_project_root() {
// Mock we already hit the operating system's root folder
PHPMockery::mock( 'App\Services\Docker\Local', 'getcwd' )->andReturn( '/' );

$config = new Config( $this->runner );
$config = new Config( $this->runner, '/application/www' );

$config->getProjectRoot();
}
Expand Down
29 changes: 19 additions & 10 deletions tests/Unit/Services/Docker/Local/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

class ConfigTest extends TestCase {

protected $runner;
private $runner;
private $workdir;

protected function setUp(): void {
parent::setUp();
Expand All @@ -26,6 +27,8 @@ protected function setUp(): void {
->with( [
'path' => '',
] )->andReturnSelf();

$this->workdir = '/application/www';
}

public function test_it_can_set_a_path() {
Expand All @@ -34,7 +37,7 @@ public function test_it_can_set_a_path() {
'path' => storage_path( 'tests/squareone' ),
] )->andReturnSelf();

$config = new Config( $this->runner );
$config = new Config( $this->runner, $this->workdir );

$config = $config->setPath( storage_path( 'tests/squareone' ) );

Expand All @@ -45,7 +48,7 @@ public function test_it_gets_a_project_root() {
// Mock getcwd() found our tests storage path
PHPMockery::mock( 'App\Services\Docker\Local', 'getcwd' )->andReturn( storage_path( 'tests/squareone' ) );

$config = new Config( $this->runner );
$config = new Config( $this->runner, $this->workdir );

$root = $config->getProjectRoot();

Expand All @@ -56,7 +59,7 @@ public function test_it_finds_docker_compose_yml() {
// Mock getcwd() found our tests storage path
PHPMockery::mock( 'App\Services\Docker\Local', 'getcwd' )->andReturn( storage_path( 'tests/squareone' ) );

$config = new Config( $this->runner );
$config = new Config( $this->runner, $this->workdir );

$compose = $config->getDockerDir();

Expand All @@ -69,7 +72,7 @@ public function test_it_finds_docker_compose_override_yml() {
// Mock getcwd() found our tests storage path
PHPMockery::mock( 'App\Services\Docker\Local', 'getcwd' )->andReturn( storage_path( 'tests/squareone' ) );

$config = new Config( $this->runner );
$config = new Config( $this->runner, $this->workdir );

$compose = $config->getDockerDir();

Expand All @@ -82,7 +85,7 @@ public function test_it_gets_a_project_name() {
// Mock getcwd() found our tests storage path
PHPMockery::mock( 'App\Services\Docker\Local', 'getcwd' )->andReturn( storage_path( 'tests/squareone' ) );

$config = new Config( $this->runner );
$config = new Config( $this->runner, $this->workdir );

$name = $config->getProjectName();

Expand All @@ -95,7 +98,7 @@ public function test_it_gets_project_domain() {
// Mock getcwd() found our tests storage path
PHPMockery::mock( 'App\Services\Docker\Local', 'getcwd' )->andReturn( storage_path( 'tests/squareone' ) );

$config = new Config( $this->runner );
$config = new Config( $this->runner, $this->workdir );

$domain = $config->getProjectDomain();

Expand All @@ -112,7 +115,7 @@ public function test_it_gets_project_url() {
// Mock getcwd() found our tests storage path
PHPMockery::mock( 'App\Services\Docker\Local', 'getcwd' )->andReturn( storage_path( 'tests/squareone' ) );

$config = new Config( $this->runner );
$config = new Config( $this->runner, $this->workdir );

$url = $config->getProjectUrl();

Expand All @@ -124,7 +127,7 @@ public function test_it_gets_project_url() {
}

public function test_it_gets_composer_volume() {
$config = new Config( $this->runner );
$config = new Config( $this->runner, $this->workdir );

// Mock getcwd() found our tests storage path
PHPMockery::mock( 'App\Services\Docker\Local', 'getcwd' )->andReturn( storage_path( 'tests/squareone' ) );
Expand All @@ -135,7 +138,7 @@ public function test_it_gets_composer_volume() {
}

public function test_it_gets_a_php_ini_path() {
$config = new Config( $this->runner );
$config = new Config( $this->runner, $this->workdir );

// Mock getcwd() found our tests storage path
PHPMockery::mock( 'App\Services\Docker\Local', 'getcwd' )->andReturn( storage_path( 'tests/squareone' ) );
Expand All @@ -145,4 +148,10 @@ public function test_it_gets_a_php_ini_path() {
$this->assertSame( storage_path( 'tests/squareone/dev/docker/php/php-ini-overrides.ini' ), $phpIni );
}

public function test_it_gets_the_docker_workdir() {
$config = new Config( $this->runner, $this->workdir );

$this->assertSame( '/application/www', $config->getWorkdir() );
}

}

0 comments on commit 1a6beb4

Please sign in to comment.