Тесты PHPUnit игнорируются, когда используется константа класса

Я пишу интеграционные тесты с PHPUnit 6.2.2 и Zendframework / Zend-тест 3.1.0 для приложения Zend Framework 3 и соблюдения следующего поведения:

Когда я определяю константу в тестовом классе, например,

use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
class FooTest extends AbstractHttpControllerTestCase
{
const MY_CONST = 123;
}

и использовать его в файле конфигурации, например,

// /config/autoload/test/mymodule.local.php
use Test\Integration\...\FooTest;
return [
'module' => [
'my' => [
'whatever' => [
'key' => FooTest::MY_CONST
]
]
]
];

тестовый класс полностью игнорируется. (Проверено с assertTrue(false).) Когда я заменяю FooTest::MY_CONST в конфигурационном файле по значению все снова работает.

Похоже, ошибка, но я не мог выяснить, является ли это ошибка в PHPUnit или в Zend\Test, Кто-нибудь наблюдал это поведение раньше? Идеи, чем это может быть вызвано (создать тикет об ошибке для PHPUnit или 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 up the MVC (application, service manager, autoloading) and the database.
*/
class Bootstrap
{

/** @var ServiceManager */
protected $serviceManager;

protected $applicationConfigPath;

public function __construct()
{
$this->applicationConfigPath = __DIR__ . '/../config/application.config.php';
}

/**
* Sets up the
*/
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 to 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();

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector