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

🎨 🐎 Refactor tests to use phpunit assertions to be more descriptive #585

Merged
merged 2 commits into from
May 26, 2017
Merged
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
144 changes: 67 additions & 77 deletions tests/MakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ public function a_vagrantfile_is_created_if_it_does_not_exists()

$tester->execute([]);

$this->assertTrue(
file_exists(self::$testDirectory.DIRECTORY_SEPARATOR.'Vagrantfile')
);
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'Vagrantfile');

$this->assertEquals(
file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'Vagrantfile'),
file_get_contents(__DIR__.'/../resources/localized/Vagrantfile')
Expand All @@ -60,9 +59,9 @@ public function an_existing_vagrantfile_is_not_overwritten()

$tester->execute([]);

$this->assertEquals(
'Already existing Vagrantfile',
file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'Vagrantfile')
$this->assertStringEqualsFile(
self::$testDirectory.DIRECTORY_SEPARATOR.'Vagrantfile',
'Already existing Vagrantfile'
);
}

Expand All @@ -73,9 +72,8 @@ public function an_aliases_file_is_created_by_default()

$tester->execute([]);

$this->assertTrue(
file_exists(self::$testDirectory.DIRECTORY_SEPARATOR.'aliases')
);
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'aliases');

$this->assertEquals(
file_get_contents(__DIR__.'/../resources/aliases'),
file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'aliases')
Expand All @@ -91,9 +89,8 @@ public function a_localized_aliases_file_is_created_by_default_in_per_project_in

$tester->execute([]);

$this->assertTrue(
file_exists(self::$testDirectory.DIRECTORY_SEPARATOR.'aliases')
);
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'aliases');

$this->assertEquals(
file_get_contents(__DIR__.'/../resources/localized/aliases'),
file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'aliases')
Expand All @@ -111,12 +108,11 @@ public function an_existing_aliases_file_is_not_overwritten()

$tester->execute([]);

$this->assertTrue(
file_exists(self::$testDirectory.DIRECTORY_SEPARATOR.'aliases')
);
$this->assertEquals(
'Already existing aliases',
file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'aliases')
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'aliases');

$this->assertStringEqualsFile(
self::$testDirectory.DIRECTORY_SEPARATOR.'aliases',
'Already existing aliases'
);
}

Expand All @@ -129,9 +125,7 @@ public function an_aliases_file_is_not_created_if_it_is_explicitly_told_to()
'--no-aliases' => true,
]);

$this->assertFalse(
file_exists(self::$testDirectory.DIRECTORY_SEPARATOR.'aliases')
);
$this->assertFileNotExists(self::$testDirectory.DIRECTORY_SEPARATOR.'aliases');
}

/** @test */
Expand All @@ -141,9 +135,8 @@ public function an_after_shell_script_is_created_by_default()

$tester->execute([]);

$this->assertTrue(
file_exists(self::$testDirectory.DIRECTORY_SEPARATOR.'after.sh')
);
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'after.sh');

$this->assertEquals(
file_get_contents(__DIR__.'/../resources/after.sh'),
file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'after.sh')
Expand All @@ -161,12 +154,11 @@ public function an_existing_after_shell_script_is_not_overwritten()

$tester->execute([]);

$this->assertTrue(
file_exists(self::$testDirectory.DIRECTORY_SEPARATOR.'after.sh')
);
$this->assertEquals(
'Already existing after.sh',
file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'after.sh')
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'after.sh');

$this->assertStringEqualsFile(
self::$testDirectory.DIRECTORY_SEPARATOR.'after.sh',
'Already existing after.sh'
);
}

Expand All @@ -179,9 +171,7 @@ public function an_after_file_is_not_created_if_it_is_explicitly_told_to()
'--no-after' => true,
]);

$this->assertFalse(
file_exists(self::$testDirectory.DIRECTORY_SEPARATOR.'after.sh')
);
$this->assertFileNotExists(self::$testDirectory.DIRECTORY_SEPARATOR.'after.sh');
}

/** @test */
Expand All @@ -193,9 +183,7 @@ public function an_example_homestead_yaml_settings_is_created_if_requested()
'--example' => true,
]);

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

/** @test */
Expand All @@ -211,12 +199,11 @@ public function an_existing_example_homestead_yaml_settings_is_not_overwritten()
'--example' => true,
]);

$this->assertTrue(
file_exists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml.example')
);
$this->assertEquals(
'name: Already existing Homestead.yaml.example',
file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml.example')
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml.example');

$this->assertStringEqualsFile(
self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml.example',
'name: Already existing Homestead.yaml.example'
);
}

Expand All @@ -230,9 +217,7 @@ public function an_example_homestead_json_settings_is_created_if_requested()
'--json' => true,
]);

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

/** @test */
Expand All @@ -249,12 +234,11 @@ public function an_existing_example_homestead_json_settings_is_not_overwritten()
'--json' => true,
]);

$this->assertTrue(
file_exists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json.example')
);
$this->assertEquals(
'{"name": "Already existing Homestead.json.example"}',
file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json.example')
$this->assertFileExists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json.example');

$this->assertStringEqualsFile(
self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json.example',
'{"name": "Already existing Homestead.json.example"}'
);
}

Expand All @@ -265,9 +249,7 @@ public function a_homestead_yaml_settings_is_created_if_it_is_does_not_exists()

$tester->execute([]);

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

/** @test */
Expand All @@ -281,9 +263,9 @@ public function an_existing_homestead_yaml_settings_is_not_overwritten()

$tester->execute([]);

$this->assertEquals(
'name: Already existing Homestead.yaml',
file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml')
$this->assertStringEqualsFile(
self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml',
'name: Already existing Homestead.yaml'
);
}

Expand All @@ -296,9 +278,7 @@ public function a_homestead_json_settings_is_created_if_it_is_requested_and_it_d
'--json' => true,
]);

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

/** @test */
Expand All @@ -312,9 +292,9 @@ public function an_existing_homestead_json_settings_is_not_overwritten()

$tester->execute([]);

$this->assertEquals(
'{"message": "Already existing Homestead.json"}',
file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json')
$this->assertStringEqualsFile(
self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json',
'{"message": "Already existing Homestead.json"}'
);
}

Expand All @@ -329,9 +309,8 @@ public function a_homestead_yaml_settings_is_created_from_a_homestead_yaml_examp

$tester->execute([]);

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

$this->assertContains(
"message: 'Already existing Homestead.yaml.example'",
file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml')
Expand All @@ -352,7 +331,8 @@ public function a_homestead_yaml_settings_created_from_a_homestead_yaml_example_
'--ip' => '192.168.10.11',
]);

$this->assertTrue(file_exists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml'));
$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']);
Expand All @@ -371,9 +351,8 @@ public function a_homestead_json_settings_is_created_from_a_homestead_json_examp
'--json' => true,
]);

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

$this->assertContains(
'"message": "Already existing Homestead.json.example"',
file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json')
Expand All @@ -395,7 +374,8 @@ public function a_homestead_json_settings_created_from_a_homestead_json_example_
'--ip' => '192.168.10.11',
]);

$this->assertTrue(file_exists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json'));
$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']);
Expand All @@ -412,8 +392,10 @@ public function a_homestead_yaml_settings_can_be_created_with_some_command_optio
'--ip' => '127.0.0.1',
]);

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

$settings = Yaml::parse(file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml'));

$this->assertEquals('test_name', $settings['name']);
$this->assertEquals('test_hostname', $settings['hostname']);
$this->assertEquals('127.0.0.1', $settings['ip']);
Expand All @@ -431,8 +413,10 @@ public function a_homestead_json_settings_can_be_created_with_some_command_optio
'--ip' => '127.0.0.1',
]);

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

$settings = json_decode(file_get_contents(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json'), true);

$this->assertEquals('test_name', $settings['name']);
$this->assertEquals('test_hostname', $settings['hostname']);
$this->assertEquals('127.0.0.1', $settings['ip']);
Expand All @@ -445,10 +429,12 @@ public function a_homestead_yaml_settings_has_preconfigured_sites()

$tester->execute([]);

$this->assertTrue(file_exists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml'));
$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/Code/{$projectName}/public",
Expand All @@ -464,10 +450,12 @@ public function a_homestead_json_settings_has_preconfigured_sites()
'--json' => true,
]);

$this->assertTrue(file_exists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json'));
$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/Code/{$projectName}/public",
Expand All @@ -481,7 +469,8 @@ public function a_homestead_yaml_settings_has_preconfigured_shared_folders()

$tester->execute([]);

$this->assertTrue(file_exists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.yaml'));
$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'));
Expand All @@ -508,7 +497,8 @@ public function a_homestead_json_settings_has_preconfigured_shared_folders()
'--json' => true,
]);

$this->assertTrue(file_exists(self::$testDirectory.DIRECTORY_SEPARATOR.'Homestead.json'));
$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);
Expand Down