digitalpianism / testframework

A simple test framework repo for Magento 1
49 stars 13 forks source link

Can't find app/Mage.php when package is installed through Composer #7

Open agereteam opened 7 years ago

agereteam commented 7 years ago

I add "digitalpianism/testframework": "dev-master" to my composer.json and do all instructions in README, but when I try to run my test from console I get error

$ phpunit -c vendor/popov/magento-magmi-import/app/code/local/Popov/Magmi/Test/phpunit.xml

Warning: require_once(D:\WebServer\git\art-market\vendor\digitalpianism\testframework\lib\DigitalPianism\TestFramework\Helper/../../../../app/Mage.php): failed to open stream: No such file or directory in D:\WebServer\git\art-market\vendor\digitalpianism\testfr
amework\lib\DigitalPianism\TestFramework\Helper\Magento.php on line 39

Fatal error: require_once(): Failed opening required 'D:\WebServer\git\art-market\vendor\digitalpianism\testframework\lib\DigitalPianism\TestFramework\Helper/../../../../app/Mage.php' (include_path='.;d:/openserver/modules/php/PHP-7-x64;d:/openserver/modules/ph
p/PHP-7-x64/PEAR/pear') in D:\WebServer\git\art-market\vendor\digitalpianism\testframework\lib\DigitalPianism\TestFramework\Helper\Magento.php on line 39

My bootstrap.php look like this

require __DIR__ . '/../../../../../../../../../htdocs/lib/DigitalPianism/TestFramework/Helper/Magento.php';
DigitalPianism_TestFramework_Helper_Magento::bootstrap();

Problem is that code in vendor/digitalpianism/testframework/lib/DigitalPianism/TestFramework/Helper/Magento.php use path relative to original Magento directory lib/ but in my case this is path relative to Composer directory vendor/. As possible solution can to use package https://github.com/joshdifabio/composed for getting variable magento-root-dir from composer.json and based on this variable get path to app/Mage.php. But I didn't do that, maybe you have better solution.

digitalpianism commented 7 years ago

@agereteam is it similar to this issue ? https://github.com/digitalpianism/testframework/pull/6 not sure if we can do shell commands with composer

agereteam commented 7 years ago

@digitalpianism this is like but not the same. I really need links in my composer.json. I develop modules and copy/past changed files every time is horrible.

digitalpianism commented 7 years ago

@agereteam can you try to edit the following file: https://github.com/digitalpianism/testframework/blob/master/lib/DigitalPianism/TestFramework/Helper/Magento.php

And replace:

require_once __DIR__.'/../../../../app/Mage.php';

With:

$dirName = dirname(__FILE__, 7);
if (preg_match('/vendor/', $dirName)) {
       $dirName = dirname(__FILE__, 8);
} else {
       $dirName = dirname(__FILE__, 5);
}

require_once($dirName . '/app/Mage.php');

And let me know if that works. I haven't fully tested that it's hacky but in theory it should work

agereteam commented 7 years ago

No, this didn't help. I got this variables in xDebug https://www.screencast.com/t/jnB9zo0I3K Test is running with next commands. Both give the same result

$ phpunit -c vendor/popov/magento-magmi-import/app/code/local/Popov/Magmi/Test/phpunit.xml
// or
$ phpunit -c htdocs/app/code/local/Popov/Magmi/Test/phpunit.xml
agereteam commented 7 years ago

I have another idea. Script can take over all siblings directories of vendor and search file app/Mage.php. In which directory this file will be find, then this is root project directory.

digitalpianism commented 7 years ago

@agereteam maybe this PR might help you: https://github.com/digitalpianism/testframework/pull/9