peedeeaay
peedeeaay

Reputation: 116

Fatal error: Class 'ZipArchive' - not found when using PHPUnit

I have refactored some PHP code and putting it through a series of PHPUnit classes.

I get the above Fatal Error when running PHPUnit (3.7.28) on it (through console).

PHP version is 5.4.6-1ubuntu1.4 (cli).

I know the Zip class is working and available as it works when running the code normally (also via console)

Thoughts / ideas appreciated.

Thanks!

<?php

namespace phpUnit\Test;

Class MyTest extends \PHPUnit_Framework_TestCase
{
Public Function setUp()
    {
    $this->zip = new ZipArchive();
    }
}

Upvotes: 4

Views: 3547

Answers (1)

Fabian Schmengler
Fabian Schmengler

Reputation: 24576

Inside a namespace, you have to reference classes (other than functions) with their fully qualified class name or import them first:

$this->zip = new \ZipArchive();

or

namespace phpUnit\Test;
use ZipArchive;

Your "normal" code is probably not using namespaces if it works there.

Upvotes: 1

Related Questions