Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 31... Línea 31...
31
 * @package   core
31
 * @package   core
32
 * @category  test
32
 * @category  test
33
 * @copyright 2012 Petr Skoda
33
 * @copyright 2012 Petr Skoda
34
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
35
 */
36
class zip_packer_test extends \advanced_testcase implements file_progress {
36
final class zip_packer_test extends \advanced_testcase implements file_progress {
37
    protected $testfile;
37
    protected $testfile;
38
    protected $files;
38
    protected $files;
Línea 39... Línea 39...
39
 
39
 
40
    /**
40
    /**
Línea 521... Línea 521...
521
        $result = $zip_archive->close();
521
        $result = $zip_archive->close();
522
        $this->assertTrue($result);
522
        $this->assertTrue($result);
523
        unlink($archive);
523
        unlink($archive);
Línea 524... Línea 524...
524
 
524
 
525
        // Create archive and close if forcing error.
525
        // Create archive and close if forcing error.
526
        // (returns true for old PHP versions and
-
 
527
        // false with warnings for new PHP versions). MDL-51863.
526
        // (returns false with warnings).
528
        $zip_archive = new zip_archive();
527
        $zip_archive = new zip_archive();
529
        $result = $zip_archive->open($archive, file_archive::CREATE);
528
        $result = $zip_archive->open($archive, file_archive::CREATE);
530
        $this->assertTrue($result);
529
        $this->assertTrue($result);
531
        $result = $zip_archive->add_file_from_string('test.txt', 'test');
530
        $result = $zip_archive->add_file_from_string('test.txt', 'test');
Línea 534... Línea 533...
534
        $this->assertTrue($result);
533
        $this->assertTrue($result);
535
        // Delete the file before closing does force close() to fail.
534
        // Delete the file before closing does force close() to fail.
536
        unlink($textfile);
535
        unlink($textfile);
537
        // Behavior is different between old PHP versions and new ones. Let's detect it.
536
        // Behavior is different between old PHP versions and new ones. Let's detect it.
538
        $result = false;
537
        $result = false;
539
        try {
538
 
540
            // Old PHP versions were not printing any warning.
539
        set_error_handler(function ($errno, $errstr) use (&$result) {
541
            $result = $zip_archive->close();
540
            $result = $errstr;
542
        } catch (\Exception $e) {
-
 
543
            // New PHP versions print PHP Warning.
-
 
544
            $this->assertInstanceOf('PHPUnit\Framework\Error\Warning', $e);
-
 
545
            $this->assertStringContainsString('ZipArchive::close', $e->getMessage());
541
            $this->assertStringContainsString('ZipArchive::close', $errstr);
546
        }
-
 
547
        // This is crazy, but it shows how some PHP versions do return true.
-
 
548
        try {
542
        }, E_WARNING);
549
            // And some PHP versions do return correctly false (5.4.25, 5.6.14...)
-
 
550
            $this->assertFalse($result);
543
        $this->assertFalse($zip_archive->close());
551
        } catch (\Exception $e) {
-
 
552
            // But others do insist into returning true (5.6.13...). Only can accept them.
-
 
553
            $this->assertInstanceOf('PHPUnit\Framework\ExpectationFailedException', $e);
-
 
554
            $this->assertTrue($result);
-
 
555
        }
-
 
556
        $this->assertFileDoesNotExist($archive);
544
        $this->assertFileDoesNotExist($archive);
-
 
545
        restore_error_handler();
557
    }
546
    }
Línea 558... Línea 547...
558
 
547
 
559
    /**
548
    /**
560
     * @depends test_add_files
549
     * @depends test_add_files