1919use Ymir \Cli \Project \EnvironmentConfiguration ;
2020use Ymir \Cli \Project \ProjectConfiguration ;
2121use Ymir \Cli \Tests \TestCase ;
22+ use Ymir \Cli \YamlParser ;
2223
2324class ProjectConfigurationTest extends TestCase
2425{
@@ -41,19 +42,19 @@ protected function tearDown(): void
4142
4243 public function testExistsReturnsFalseIfFileDoesNotExist (): void
4344 {
44- $ this ->assertFalse (( new ProjectConfiguration ( new Filesystem (), [], 'non-existent-file ' ) )->exists ());
45+ $ this ->assertFalse ($ this -> createProjectConfiguration ( 'non-existent-file ' )->exists ());
4546 }
4647
4748 public function testExistsReturnsTrueIfFileExists (): void
4849 {
49- $ this ->assertTrue (( new ProjectConfiguration ( new Filesystem (), [], $ this ->tempFile ) )->exists ());
50+ $ this ->assertTrue ($ this -> createProjectConfiguration ( $ this ->tempFile )->exists ());
5051 }
5152
5253 public function testGetEnvironmentConfigurationReturnsConfiguration (): void
5354 {
5455 file_put_contents ($ this ->tempFile , "environments: \n prod: \n foo: bar " );
5556
56- $ configuration = ( new ProjectConfiguration ( new Filesystem (), [], $ this ->tempFile ) )->getEnvironmentConfiguration ('prod ' );
57+ $ configuration = $ this -> createProjectConfiguration ( $ this ->tempFile )->getEnvironmentConfiguration ('prod ' );
5758
5859 $ this ->assertInstanceOf (EnvironmentConfiguration::class, $ configuration );
5960 $ this ->assertSame ('prod ' , $ configuration ->getName ());
@@ -67,14 +68,14 @@ public function testGetEnvironmentConfigurationThrowsExceptionIfEnvironmentDoesN
6768 $ this ->expectException (InvalidArgumentException::class);
6869 $ this ->expectExceptionMessage ('Environment "staging" not found in Ymir project configuration file ' );
6970
70- ( new ProjectConfiguration ( new Filesystem (), [], $ this ->tempFile ) )->getEnvironmentConfiguration ('staging ' );
71+ $ this -> createProjectConfiguration ( $ this ->tempFile )->getEnvironmentConfiguration ('staging ' );
7172 }
7273
7374 public function testGetProjectIdReturnsId (): void
7475 {
7576 file_put_contents ($ this ->tempFile , 'id: 123 ' );
7677
77- $ this ->assertSame (123 , ( new ProjectConfiguration ( new Filesystem (), [], $ this ->tempFile ) )->getProjectId ());
78+ $ this ->assertSame (123 , $ this -> createProjectConfiguration ( $ this ->tempFile )->getProjectId ());
7879 }
7980
8081 public function testGetProjectIdThrowsExceptionIfIdIsMissing (): void
@@ -84,14 +85,14 @@ public function testGetProjectIdThrowsExceptionIfIdIsMissing(): void
8485 $ this ->expectException (ConfigurationException::class);
8586 $ this ->expectExceptionMessage ('No "id" found in Ymir project configuration file ' );
8687
87- ( new ProjectConfiguration ( new Filesystem (), [], $ this ->tempFile ) )->getProjectId ();
88+ $ this -> createProjectConfiguration ( $ this ->tempFile )->getProjectId ();
8889 }
8990
9091 public function testGetProjectNameReturnsName (): void
9192 {
9293 file_put_contents ($ this ->tempFile , 'name: foo ' );
9394
94- $ this ->assertSame ('foo ' , ( new ProjectConfiguration ( new Filesystem (), [], $ this ->tempFile ) )->getProjectName ());
95+ $ this ->assertSame ('foo ' , $ this -> createProjectConfiguration ( $ this ->tempFile )->getProjectName ());
9596 }
9697
9798 public function testGetProjectNameThrowsExceptionIfNameIsMissing (): void
@@ -101,7 +102,7 @@ public function testGetProjectNameThrowsExceptionIfNameIsMissing(): void
101102 $ this ->expectException (ConfigurationException::class);
102103 $ this ->expectExceptionMessage ('No "name" found in Ymir project configuration file ' );
103104
104- ( new ProjectConfiguration ( new Filesystem (), [], $ this ->tempFile ) )->getProjectName ();
105+ $ this -> createProjectConfiguration ( $ this ->tempFile )->getProjectName ();
105106 }
106107
107108 public function testGetProjectTypeThrowsExceptionIfTypeIsMissing (): void
@@ -111,7 +112,7 @@ public function testGetProjectTypeThrowsExceptionIfTypeIsMissing(): void
111112 $ this ->expectException (ConfigurationException::class);
112113 $ this ->expectExceptionMessage ('No "type" found in Ymir project configuration file ' );
113114
114- ( new ProjectConfiguration ( new Filesystem (), [], $ this ->tempFile ) )->getProjectType ();
115+ $ this -> createProjectConfiguration ( $ this ->tempFile )->getProjectType ();
115116 }
116117
117118 public function testLoadConfigurationThrowsExceptionIfParsingFails (): void
@@ -121,6 +122,11 @@ public function testLoadConfigurationThrowsExceptionIfParsingFails(): void
121122 $ this ->expectException (ConfigurationException::class);
122123 $ this ->expectExceptionMessage ('Error parsing Ymir project configuration file ' );
123124
124- new ProjectConfiguration (new Filesystem (), [], $ this ->tempFile );
125+ $ this ->createProjectConfiguration ($ this ->tempFile );
126+ }
127+
128+ private function createProjectConfiguration (string $ configurationFilePath ): ProjectConfiguration
129+ {
130+ return new ProjectConfiguration (new Filesystem (), new YamlParser (), [], $ configurationFilePath );
125131 }
126132}
0 commit comments