diff --git a/tests/MakeCommandTest.php b/tests/MakeCommandTest.php index fa315a429..730e19d2f 100644 --- a/tests/MakeCommandTest.php +++ b/tests/MakeCommandTest.php @@ -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') @@ -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' ); } @@ -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') @@ -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') @@ -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' ); } @@ -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 */ @@ -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') @@ -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' ); } @@ -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 */ @@ -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 */ @@ -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' ); } @@ -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 */ @@ -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"}' ); } @@ -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 */ @@ -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' ); } @@ -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 */ @@ -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"}' ); } @@ -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') @@ -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']); @@ -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') @@ -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']); @@ -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']); @@ -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']); @@ -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", @@ -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", @@ -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')); @@ -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);