1- <?php
1+ <?php /** @noinspection PhpUnhandledExceptionInspection */
22
33namespace splitbrain \PHPArchive ;
44
5- use splitbrain \PHPArchive \Tar ;
6- use PHPUnit \Framework \TestCase ;
75use org \bovigo \vfs \vfsStream ;
6+ use PHPUnit \Framework \TestCase ;
87
98class TarTestCase extends TestCase
109{
10+ /** @var int callback counter */
11+ protected $ counter = 0 ;
12+
1113 /**
1214 * file extensions that several tests use
1315 */
1416 protected $ extensions = array ('tar ' );
1517
18+ /** @inheritdoc */
1619 protected function setUp ()
1720 {
1821 parent ::setUp ();
@@ -27,12 +30,22 @@ protected function setUp()
2730 vfsStream::setup ('home_root_path ' );
2831 }
2932
33+ /** @inheritdoc */
3034 protected function tearDown ()
3135 {
3236 parent ::tearDown ();
3337 $ this ->extensions [] = null ;
3438 }
3539
40+ /**
41+ * Callback check function
42+ * @param FileInfo $fileinfo
43+ */
44+ public function increaseCounter ($ fileinfo ) {
45+ $ this ->assertInstanceOf ('\\splitbrain \\PHPArchive \\FileInfo ' , $ fileinfo );
46+ $ this ->counter ++;
47+ }
48+
3649 /*
3750 * dependency for tests needing zlib extension to pass
3851 */
@@ -170,23 +183,30 @@ public function testDogfood()
170183 $ archive = sys_get_temp_dir () . '/dwtartest ' . md5 (time ()) . '. ' . $ ext ;
171184 $ extract = sys_get_temp_dir () . '/dwtartest ' . md5 (time () + 1 );
172185
186+ $ this ->counter = 0 ;
173187 $ tar = new Tar ();
188+ $ tar ->setCallback (array ($ this , 'increaseCounter ' ));
174189 $ tar ->create ($ archive );
175190 foreach ($ input as $ path ) {
176191 $ file = basename ($ path );
177192 $ tar ->addFile ($ path , $ file );
178193 }
179194 $ tar ->close ();
180195 $ this ->assertFileExists ($ archive );
196+ $ this ->assertEquals (count ($ input ), $ this ->counter );
181197
198+ $ this ->counter = 0 ;
182199 $ tar = new Tar ();
200+ $ tar ->setCallback (array ($ this , 'increaseCounter ' ));
183201 $ tar ->open ($ archive );
184202 $ tar ->extract ($ extract , '' , '/FileInfo \\.php/ ' , '/.* \\.php/ ' );
185203
186204 $ this ->assertFileExists ("$ extract/Tar.php " );
187205 $ this ->assertFileExists ("$ extract/Zip.php " );
188206 $ this ->assertFileNotExists ("$ extract/FileInfo.php " );
189207
208+ $ this ->assertEquals (count ($ input ) - 1 , $ this ->counter );
209+
190210 $ this ->nativeCheck ($ archive , $ ext );
191211
192212 self ::RDelete ($ extract );
0 commit comments