config en cours, bloque sur composer et son utilisation du proxy
This commit is contained in:
62
tests/InitScriptTest.php
Normal file
62
tests/InitScriptTest.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tests\Traits\GeneratesTestDirectory;
|
||||
|
||||
class InitScriptTest extends TestCase
|
||||
{
|
||||
use GeneratesTestDirectory;
|
||||
|
||||
/**
|
||||
* Copies init.sh and resources directory to the temporal directory.
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$projectDirectory = __DIR__.'/..';
|
||||
|
||||
exec("cp {$projectDirectory}/init.sh ".self::$testDirectory);
|
||||
exec("cp -r {$projectDirectory}/resources ".self::$testDirectory);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_displays_a_success_message()
|
||||
{
|
||||
$output = exec('bash init.sh');
|
||||
|
||||
$this->assertEquals('Homestead initialized!', $output);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_creates_a_homestead_yaml_file()
|
||||
{
|
||||
exec('bash init.sh');
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.'/Homestead.yaml');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_creates_a_homestead_json_file_if_requested()
|
||||
{
|
||||
exec('bash init.sh json');
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.'/Homestead.json');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_creates_an_after_shell_script()
|
||||
{
|
||||
exec('bash init.sh');
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.'/after.sh');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_creates_an_aliases_file()
|
||||
{
|
||||
exec('bash init.sh');
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.'/aliases');
|
||||
}
|
||||
}
|
541
tests/MakeCommandTest.php
Normal file
541
tests/MakeCommandTest.php
Normal file
@@ -0,0 +1,541 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||
use Laravel\Homestead\MakeCommand;
|
||||
use Laravel\Homestead\Traits\GeneratesSlugs;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Tests\Traits\GeneratesTestDirectory;
|
||||
|
||||
class MakeCommandTest extends TestCase
|
||||
{
|
||||
use ArraySubsetAsserts, GeneratesSlugs, GeneratesTestDirectory;
|
||||
|
||||
/** @test */
|
||||
public function it_displays_a_success_message()
|
||||
{
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([]);
|
||||
|
||||
$this->assertStringContainsString('Homestead Installed!', $tester->getDisplay());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_returns_a_success_status_code()
|
||||
{
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([]);
|
||||
|
||||
$this->assertEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function a_vagrantfile_is_created_if_it_does_not_exists()
|
||||
{
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([]);
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'Vagrantfile');
|
||||
|
||||
$this->assertFileEquals(
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'Vagrantfile',
|
||||
__DIR__.'/../resources/localized/Vagrantfile'
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function an_existing_vagrantfile_is_not_overwritten()
|
||||
{
|
||||
file_put_contents(
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'Vagrantfile',
|
||||
'Already existing Vagrantfile'
|
||||
);
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([]);
|
||||
|
||||
$this->assertStringEqualsFile(
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'Vagrantfile',
|
||||
'Already existing Vagrantfile'
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function an_aliases_file_is_created_by_default()
|
||||
{
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([]);
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'aliases');
|
||||
|
||||
$this->assertFileEquals(
|
||||
__DIR__.'/../resources/aliases',
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'aliases'
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function a_localized_aliases_file_is_created_by_default_in_per_project_installations()
|
||||
{
|
||||
$this->markTestSkipped('Currently unable to emulate a per project installation');
|
||||
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([]);
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'aliases');
|
||||
|
||||
$this->assertFileEquals(
|
||||
__DIR__.'/../resources/localized/aliases',
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'aliases'
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function an_existing_aliases_file_is_not_overwritten()
|
||||
{
|
||||
file_put_contents(
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'aliases',
|
||||
'Already existing aliases'
|
||||
);
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([]);
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'aliases');
|
||||
|
||||
$this->assertStringEqualsFile(
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'aliases',
|
||||
'Already existing aliases'
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function an_aliases_file_is_not_created_if_it_is_explicitly_told_to()
|
||||
{
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([
|
||||
'--no-aliases' => true,
|
||||
]);
|
||||
|
||||
$this->assertFileDoesNotExist(self::$testDirectory.DIRECTORY_SEPARATOR.'aliases');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function an_after_shell_script_is_created_by_default()
|
||||
{
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([]);
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'after.sh');
|
||||
|
||||
$this->assertFileEquals(
|
||||
__DIR__.'/../resources/after.sh',
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'after.sh'
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function an_existing_after_shell_script_is_not_overwritten()
|
||||
{
|
||||
file_put_contents(
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'after.sh',
|
||||
'Already existing after.sh'
|
||||
);
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([]);
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'after.sh');
|
||||
|
||||
$this->assertStringEqualsFile(
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'after.sh',
|
||||
'Already existing after.sh'
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function an_after_file_is_not_created_if_it_is_explicitly_told_to()
|
||||
{
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([
|
||||
'--no-after' => true,
|
||||
]);
|
||||
|
||||
$this->assertFileDoesNotExist(self::$testDirectory.DIRECTORY_SEPARATOR.'after.sh');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function an_example_homestead_yaml_settings_is_created_if_requested()
|
||||
{
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([
|
||||
'--example' => true,
|
||||
]);
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml.example');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function an_existing_example_homestead_yaml_settings_is_not_overwritten()
|
||||
{
|
||||
file_put_contents(
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml.example',
|
||||
'name: Already existing Homestead.yaml.example'
|
||||
);
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([
|
||||
'--example' => true,
|
||||
]);
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml.example');
|
||||
|
||||
$this->assertStringEqualsFile(
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml.example',
|
||||
'name: Already existing Homestead.yaml.example'
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function an_example_homestead_json_settings_is_created_if_requested()
|
||||
{
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([
|
||||
'--example' => true,
|
||||
'--json' => true,
|
||||
]);
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json.example');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function an_existing_example_homestead_json_settings_is_not_overwritten()
|
||||
{
|
||||
file_put_contents(
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json.example',
|
||||
'{"name": "Already existing Homestead.json.example"}'
|
||||
);
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([
|
||||
'--example' => true,
|
||||
'--json' => true,
|
||||
]);
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json.example');
|
||||
|
||||
$this->assertStringEqualsFile(
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json.example',
|
||||
'{"name": "Already existing Homestead.json.example"}'
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function a_homestead_yaml_settings_is_created_if_it_is_does_not_exists()
|
||||
{
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([]);
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function an_existing_homestead_yaml_settings_is_not_overwritten()
|
||||
{
|
||||
file_put_contents(
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml',
|
||||
'name: Already existing Homestead.yaml'
|
||||
);
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([]);
|
||||
|
||||
$this->assertStringEqualsFile(
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml',
|
||||
'name: Already existing Homestead.yaml'
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function a_homestead_json_settings_is_created_if_it_is_requested_and_it_does_not_exists()
|
||||
{
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([
|
||||
'--json' => true,
|
||||
]);
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function an_existing_homestead_json_settings_is_not_overwritten()
|
||||
{
|
||||
file_put_contents(
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json',
|
||||
'{"message": "Already existing Homestead.json"}'
|
||||
);
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([]);
|
||||
|
||||
$this->assertStringEqualsFile(
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json',
|
||||
'{"message": "Already existing Homestead.json"}'
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function a_homestead_yaml_settings_is_created_from_a_homestead_yaml_example_if_it_exists()
|
||||
{
|
||||
file_put_contents(
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml.example',
|
||||
"message: 'Already existing Homestead.yaml.example'"
|
||||
);
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([]);
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml');
|
||||
|
||||
$this->assertStringContainsString(
|
||||
"message: 'Already existing Homestead.yaml.example'",
|
||||
file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml')
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function a_homestead_yaml_settings_created_from_a_homestead_yaml_example_can_override_the_ip_address()
|
||||
{
|
||||
copy(
|
||||
__DIR__.'/../resources/Homestead.yaml',
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml.example'
|
||||
);
|
||||
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([
|
||||
'--ip' => '192.168.10.11',
|
||||
]);
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml');
|
||||
|
||||
$settings = Yaml::parse(file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml'));
|
||||
|
||||
$this->assertEquals('192.168.10.11', $settings['ip']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function a_homestead_json_settings_is_created_from_a_homestead_json_example_if_is_requested_and_if_it_exists()
|
||||
{
|
||||
file_put_contents(
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json.example',
|
||||
'{"message": "Already existing Homestead.json.example"}'
|
||||
);
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([
|
||||
'--json' => true,
|
||||
]);
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json');
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'"message": "Already existing Homestead.json.example"',
|
||||
file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json')
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function a_homestead_json_settings_created_from_a_homestead_json_example_can_override_the_ip_address()
|
||||
{
|
||||
copy(
|
||||
__DIR__.'/../resources/Homestead.json',
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json.example'
|
||||
);
|
||||
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([
|
||||
'--json' => true,
|
||||
'--ip' => '192.168.10.11',
|
||||
]);
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json');
|
||||
|
||||
$settings = json_decode(file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json'), true);
|
||||
|
||||
$this->assertEquals('192.168.10.11', $settings['ip']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function a_homestead_yaml_settings_can_be_created_with_some_command_options_overrides()
|
||||
{
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([
|
||||
'--name' => 'test_name',
|
||||
'--hostname' => 'test_hostname',
|
||||
'--ip' => '127.0.0.1',
|
||||
]);
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml');
|
||||
|
||||
$settings = Yaml::parse(file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml'));
|
||||
|
||||
self::assertArraySubset([
|
||||
'name' => 'test_name',
|
||||
'hostname' => 'test_hostname',
|
||||
'ip' => '127.0.0.1',
|
||||
], $settings);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function a_homestead_json_settings_can_be_created_with_some_command_options_overrides()
|
||||
{
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([
|
||||
'--json' => true,
|
||||
'--name' => 'test_name',
|
||||
'--hostname' => 'test_hostname',
|
||||
'--ip' => '127.0.0.1',
|
||||
]);
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json');
|
||||
|
||||
$settings = json_decode(file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json'), true);
|
||||
|
||||
self::assertArraySubset([
|
||||
'name' => 'test_name',
|
||||
'hostname' => 'test_hostname',
|
||||
'ip' => '127.0.0.1',
|
||||
], $settings);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function a_homestead_yaml_settings_has_preconfigured_sites()
|
||||
{
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([]);
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml');
|
||||
|
||||
$settings = Yaml::parse(file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml'));
|
||||
|
||||
$this->assertEquals([
|
||||
'map' => 'homestead.test',
|
||||
'to' => '/home/vagrant/code/public',
|
||||
], $settings['sites'][0]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function a_homestead_json_settings_has_preconfigured_sites()
|
||||
{
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([
|
||||
'--json' => true,
|
||||
]);
|
||||
|
||||
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json');
|
||||
|
||||
$settings = json_decode(file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json'), true);
|
||||
|
||||
$this->assertEquals([
|
||||
'map' => 'homestead.test',
|
||||
'to' => '/home/vagrant/code/public',
|
||||
], $settings['sites'][0]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function a_homestead_yaml_settings_has_preconfigured_shared_folders()
|
||||
{
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([]);
|
||||
|
||||
$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'));
|
||||
|
||||
// The "map" is not tested for equality because getcwd() (The method to obtain the project path)
|
||||
// returns a directory in a different location that the test directory itself.
|
||||
//
|
||||
// Example:
|
||||
// - project directory: /private/folders/...
|
||||
// - test directory: /var/folders/...
|
||||
//
|
||||
// The curious thing is that both directories point to the same location.
|
||||
//
|
||||
$this->assertMatchesRegularExpression("/{$projectDirectory}/", $settings['folders'][0]['map']);
|
||||
$this->assertEquals('/home/vagrant/code', $settings['folders'][0]['to']);
|
||||
$this->assertEquals($projectName, $settings['name']);
|
||||
$this->assertEquals($projectName, $settings['hostname']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function a_homestead_json_settings_has_preconfigured_shared_folders()
|
||||
{
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([
|
||||
'--json' => true,
|
||||
]);
|
||||
|
||||
$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);
|
||||
|
||||
// The "map" is not tested for equality because getcwd() (The method to obtain the project path)
|
||||
// returns a directory in a different location that the test directory itself.
|
||||
//
|
||||
// Example:
|
||||
// - project directory: /private/folders/...
|
||||
// - test directory: /var/folders/...
|
||||
//
|
||||
// The curious thing is that both directories point to the same location.
|
||||
//
|
||||
$this->assertMatchesRegularExpression("/{$projectDirectory}/", $settings['folders'][0]['map']);
|
||||
$this->assertEquals('/home/vagrant/code', $settings['folders'][0]['to']);
|
||||
$this->assertEquals($projectName, $settings['name']);
|
||||
$this->assertEquals($projectName, $settings['hostname']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function a_warning_is_thrown_if_the_homestead_settings_json_and_yaml_exists_at_the_same_time()
|
||||
{
|
||||
file_put_contents(
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json',
|
||||
'{"message": "Already existing Homestead.json"}'
|
||||
);
|
||||
file_put_contents(
|
||||
self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml',
|
||||
"message: 'Already existing Homestead.yaml'"
|
||||
);
|
||||
$tester = new CommandTester(new MakeCommand());
|
||||
|
||||
$tester->execute([]);
|
||||
|
||||
$this->assertStringContainsString('WARNING! You have Homestead.yaml AND Homestead.json configuration files', $tester->getDisplay());
|
||||
}
|
||||
}
|
200
tests/Settings/JsonSettingsTest.php
Normal file
200
tests/Settings/JsonSettingsTest.php
Normal file
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Settings;
|
||||
|
||||
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||
use Laravel\Homestead\Settings\JsonSettings;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tests\Traits\GeneratesTestDirectory;
|
||||
|
||||
class JsonSettingsTest extends TestCase
|
||||
{
|
||||
use ArraySubsetAsserts, GeneratesTestDirectory;
|
||||
|
||||
/** @test */
|
||||
public function it_can_be_created_from_a_filename()
|
||||
{
|
||||
$settings = JsonSettings::fromFile(__DIR__.'/../../resources/Homestead.json');
|
||||
|
||||
self::assertArraySubset([
|
||||
'ip' => '192.168.56.56',
|
||||
'memory' => '2048',
|
||||
'cpus' => '2',
|
||||
], $settings->toArray());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_be_saved_to_a_file()
|
||||
{
|
||||
$settings = new JsonSettings([
|
||||
'ip' => '192.168.56.56',
|
||||
'memory' => '2048',
|
||||
'cpus' => 1,
|
||||
]);
|
||||
$filename = self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json';
|
||||
|
||||
$settings->save($filename);
|
||||
|
||||
$this->assertFileExists($filename);
|
||||
$attributes = json_decode(file_get_contents($filename), true);
|
||||
self::assertArraySubset([
|
||||
'ip' => '192.168.56.56',
|
||||
'memory' => '2048',
|
||||
'cpus' => '1',
|
||||
], $settings->toArray());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_update_its_attributes()
|
||||
{
|
||||
$settings = new JsonSettings([
|
||||
'ip' => '192.168.56.56',
|
||||
'memory' => '2048',
|
||||
'cpus' => 1,
|
||||
]);
|
||||
|
||||
$settings->update([
|
||||
'ip' => '127.0.0.1',
|
||||
'memory' => '4096',
|
||||
'cpus' => 2,
|
||||
]);
|
||||
|
||||
self::assertArraySubset([
|
||||
'ip' => '127.0.0.1',
|
||||
'memory' => '4096',
|
||||
'cpus' => '2',
|
||||
], $settings->toArray());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_updates_only_not_null_attributes()
|
||||
{
|
||||
$settings = new JsonSettings([
|
||||
'ip' => '192.168.56.56',
|
||||
'memory' => '2048',
|
||||
'cpus' => 1,
|
||||
]);
|
||||
|
||||
$settings->update([
|
||||
'ip' => null,
|
||||
'memory' => null,
|
||||
'cpus' => null,
|
||||
]);
|
||||
|
||||
self::assertArraySubset([
|
||||
'ip' => '192.168.56.56',
|
||||
'memory' => '2048',
|
||||
'cpus' => '1',
|
||||
], $settings->toArray());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_update_its_name()
|
||||
{
|
||||
$settings = new JsonSettings(['name' => 'Initial name']);
|
||||
|
||||
$settings->updateName('Updated name');
|
||||
|
||||
$attributes = $settings->toArray();
|
||||
$this->assertEquals('Updated name', $attributes['name']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_update_its_hostname()
|
||||
{
|
||||
$settings = new JsonSettings(['name' => 'Initial ip address']);
|
||||
|
||||
$settings->updateHostname('Updated hostname');
|
||||
|
||||
$attributes = $settings->toArray();
|
||||
$this->assertEquals('Updated hostname', $attributes['hostname']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_update_its_ip_address()
|
||||
{
|
||||
$settings = new JsonSettings(['name' => 'Initial ip address']);
|
||||
|
||||
$settings->updateIpAddress('Updated ip address');
|
||||
|
||||
$attributes = $settings->toArray();
|
||||
$this->assertEquals('Updated ip address', $attributes['ip']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_configure_its_sites_from_existing_settings()
|
||||
{
|
||||
$settings = new JsonSettings([
|
||||
'sites' => [
|
||||
[
|
||||
'map' => 'homestead.test',
|
||||
'to' => '/home/vagrant/Laravel/public',
|
||||
'type' => 'laravel',
|
||||
'schedule' => true,
|
||||
'php' => '7.1',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$settings->configureSites('test.com', 'test-com');
|
||||
|
||||
$attributes = $settings->toArray();
|
||||
$this->assertEquals([
|
||||
'map' => 'homestead.test',
|
||||
'to' => '/home/vagrant/Laravel/public',
|
||||
'type' => 'laravel',
|
||||
'schedule' => true,
|
||||
'php' => '7.1',
|
||||
], $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.test',
|
||||
'to' => '/home/vagrant/test-com/public',
|
||||
], $attributes['sites'][0]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_configure_its_shared_folders_from_existing_settings()
|
||||
{
|
||||
$settings = new JsonSettings([
|
||||
'folders' => [
|
||||
[
|
||||
'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',
|
||||
'to' => '/home/vagrant/project_name',
|
||||
], $attributes['folders'][0]);
|
||||
}
|
||||
}
|
200
tests/Settings/YamlSettingsTest.php
Normal file
200
tests/Settings/YamlSettingsTest.php
Normal file
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Settings;
|
||||
|
||||
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||
use Laravel\Homestead\Settings\YamlSettings;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Tests\Traits\GeneratesTestDirectory;
|
||||
|
||||
class YamlSettingsTest extends TestCase
|
||||
{
|
||||
use ArraySubsetAsserts, GeneratesTestDirectory;
|
||||
|
||||
/** @test */
|
||||
public function it_can_be_created_from_a_filename()
|
||||
{
|
||||
$settings = YamlSettings::fromFile(__DIR__.'/../../resources/Homestead.yaml');
|
||||
|
||||
self::assertArraySubset([
|
||||
'ip' => '192.168.56.56',
|
||||
'memory' => '2048',
|
||||
'cpus' => '2',
|
||||
], $settings->toArray());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_be_saved_to_a_file()
|
||||
{
|
||||
$settings = new YamlSettings([
|
||||
'ip' => '192.168.56.56',
|
||||
'memory' => '2048',
|
||||
'cpus' => 1,
|
||||
]);
|
||||
$filename = self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml';
|
||||
|
||||
$settings->save($filename);
|
||||
|
||||
$this->assertFileExists($filename);
|
||||
self::assertArraySubset([
|
||||
'ip' => '192.168.56.56',
|
||||
'memory' => '2048',
|
||||
'cpus' => '1',
|
||||
], Yaml::parse(file_get_contents($filename)));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_update_its_attributes()
|
||||
{
|
||||
$settings = new YamlSettings([
|
||||
'ip' => '192.168.56.56',
|
||||
'memory' => '2048',
|
||||
'cpus' => 1,
|
||||
]);
|
||||
|
||||
$settings->update([
|
||||
'ip' => '127.0.0.1',
|
||||
'memory' => '4096',
|
||||
'cpus' => 2,
|
||||
]);
|
||||
|
||||
self::assertArraySubset([
|
||||
'ip' => '127.0.0.1',
|
||||
'memory' => '4096',
|
||||
'cpus' => '2',
|
||||
], $settings->toArray());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_updates_only_not_null_attributes()
|
||||
{
|
||||
$settings = new YamlSettings([
|
||||
'ip' => '192.168.56.56',
|
||||
'memory' => '2048',
|
||||
'cpus' => 1,
|
||||
]);
|
||||
|
||||
$settings->update([
|
||||
'ip' => null,
|
||||
'memory' => null,
|
||||
'cpus' => null,
|
||||
]);
|
||||
|
||||
self::assertArraySubset([
|
||||
'ip' => '192.168.56.56',
|
||||
'memory' => '2048',
|
||||
'cpus' => '1',
|
||||
], $settings->toArray());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_update_its_name()
|
||||
{
|
||||
$settings = new YamlSettings(['name' => 'Initial name']);
|
||||
|
||||
$settings->updateName('Updated name');
|
||||
|
||||
$attributes = $settings->toArray();
|
||||
$this->assertEquals('Updated name', $attributes['name']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_update_its_hostname()
|
||||
{
|
||||
$settings = new YamlSettings(['name' => 'Initial ip address']);
|
||||
|
||||
$settings->updateHostname('Updated hostname');
|
||||
|
||||
$attributes = $settings->toArray();
|
||||
$this->assertEquals('Updated hostname', $attributes['hostname']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_update_its_ip_address()
|
||||
{
|
||||
$settings = new YamlSettings(['name' => 'Initial ip address']);
|
||||
|
||||
$settings->updateIpAddress('Updated ip address');
|
||||
|
||||
$attributes = $settings->toArray();
|
||||
$this->assertEquals('Updated ip address', $attributes['ip']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_configure_its_sites_from_existing_settings()
|
||||
{
|
||||
$settings = new YamlSettings([
|
||||
'sites' => [
|
||||
[
|
||||
'map' => 'homestead.test',
|
||||
'to' => '/home/vagrant/Laravel/public',
|
||||
'type' => 'laravel',
|
||||
'schedule' => true,
|
||||
'php' => '7.1',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$settings->configureSites('test.com', 'test-com');
|
||||
|
||||
$attributes = $settings->toArray();
|
||||
$this->assertEquals([
|
||||
'map' => 'homestead.test',
|
||||
'to' => '/home/vagrant/Laravel/public',
|
||||
'type' => 'laravel',
|
||||
'schedule' => true,
|
||||
'php' => '7.1',
|
||||
], $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.test',
|
||||
'to' => '/home/vagrant/test-com/public',
|
||||
], $attributes['sites'][0]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_configure_its_shared_folders_from_existing_settings()
|
||||
{
|
||||
$settings = new YamlSettings([
|
||||
'folders' => [
|
||||
[
|
||||
'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',
|
||||
'to' => '/home/vagrant/project_name',
|
||||
], $attributes['folders'][0]);
|
||||
}
|
||||
}
|
43
tests/Traits/GeneratesTestDirectory.php
Normal file
43
tests/Traits/GeneratesTestDirectory.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Traits;
|
||||
|
||||
trait GeneratesTestDirectory
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected static $testDirectory;
|
||||
|
||||
/**
|
||||
* Create a tests directory and make it the current directory.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
self::$testDirectory = sys_get_temp_dir().DIRECTORY_SEPARATOR.uniqid('homestead_', true);
|
||||
mkdir(self::$testDirectory);
|
||||
chdir(self::$testDirectory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the tests directory.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
rmdir(self::$testDirectory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all the files inside the tests directory.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown(): void
|
||||
{
|
||||
exec('rm -rf '.self::$testDirectory.DIRECTORY_SEPARATOR.'*');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user