Error "class DomDocument not found" when trying to run PHPUnit

1

When I try to run the command phpunit from the command line, I received the following error:

  

Class 'DOMDocument' not found

This was not happening before. I remember having to remove and reinstall PHP.

What can cause this error, since DomDocument is a native PHP class?

Note: I am using the Ubuntu operating system.

    
asked by anonymous 23.02.2017 / 16:42

2 answers

1

To install in Ubuntu I believe this is the command, if it is php5.6:

sudo apt-get install php5.6-xml

Other linux based on Debian or older versions of Ubuntu I believe works like this:

sudo apt-get install php5-dom

If it's 7.0 would be this:

sudo apt-get install php7.0-xml

php7.1:

sudo apt-get install php7.1-xml

The only thing that can change is if you are using PPA, then it will depend on how you installed

    
01.03.2017 / 21:39
3

Some Linux distributions separate the DOM extension into another package to make the installation cleaner and more organized.

I do not remember the package name in Ubuntu, but it's something like php-xml. After installing, make sure the extension is active in php.

You can check by looking at phpinfo ();

If it is not active, simply add the extension in your php.ini:

extension=dom.so
    
01.03.2017 / 20:32