Les tests unitaires plantent
Erreur sur le test unitaire avec tar sur le cas empty chez moi en PHP 7.4
```
~/Sites/localhost/fraich40/plugins-dist/archiviste/ [master*] vendor/bin/phpunit (master|✚1)
PHPUnit 9.5.13 by Sebastian Bergmann and contributors.
Runtime: PHP 7.4.21
Configuration: /Users/cedric/Sites/localhost/fraich40/plugins-dist/archiviste/phpunit.xml.dist
Warning: No code coverage driver available
.E.................. 20 / 20 (100%)
Time: 00:00.038, Memory: 6.00 MB
There was 1 error:
1) Spip\Archiver\Tests\SpipArchiverTest::testInformer with data set "empty-tar" (0, array(array(''), array()), '/Users/cedric/Sites/localhost...ty.tar', 'tar')
RuntimeException: Directory name must not be empty.
/Users/cedric/Sites/localhost/fraich40/plugins-dist/archiviste/src/TarArchive.php:44
/Users/cedric/Sites/localhost/fraich40/plugins-dist/archiviste/src/SpipArchiver.php:37
/Users/cedric/Sites/localhost/fraich40/plugins-dist/archiviste/tests/SpipArchiverTest.php:163
ERRORS!
Tests: 20, Assertions: 49, Errors: 1.
```
En debugant je vois que si un fichier n'existe pas `$this->tar` n'est pas correctement initialisé dans le open()
Le patch suivant corrige ce cas en verifiant que l'instantiation eu lieu correctement :
```
diff --git a/src/TarArchive.php b/src/TarArchive.php
index 693c2ae..602d568 100644
--- a/src/TarArchive.php
+++ b/src/TarArchive.php
@@ -26,6 +26,10 @@ class TarArchive implements ArchiveInterface
2
);
+ if ('' === $this->tar->getFilename()) {
+ return 0;
+ }
+
return 1;
}
@@ -38,7 +42,6 @@ class TarArchive implements ArchiveInterface
if ('' === $this->tar->getPathname()) {
return $files;
}
-
$root_dir = dirname($this->tar->getPathname());
$source = new NoDotFilterIterator(
new \RecursiveIteratorIterator(
```
Et du coup on voit que le test emballer sur le tar ne marche pas (c'était visiblement masqué par le fait qu'on avait pas d'erreur sur un fichier vide avant...)
```
~/Sites/localhost/fraich40/plugins-dist/archiviste/ [master*] vendor/bin/phpunit (master|✚1)
PHPUnit 9.5.13 by Sebastian Bergmann and contributors.
Runtime: PHP 7.4.21
Configuration: /Users/cedric/Sites/localhost/fraich40/plugins-dist/archiviste/phpunit.xml.dist
Warning: No code coverage driver available
.F......F........... 20 / 20 (100%)
Time: 00:00.030, Memory: 6.00 MB
There were 2 failures:
1) Spip\Archiver\Tests\SpipArchiverTest::testInformer with data set "empty-tar" (0, array(array(''), array()), '/Users/cedric/Sites/localhost...ty.tar', 'tar')
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
'proprietes' => Array (
- 'racine' => ''
)
'fichiers' => Array ()
)
/Users/cedric/Sites/localhost/fraich40/plugins-dist/archiviste/tests/SpipArchiverTest.php:166
2) Spip\Archiver\Tests\SpipArchiverTest::testEmballer with data set "tar" (true, 0, '/Users/cedric/Sites/localhost...er.tar', '', array('/Users/cedric/Sites/localhost...st.txt'), '/Users/cedric/Sites/localhost...ectory')
compress ok
Failed asserting that false matches expected true.
/Users/cedric/Sites/localhost/fraich40/plugins-dist/archiviste/tests/SpipArchiverTest.php:283
FAILURES!
Tests: 20, Assertions: 48, Failures: 2.
```
issue