php - How to use my own autoloader instead of Composer's for unit testing? -
what bootstrap
in phpunit.xml? how can use own autoloader instead of composer's unit testing?
directory structure,
autoload/ test/ vendor/ composer.json phpunit.xml
originals:
<?xml version="1.0" encoding="utf-8"?> <phpunit colors="true" bootstrap="vendor/autoload.php"> <testsuites> <testsuite name="application test suite"> <directory>./test/</directory> </testsuite> </testsuites> </phpunit>
composer.json,
{ "require": { }, "require-dev": { "phpunit/phpunit": "*" }, "autoload": { "psr-0": { "stats": "" } } }
original test resutl,
below own autoload class autoload/classloader.php
,
<?php namespace myvendor\autoload; class classloader { public function fetch( $directories ) { spl_autoload_register( [$this, 'getclass'] ); } private function getclass( $classname ) { .... } }
my phpunit.xml
, changed bootsrap
autoload/classloader.php
<?xml version="1.0" encoding="utf-8"?> <phpunit colors="true" bootstrap="autoload/classloader.php"> <testsuites> <testsuite name="application test suite"> <directory>./test/</directory> </testsuite> </testsuites> </phpunit>
when run phpunit
in cmd , test result,
it looks different original didn't failed. test correct?
any ideas?
create own bootstrap.php file, , use spl_autoload_register register autoloader:
// external spl_autoload_register('classloader::getclass'); // internal function autoload($classname) { .... } spl_autoload_register('autoload');
then call in phpunit.xml file:
<?xml version="1.0" encoding="utf-8"?> <phpunit colors="true" bootstrap="bootstrap.php"> ...
Comments
Post a Comment