Composer file is set up wrong? Not Auto loading my class - PHP -
in above image can see composer.json
. file belongs freya/loader/assets, can see expanded.
you can see vendor directory created , have phpunit.xml file looks such:
<phpunit bootstrap="bootstrap.php" backupglobals="false" colors="true" converterrorstoexceptions="true" convertnoticestoexceptions="true" convertwarningstoexceptions="true" > <testsuites> <testsuite> <directory suffix="test.php">./tests</directory> </testsuite> </testsuites> </phpunit>
when run phpunit
in terminal while in directory error:
php fatal error: class 'assetloader' not found in /vagrant/freya/loader/assets/tests/assetstest.php on line 18
the test looks like:
<?php use freya\loader\assets; class assetstest extends wp_unittestcase { public function testassetsareregistered() { // $assetstoregister = array( // 'css' => array( // 'some_file' => 'http://example.com' // ), // 'js' => array( // 'some_file' => 'http://example.com' // ) // 'front_jquery_version' => '2.7.1' // ); $assets = new assetloader(); var_dump($assets->getassets()); } }
i cannot figure out why file not being required. using psr-4
standards , far can tell there nothing wrong composer file. class rather long docs, ill paste shell show namespace , class definition:
assetloader.php
<?php namespace freya\loader\assets; class assetloader { ... }
**did miss something? type wrong? looks correct me ... **
update one
as requested please see bootstrap file.
<?php /** ---------------------------------------------------- **/ // require vendors autoload file. /** ---------------------------------------------------- **/ require_once 'vendor/autoload.php'; /** ---------------------------------------------------- **/ // neeed wordpress bootstrap files test. /** ---------------------------------------------------- **/ define('wp_test_dir', parse_ini_file('test-config.ini')['test-location']); // include bootstrap file. require_once wp_test_dir . 'includes/bootstrap.php'; // include functions file require_once wp_test_dir . 'includes/functions.php';
update 2
so 1 suggested run composer dump-autoload
did, ran phpunit , got same issue:
$ composer dump-autoload generating autoload files $ phpunit configuration read /vagrant/freya/loader/assets/phpunit.xml php fatal error: class 'assetloader' not found in /vagrant/freya/loader/assets/tests/assetstest.php on line 18 php stack trace: php 1. {main}() /usr/local/bin/phpunit:0 php 2. phpunit_textui_command::main() /usr/local/bin/phpunit:535 php 3. phpunit_textui_command->run() phar:///usr/local/bin/phpunit/phpunit/textui/command.php:105 php 4. phpunit_textui_testrunner->dorun() phar:///usr/local/bin/phpunit/phpunit/textui/command.php:153 php 5. phpunit_framework_testsuite->run() phar:///usr/local/bin/phpunit/phpunit/textui/testrunner.php:406 php 6. phpunit_framework_testsuite->run() phar:///usr/local/bin/phpunit/phpunit/framework/testsuite.php:722 php 7. phpunit_framework_testcase->run() phar:///usr/local/bin/phpunit/phpunit/framework/testsuite.php:722 php 8. phpunit_framework_testresult->run() phar:///usr/local/bin/phpunit/phpunit/framework/testcase.php:699 php 9. phpunit_framework_testcase->runbare() phar:///usr/local/bin/phpunit/phpunit/framework/testresult.php:609 php 10. phpunit_framework_testcase->runtest() phar:///usr/local/bin/phpunit/phpunit/framework/testcase.php:743 php 11. reflectionmethod->invokeargs() phar:///usr/local/bin/phpunit/phpunit/framework/testcase.php:866 php 12. assetstest->testassetsareregistered() phar:///usr/local/bin/phpunit/phpunit/framework/testcase.php:866 fatal error: class 'assetloader' not found in /vagrant/freya/loader/assets/tests/assetstest.php on line 18 call stack: 0.0007 389896 1. {main}() /usr/local/bin/phpunit:0 0.0789 13012000 2. phpunit_textui_command::main() /usr/local/bin/phpunit:535 0.0789 13012648 3. phpunit_textui_command->run() phar:///usr/local/bin/phpunit/phpunit/textui/command.php:105 1.6249 38992520 4. phpunit_textui_testrunner->dorun() phar:///usr/local/bin/phpunit/phpunit/textui/command.php:153 1.6292 39003688 5. phpunit_framework_testsuite->run() phar:///usr/local/bin/phpunit/phpunit/textui/testrunner.php:406 1.6294 39007208 6. phpunit_framework_testsuite->run() phar:///usr/local/bin/phpunit/phpunit/framework/testsuite.php:722 1.6305 39011272 7. phpunit_framework_testcase->run() phar:///usr/local/bin/phpunit/phpunit/framework/testsuite.php:722 1.6305 39012816 8. phpunit_framework_testresult->run() phar:///usr/local/bin/phpunit/phpunit/framework/testcase.php:699 1.6306 39015248 9. phpunit_framework_testcase->runbare() phar:///usr/local/bin/phpunit/phpunit/framework/testresult.php:609 1.6409 39068824 10. phpunit_framework_testcase->runtest() phar:///usr/local/bin/phpunit/phpunit/framework/testcase.php:743 1.6409 39069592 11. reflectionmethod->invokeargs() phar:///usr/local/bin/phpunit/phpunit/framework/testcase.php:866 1.6410 39069672 12. assetstest->testassetsareregistered() phar:///usr/local/bin/phpunit/phpunit/framework/testcase.php:866
use freya\loader\assets;
this doesn't mean "import namespace" may used other languages. in php, means: alias freya\loader\assets
assets
in file.
this means new assetsloader()
still tries load global scope (that's why see assetsloader
in class not found message, instead of freya\loader\assets\assetsloader
).
to make work, either use new assets\assetsloader()
(remember, aliased freya\loader\assets
assets
) or use freya\loader\assets\assetsloader
(this way, assetsloader
aliased fqcn).
Comments
Post a Comment