M
M
myzerov2014-10-02 14:35:07
PHP
myzerov, 2014-10-02 14:35:07

Is it possible to teach PHPUnit to understand dynamic extension classes?

Hey!
Let's say I'm a complete layman in the topic of automatic testing.
Let's say I installed PHPUnit.
I have a class

class Main {
public $tnt;
public function __construct() {
//тут я включаю автозагрузку
spl_autoload_register<...>;
//а затем... создаю инстанс нужной мне приблуды (в данном случае это Tarantool от mail.ru)
$this->tnt = Tarantool("localhost", "port_number");
}
}

I'll explain: the Tarantool class is taken from the "tarantool-php" dynamic extension, created to work with this NoSQL database from php. The module is a regular .so file built from source and uploaded by php.
When I run a test that instantiates the Main class, I get the following error:
"PHP Fatal error: {closure}(): Failed opening required '/var/www/gameserver/Tarantool.php' (include_path='/usr/ lib/php5/') in /var/www/gameserver/app/Main.php on line xxx"
I run PHPUnit just like that, without any bootstraps, without configurations, without anything.
PHPUnit, as I understand it, thinks that I want to autoload the Tarantool class from the /var/www/gameserver/ folder, but the Tarantool class is available to me without autoload,
Questions:
1. I don't understand something in the organization of testing using PHPUnit and I need to use my own mock instead of the real Tarantool class from the extension?
2. If I can use dynamic extension classes, how can I tell PHPUnit to understand where to load them from? How to specify the path to the extension?
3. Can it be wrong to use autoload inside the classes under test? Or how?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nonlux, 2014-10-18
@myzerov

1. Yes, I would get wet), but for this the constructor must be changed.
2. I think here the legs are dancing from the PHP settings.
Look in which environment your (php.ini) Main is running and in which phpunit is running.
If my telepathic abilities do not fail. Then your Main works with a web environment ( php-fpm or cgi, etc.), and phpunit works through php-cli. The whole difference is in the php.ini used
And most likely your extension is not connected in the second one
3. Xs, it all depends on the application logic

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question