@@ -1406,6 +1406,69 @@ public function testDumpFileWithZlibScheme()
1406
1406
$ this ->assertSame ('bar ' , file_get_contents ($ filename ));
1407
1407
}
1408
1408
1409
+ public function testAppendToFile ()
1410
+ {
1411
+ $ filename = $ this ->workspace .DIRECTORY_SEPARATOR .'foo ' .DIRECTORY_SEPARATOR .'bar.txt ' ;
1412
+ $ this ->filesystem ->dumpFile ($ filename , 'foo ' );
1413
+
1414
+ // skip mode check on Windows
1415
+ if ('\\' !== DIRECTORY_SEPARATOR ) {
1416
+ $ oldMask = umask (0002 );
1417
+ }
1418
+
1419
+ $ this ->filesystem ->appendToFile ($ filename , 'bar ' );
1420
+
1421
+ $ this ->assertFileExists ($ filename );
1422
+ $ this ->assertSame ('foobar ' , file_get_contents ($ filename ));
1423
+
1424
+ // skip mode check on Windows
1425
+ if ('\\' !== DIRECTORY_SEPARATOR ) {
1426
+ $ this ->assertFilePermissions (664 , $ filename );
1427
+ umask ($ oldMask );
1428
+ }
1429
+ }
1430
+
1431
+ public function testAppendToFileWithScheme ()
1432
+ {
1433
+ if (defined ('HHVM_VERSION ' )) {
1434
+ $ this ->markTestSkipped ('HHVM does not handle the file:// scheme correctly ' );
1435
+ }
1436
+
1437
+ $ scheme = 'file:// ' ;
1438
+ $ filename = $ scheme .$ this ->workspace .DIRECTORY_SEPARATOR .'foo ' .DIRECTORY_SEPARATOR .'baz.txt ' ;
1439
+ $ this ->filesystem ->dumpFile ($ filename , 'foo ' );
1440
+
1441
+ $ this ->filesystem ->appendToFile ($ filename , 'bar ' );
1442
+
1443
+ $ this ->assertFileExists ($ filename );
1444
+ $ this ->assertSame ('foobar ' , file_get_contents ($ filename ));
1445
+ }
1446
+
1447
+ public function testAppendToFileWithZlibScheme ()
1448
+ {
1449
+ $ scheme = 'compress.zlib:// ' ;
1450
+ $ filename = $ this ->workspace .DIRECTORY_SEPARATOR .'foo ' .DIRECTORY_SEPARATOR .'baz.txt ' ;
1451
+ $ this ->filesystem ->dumpFile ($ filename , 'foo ' );
1452
+
1453
+ // Zlib stat uses file:// wrapper so remove it
1454
+ $ this ->assertSame ('foo ' , file_get_contents (str_replace ($ scheme , '' , $ filename )));
1455
+
1456
+ $ this ->filesystem ->appendToFile ($ filename , 'bar ' );
1457
+
1458
+ $ this ->assertFileExists ($ filename );
1459
+ $ this ->assertSame ('foobar ' , file_get_contents ($ filename ));
1460
+ }
1461
+
1462
+ public function testAppendToFileCreateTheFileIfNotExists ()
1463
+ {
1464
+ $ filename = $ this ->workspace .DIRECTORY_SEPARATOR .'foo ' .DIRECTORY_SEPARATOR .'bar.txt ' ;
1465
+
1466
+ $ this ->filesystem ->appendToFile ($ filename , 'bar ' );
1467
+
1468
+ $ this ->assertFileExists ($ filename );
1469
+ $ this ->assertSame ('bar ' , file_get_contents ($ filename ));
1470
+ }
1471
+
1409
1472
public function testCopyShouldKeepExecutionPermission ()
1410
1473
{
1411
1474
$ this ->markAsSkippedIfChmodIsMissing ();
0 commit comments