66use test \{Assert , Expect , Test };
77
88class FileOutputStreamTest {
9+ const INITIAL = 'Created by FileOutputStreamTest ' ;
910 private $ files = [];
1011
1112 /** @return io.TempFile */
1213 private function tempFile () {
13- $ file = (new TempFile ())->containing (' Created by FileOutputStreamTest ' );
14+ $ file = (new TempFile ())->containing (self :: INITIAL );
1415 $ this ->files []= $ file ;
1516 return $ file ;
1617 }
@@ -112,4 +113,39 @@ public function truncation() {
112113 Assert::equals ('Exist ' , Files::read ($ file ));
113114 });
114115 }
116+
117+ #[Test]
118+ public function size_initially () {
119+ $ stream = new FileOutputStream ($ this ->tempFile ());
120+ Assert::equals (0 , $ stream ->size ());
121+ }
122+
123+ #[Test]
124+ public function size_after_writing () {
125+ $ stream = new FileOutputStream ($ this ->tempFile ());
126+ $ stream ->write ('Test ' );
127+ Assert::equals (4 , $ stream ->size ());
128+ }
129+
130+ #[Test]
131+ public function size_after_truncation () {
132+ $ stream = new FileOutputStream ($ this ->tempFile ());
133+ $ stream ->write ('Test ' );
134+ $ stream ->truncate (2 );
135+ Assert::equals (2 , $ stream ->size ());
136+ }
137+
138+ #[Test]
139+ public function size_when_opened_with_append () {
140+ $ file = $ this ->tempFile ();
141+ $ file ->open (File::APPEND );
142+
143+ $ stream = new FileOutputStream ($ file );
144+ $ stream ->write ('Test ' );
145+ $ size = $ stream ->size ();
146+ $ stream ->close ();
147+
148+ Assert::equals (strlen (self ::INITIAL ) + 4 , $ size );
149+ Assert::equals (self ::INITIAL .'Test ' , Files::read ($ file ));
150+ }
115151}
0 commit comments