Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

❄️ 🚑 ✅ Make command should respect Homestead config example file #624

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/MakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ protected function createSettingsFile($format, $options)

if (! $this->exampleSettingsExists($format)) {
$settings->updateName($options['name'])
->updateHostname($options['hostname']);
->updateHostname($options['hostname']);
}

$settings->updateIpAddress($options['ip'])
->configureSites($this->projectName, $this->defaultName)
->configureSharedFolders($this->basePath, $this->defaultName)
->save("{$this->basePath}/Homestead.{$format}");
->configureSites($this->projectName, $this->defaultName)
->configureSharedFolders($this->basePath, $this->defaultName)
->save("{$this->basePath}/Homestead.{$format}");
}

/**
Expand Down
58 changes: 44 additions & 14 deletions src/Settings/HomesteadSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,38 @@ public function updateIpAddress($ip)
*/
public function configureSites($projectName, $projectDirectory)
{
$site = [
'map' => "{$projectName}.app",
'to' => "/home/vagrant/{$projectDirectory}/public",
$sites = [
[
'map' => "{$projectName}.app",
'to' => "/home/vagrant/{$projectDirectory}/public",
],
];

if (isset($this->attributes['sites']) && ! empty($this->attributes['sites'])) {
if (isset($this->attributes['sites'][0]['type'])) {
$site['type'] = $this->attributes['sites'][0]['type'];
}

if (isset($this->attributes['sites'][0]['schedule'])) {
$site['schedule'] = $this->attributes['sites'][0]['schedule'];
foreach ($this->attributes['sites'] as $index => $user_site) {
if (isset($user_site['map'])) {
$sites[$index]['map'] = $user_site['map'];
}

if (isset($user_site['to'])) {
$sites[$index]['to'] = $user_site['to'];
}

if (isset($user_site['type'])) {
$sites[$index]['type'] = $user_site['type'];
}

if (isset($user_site['schedule'])) {
$sites[$index]['schedule'] = $user_site['schedule'];
}

if (isset($user_site['php'])) {
$sites[$index]['php'] = $user_site['php'];
}
}
}

$this->update(['sites' => [$site]]);
$this->update(['sites' => $sites]);

return $this;
}
Expand All @@ -129,12 +145,26 @@ public function configureSites($projectName, $projectDirectory)
*/
public function configureSharedFolders($projectPath, $projectDirectory)
{
$folder = [
'map' => $projectPath,
'to' => "/home/vagrant/{$projectDirectory}",
$folders = [
[
'map' => $projectPath,
'to' => "/home/vagrant/{$projectDirectory}",
],
];

$this->update(['folders' => [$folder]]);
if (isset($this->attributes['folders']) && ! empty($this->attributes['folders'])) {
foreach ($this->attributes['folders'] as $index => $user_folder) {
if (isset($user_folder['to'])) {
$folders[$index]['to'] = $user_folder['to'];
}

if (isset($user_folder['type'])) {
$folders[$index]['type'] = $user_folder['type'];
}
}
}

$this->update(['folders' => $folders]);

return $this;
}
Expand Down
20 changes: 10 additions & 10 deletions tests/MakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,11 @@ public function a_homestead_yaml_settings_has_preconfigured_sites()

$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml');

$projectDirectory = basename(getcwd());
$projectName = $this->slug($projectDirectory);
$settings = Yaml::parse(file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml'));

$this->assertEquals([
'map' => "{$projectDirectory}.app",
'to' => "/home/vagrant/{$projectName}/public",
'map' => 'homestead.app',
'to' => '/home/vagrant/Code/Laravel/public',
], $settings['sites'][0]);
}

Expand All @@ -452,13 +450,11 @@ public function a_homestead_json_settings_has_preconfigured_sites()

$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json');

$projectDirectory = basename(getcwd());
$projectName = $this->slug($projectDirectory);
$settings = json_decode(file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json'), true);

$this->assertEquals([
'map' => "{$projectDirectory}.app",
'to' => "/home/vagrant/{$projectName}/public",
'map' => 'homestead.app',
'to' => '/home/vagrant/Code/Laravel/public',
], $settings['sites'][0]);
}

Expand All @@ -485,7 +481,9 @@ public function a_homestead_yaml_settings_has_preconfigured_shared_folders()
// The curious thing is that both directories point to the same location.
//
$this->assertRegExp("/{$projectDirectory}/", $settings['folders'][0]['map']);
$this->assertEquals("/home/vagrant/{$projectName}", $settings['folders'][0]['to']);
$this->assertEquals('/home/vagrant/Code', $settings['folders'][0]['to']);
$this->assertEquals($projectName, $settings['name']);
$this->assertEquals($projectName, $settings['hostname']);
}

/** @test */
Expand Down Expand Up @@ -513,7 +511,9 @@ public function a_homestead_json_settings_has_preconfigured_shared_folders()
// The curious thing is that both directories point to the same location.
//
$this->assertRegExp("/{$projectDirectory}/", $settings['folders'][0]['map']);
$this->assertEquals("/home/vagrant/{$projectName}", $settings['folders'][0]['to']);
$this->assertEquals('/home/vagrant/Code', $settings['folders'][0]['to']);
$this->assertEquals($projectName, $settings['name']);
$this->assertEquals($projectName, $settings['hostname']);
}

/** @test */
Expand Down
45 changes: 39 additions & 6 deletions tests/Settings/JsonSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function it_can_update_its_ip_address()
}

/** @test */
public function it_can_configure_its_sites()
public function it_can_configure_its_sites_from_existing_settings()
{
$settings = new JsonSettings([
'sites' => [
Expand All @@ -125,6 +125,7 @@ public function it_can_configure_its_sites()
'to' => '/home/vagrant/Laravel/public',
'type' => 'laravel',
'schedule' => true,
'php' => '5.6',
],
],
]);
Expand All @@ -133,25 +134,57 @@ public function it_can_configure_its_sites()

$attributes = $settings->toArray();
$this->assertEquals([
'map' => 'test.com.app',
'to' => '/home/vagrant/test-com/public',
'map' => 'homestead.app',
'to' => '/home/vagrant/Laravel/public',
'type' => 'laravel',
'schedule' => true,
'php' => '5.6',
], $attributes['sites'][0]);
}

/** @test */
public function it_can_configure_its_sites_from_empty_settings()
{
$settings = new JsonSettings([]);
$settings->configureSites('test.com', 'test-com');

$attributes = $settings->toArray();
$this->assertEquals([
'map' => 'test.com.app',
'to' => '/home/vagrant/test-com/public',
], $attributes['sites'][0]);
}

/** @test */
public function it_can_configure_its_shared_folders()
public function it_can_configure_its_shared_folders_from_existing_settings()
{
$settings = new JsonSettings([
'folders' => [
'map' => '~/Code',
'to' => '/home/vagrant/',
[
'map' => '~/Code',
'to' => '/home/vagrant/Code',
'type' => 'nfs',
],
],
]);

$settings->configureSharedFolders('/a/path/for/project_name', 'project_name');

$attributes = $settings->toArray();
$this->assertEquals([
'map' => '/a/path/for/project_name',
'to' => '/home/vagrant/Code',
'type' => 'nfs',
], $attributes['folders'][0]);
}

/** @test */
public function it_can_configure_its_shared_folders_from_empty_settings()
{
$settings = new JsonSettings([]);

$settings->configureSharedFolders('/a/path/for/project_name', 'project_name');

$attributes = $settings->toArray();
$this->assertEquals([
'map' => '/a/path/for/project_name',
Expand Down
45 changes: 39 additions & 6 deletions tests/Settings/YamlSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function it_can_update_its_ip_address()
}

/** @test */
public function it_can_configure_its_sites()
public function it_can_configure_its_sites_from_existing_settings()
{
$settings = new YamlSettings([
'sites' => [
Expand All @@ -126,6 +126,7 @@ public function it_can_configure_its_sites()
'to' => '/home/vagrant/Laravel/public',
'type' => 'laravel',
'schedule' => true,
'php' => '5.6',
],
],
]);
Expand All @@ -134,25 +135,57 @@ public function it_can_configure_its_sites()

$attributes = $settings->toArray();
$this->assertEquals([
'map' => 'test.com.app',
'to' => '/home/vagrant/test-com/public',
'map' => 'homestead.app',
'to' => '/home/vagrant/Laravel/public',
'type' => 'laravel',
'schedule' => true,
'php' => '5.6',
], $attributes['sites'][0]);
}

/** @test */
public function it_can_configure_its_sites_from_empty_settings()
{
$settings = new YamlSettings([]);
$settings->configureSites('test.com', 'test-com');

$attributes = $settings->toArray();
$this->assertEquals([
'map' => 'test.com.app',
'to' => '/home/vagrant/test-com/public',
], $attributes['sites'][0]);
}

/** @test */
public function it_can_configure_its_shared_folders()
public function it_can_configure_its_shared_folders_from_existing_settings()
{
$settings = new YamlSettings([
'folders' => [
'map' => '~/Code',
'to' => '/home/vagrant',
[
'map' => '~/Code',
'to' => '/home/vagrant/Code',
'type' => 'nfs',
],
],
]);

$settings->configureSharedFolders('/a/path/for/project_name', 'project_name');

$attributes = $settings->toArray();
$this->assertEquals([
'map' => '/a/path/for/project_name',
'to' => '/home/vagrant/Code',
'type' => 'nfs',
], $attributes['folders'][0]);
}

/** @test */
public function it_can_configure_its_shared_folders_from_empty_settings()
{
$settings = new YamlSettings([]);

$settings->configureSharedFolders('/a/path/for/project_name', 'project_name');

$attributes = $settings->toArray();
$this->assertEquals([
'map' => '/a/path/for/project_name',
Expand Down