php - PHPUnit tests ignored, when a class constant is in use -
i'm writing integration tests phpunit 6.2.2
, zendframework/zend-test 3.1.0
zend framework 3 application , observing following behavior:
when define constant in test class, e.g.
use zend\test\phpunit\controller\abstracthttpcontrollertestcase; class footest extends abstracthttpcontrollertestcase { const my_const = 123; }
and use in configuration file, e.g.
// /config/autoload/test/mymodule.local.php use test\integration\...\footest; return [ 'module' => [ 'my' => [ 'whatever' => [ 'key' => footest::my_const ] ] ] ];
the test class gets ignored. (checked asserttrue(false)
.) when replace footest::my_const
in config file value, works again.
looks bug, not find out, whether it's bug in phpunit or in zend\test
. has observed behavior before? ideas, might caused (to create bug ticket phpunit or zend\test
)?
phpunit.xml
<?xml version="1.0" encoding="utf-8"?> <phpunit xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:nonamespaceschemalocation="http://schema.phpunit.de/6.1/phpunit.xsd" backupglobals="false" backupstaticattributes="false" bootstrap="test/bootstrap.php" cachetokens="false" colors="true" > <php> <env name="runtime_context" value="testing"/> </php> <testsuites> <testsuite name="unit-app-only"> <directory suffix="test.php">test/unit</directory> </testsuite> <testsuite name="integration-app-only"> <directory suffix="test.php">test/integration</directory> </testsuite> <testsuite name="app-lib"> <directory suffix="test.php">vendor/my-namespace/my-common-lib/tests</directory> </testsuite> </testsuites> <logging> <log type="coverage-html" target="build/coverage"/> <log type="coverage-clover" target="build/logs/clover.xml"/> <log type="coverage-crap4j" target="build/logs/crap4j.xml"/> <log type="junit" target="build/logs/junit.xml" logincompleteskipped="false"/> </logging> <filter> <whitelist processuncoveredfilesfromwhitelist="true"> <directory suffix=".php">module/**/src</directory> <directory suffix=".php">vendor/my-namespace/**/src</directory> <exclude> <directory suffix=".php">vendor/my-namespace/**/tests</directory> </exclude> </whitelist> </filter> </phpunit>
test/bootstrap.php
namespace test; use mynamespace\test\abstractcontrollerdbtest; use mynamespace\test\abstractcontrollertest; use mynamespace\test\abstractdbtest; use mynamespace\test\databaseinitializer; use runtimeexception; use zend\loader\autoloaderfactory; use zend\mvc\service\servicemanagerconfig; use zend\servicemanager\servicemanager; error_reporting(e_all | e_strict); ini_set('memory_limit', '768m'); chdir(__dir__); /** * sets mvc (application, service manager, autoloading) , database. */ class bootstrap { /** @var servicemanager */ protected $servicemanager; protected $applicationconfigpath; public function __construct() { $this->applicationconfigpath = __dir__ . '/../config/application.config.php'; } /** * sets */ public function init() { // autoloading setup static::initautoloader(); // application configuration $applicationconfig = require_once $this->applicationconfigpath; // service manager setup $this->setupservicemanager($applicationconfig); // application setup $this->bootstrapapplication($applicationconfig); // database setup $dbconfigs = $this->servicemanager->get('config')['db']; self::setupdatabase($dbconfigs); } public function chroot() { $rootpath = dirname(static::findparentpath('module')); chdir($rootpath); } protected function setupservicemanager($config) { $servicemanagerconfig = isset($config['service_manager']) ? $config['service_manager'] : []; $servicemanagerconfigobject = new servicemanagerconfig($servicemanagerconfig); $this->servicemanager = new servicemanager(); $servicemanagerconfigobject->configureservicemanager($this->servicemanager); } protected function bootstrapapplication($config) { $this->servicemanager->setservice('applicationconfig', $config); $this->servicemanager->get('modulemanager')->loadmodules(); $listenersfromappconfig = isset($configuration['listeners']) ? $configuration['listeners'] : []; $config = $this->servicemanager->get('config'); $listenersfromconfigservice = isset($config['listeners']) ? $config['listeners'] : []; $listeners = array_unique(array_merge($listenersfromconfigservice, $listenersfromappconfig)); $application = $this->servicemanager->get('application'); $application->bootstrap($listeners); } protected function setupdatabase(array $dbconfigs) { $databaseinitializer = new databaseinitializer($dbconfigs); $databaseinitializer->setup(); abstractdbtest::setdbconfigs($dbconfigs); abstractcontrollertest::setapplicationconfigpath($this->applicationconfigpath); abstractcontrollertest::setdbconfigs($dbconfigs); } protected function initautoloader() { $vendorpath = static::findparentpath('vendor'); if (file_exists($vendorpath.'/autoload.php')) { include $vendorpath.'/autoload.php'; } if (! class_exists('zend\loader\autoloaderfactory')) { throw new runtimeexception( 'unable load zf2. run `php composer.phar install`' ); } autoloaderfactory::factory(array( 'zend\loader\standardautoloader' => array( 'autoregister_zf' => true, 'namespaces' => array( __namespace__ => __dir__, ), ), )); } protected function findparentpath($path) { $dir = __dir__; $previousdir = '.'; while (!is_dir($dir . '/' . $path)) { $dir = dirname($dir); if ($previousdir === $dir) { return false; } $previousdir = $dir; } return $dir . '/' . $path; } } $bootstrap = new bootstrap(); $bootstrap->init(); $bootstrap->chroot();
Comments
Post a Comment