55
66namespace FriendsOfTYPO3 \CrowdinBase \Tests \Configuration ;
77
8- use FriendsOfTYPO3 \CrowdinBase \Configuration \Exception \ConfigurationFileWriteException ;
9- use FriendsOfTYPO3 \CrowdinBase \Configuration \ConfigurationReader ;
108use FriendsOfTYPO3 \CrowdinBase \Configuration \ConfigurationWriter ;
11- use FriendsOfTYPO3 \CrowdinBase \Configuration \Exception \ InvalidConfigurationDataException ;
9+ use FriendsOfTYPO3 \CrowdinBase \Configuration \Entity \ Language ;
1210use FriendsOfTYPO3 \CrowdinBase \Configuration \Entity \Project ;
11+ use FriendsOfTYPO3 \CrowdinBase \Configuration \Exception \ConfigurationFileWriteException ;
12+ use FriendsOfTYPO3 \CrowdinBase \Configuration \Exception \InvalidConfigurationDataException ;
1313use FriendsOfTYPO3 \CrowdinBase \Extension \ExtensionKeyGenerator ;
1414use PHPUnit \Framework \Attributes \CoversClass ;
1515use PHPUnit \Framework \Attributes \Test ;
@@ -23,26 +23,24 @@ public function writeCreatesConfigurationFileCorrectly(): void
2323 {
2424 $ configurationFile = '/tmp/crowdin-base-configuration-writer-test/ ' . uniqid ();
2525 $ projects = [
26- new Project (1 , 'typo3-extension-some-identifier ' , 'typo3 extension news ' , ['de ' ]),
27- new Project (2 , 'typo3-extension-another-identifier ' , 'typo3 extension tt_address ' , ['fr ' , 'it ' ]),
26+ new Project (
27+ 1 ,
28+ 'typo3-extension-some-identifier ' ,
29+ 'news ' ,
30+ [new Language ('de ' , 'German ' )]
31+ ),
32+ new Project (
33+ 2 ,
34+ 'typo3-extension-another-identifier ' ,
35+ 'typo3 extension tt_address ' ,
36+ [new Language ('fr ' , 'French ' ), new Language ('it ' , 'Italian ' )]
37+ ),
2838 ];
2939 $ subject = new ConfigurationWriter (new ExtensionKeyGenerator (), $ configurationFile , []);
3040
3141 $ subject ->write ($ projects );
32- $ configurationReader = new ConfigurationReader ($ configurationFile );
33- $ actual = $ configurationReader ->read ();
34-
35- self ::assertCount (2 , $ actual );
36-
37- self ::assertSame (2 , $ actual [0 ]->id );
38- self ::assertSame ('typo3-extension-another-identifier ' , $ actual [0 ]->identifier );
39- self ::assertSame ('tt_address ' , $ actual [0 ]->name );
40- self ::assertSame (['fr ' , 'it ' ], $ actual [0 ]->languages );
4142
42- self ::assertSame (1 , $ actual [1 ]->id );
43- self ::assertSame ('typo3-extension-some-identifier ' , $ actual [1 ]->identifier );
44- self ::assertSame ('news ' , $ actual [1 ]->name );
45- self ::assertSame (['de ' ], $ actual [1 ]->languages );
43+ self ::assertJsonFileEqualsJsonFile (__DIR__ . '/Output/configuration.json ' , $ configurationFile );
4644
4745 unlink ($ configurationFile );
4846 }
@@ -52,17 +50,24 @@ public function writeCreatesConfigurationFileWithoutGivenSkippedProjectsCorrectl
5250 {
5351 $ configurationFile = '/tmp/crowdin-base-configuration-writer-test/ ' . uniqid ();
5452 $ projects = [
55- new Project (1 , 'typo3-extension-some-identifier ' , 'typo3 extension news ' , ['de ' ]),
56- new Project (2 , 'typo3-extension-another-identifier ' , 'typo3 extension tt_address ' , ['fr ' , 'it ' ]),
53+ new Project (
54+ 1 ,
55+ 'typo3-extension-some-identifier ' ,
56+ 'news ' ,
57+ [new Language ('de ' , 'German ' )]
58+ ),
59+ new Project (
60+ 2 ,
61+ 'typo3-extension-another-identifier ' ,
62+ 'typo3 extension tt_address ' ,
63+ [new Language ('fr ' , 'French ' ), new Language ('it ' , 'Italian ' )]
64+ ),
5765 ];
5866 $ subject = new ConfigurationWriter (new ExtensionKeyGenerator (), $ configurationFile , ['typo3-extension-some-identifier ' ]);
5967
6068 $ subject ->write ($ projects );
61- $ configurationReader = new ConfigurationReader ($ configurationFile );
62- $ actual = $ configurationReader ->read ();
6369
64- self ::assertCount (1 , $ actual );
65- self ::assertSame (2 , $ actual [0 ]->id );
70+ self ::assertJsonFileEqualsJsonFile (__DIR__ . '/Output/configuration-without-skipped.json ' , $ configurationFile );
6671
6772 unlink ($ configurationFile );
6873 }
@@ -74,7 +79,12 @@ public function writeThrowsErrorOnInvalidJson(): void
7479
7580 $ configurationFile = '/tmp/crowdin-base-configuration-writer-test/ ' . uniqid ();
7681 $ projects = [
77- new Project (1 , 'typo3-extension-some-identifier ' , "typo3 extension news \xB1\x31" , ['de ' ]),
82+ new Project (
83+ 1 ,
84+ 'typo3-extension-some-identifier ' ,
85+ "typo3 extension news \xB1\x31" ,
86+ [new Language ('de ' , 'German ' )]
87+ ),
7888 ];
7989 $ subject = new ConfigurationWriter (new ExtensionKeyGenerator (), $ configurationFile , []);
8090
@@ -90,7 +100,12 @@ public function writeThrowsErrorIfConfigurationFileCannotBeWritten(): void
90100 mkdir (dirname ($ configurationFile ));
91101 chmod (dirname ($ configurationFile ), 0500 );
92102 $ projects = [
93- new Project (1 , 'typo3-extension-some-identifier ' , "typo3 extension news " , ['de ' ]),
103+ new Project (
104+ 1 ,
105+ 'typo3-extension-some-identifier ' ,
106+ 'news ' ,
107+ [new Language ('de ' , 'German ' )]
108+ ),
94109 ];
95110
96111 $ subject = new ConfigurationWriter (new ExtensionKeyGenerator (), $ configurationFile , []);
0 commit comments