我无法使用PHPUnit(版本5.7)来查找我的Custom Framework类。任何帮助将不胜感激,因为我已经尝试了很多。当我运行测试时,它抱怨无法找到自动加载的类。
{
"scripts": {
"test": [
"@clean",
"@load",
"@phpunit"
],
"clean": "composer clear-cache",
"load": "composer dump-autoload -o",
"phpunit": "\"vendor/bin/phpunit\" --configuration phpunit.xml tests"
},
"autoload": {
"psr-4": {
"AdoptableFramework\\": "src/",
"AdoptableFramework\\Tests\\": "tests/",
"AdoptableFramework\\Extend\\": "src/extend/"
}
},
"require": {
"matthiasmullie/minify": "^1.3"
},
"require-dev": {
"phpunit/phpunit": "5.7"
}
}
这就是我的phpunit.xml:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.7/phpunit.xsd"
bootstrap="vendor\autoload.php"
backupGlobals="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
backupStaticAttributes="false"
cacheTokens="false"
colors="always"
convertErrorsToExceptions="true"
convertNoticesToExceptions="false"
convertWarningsToExceptions="false"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
verbose="true">
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/AdoptableFramework</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="tests/code_coverage"
showUncoveredFiles="true"/>
</logging>
</phpunit>
我的文件夹结构如下:
src
--AdoptableFramework
----Core
------Database.php tests
--databaseTest.php
--unitTestSuite.php
这就是我的databaseTest.php的样子:
<?php
namespace AdoptableFramework\Tests;
use AdoptableFramework\Core\Database;
use AdoptableFramework\Tests\unitTestSuite;
class DatabaseTest extends UnitTestSuite
{
public function testDatabase()
{
$database = new Database();
$this->assertEquals(null, $database);
}
}
?>
这是我的Database.php withint AdoptableFramework / Core。
<?
/**
* @link https://www.pswebsolutions.co.uk/
* @author Paul Sonny Cook <paul.cook@pswebsolutions.co.uk>
* @copyright 2017 P S Web Solutions Ltd
* @version 1.0.0
* @package psAdoptables
**/
namespace AdoptableFramework\Core;
class Database
{
public function __construct($host = null, $username = null, $password = null, $database = null) {
$this->type = __CLASS__;
if ($host || $username || $password || $database) {
$this->connect($host, $username, $password, $database);
} else {
$this->connect();
}
}
public function connect($host = DB_HOST, $username = DB_USER, $password = DB_PASS, $database = DB_DATABASE)
{
return true;
}
}
?>
autoload_static.php类映射:
我查看了我的autoload_static.php文件,可以看到:
'AdoptableFramework\\Core\\Database' => __DIR__ . '/../..' . '/src/AdoptableFramework/Core/Database.php',
'AdoptableFramework\\Extend\\ExtendDatabase' => __DIR__ . '/../..' . '/src/AdoptableFramework/Extend/ExtendDatabase.php',
'AdoptableFramework\\Game' => __DIR__ . '/../..' . '/src/AdoptableFramework/Game.php',
'AdoptableFramework\\Tests\\DatabaseTest' => __DIR__ . '/../..' . '/tests/databaseTest.php',
'AdoptableFramework\\Tests\\UnitTestSuite' => __DIR__ . '/../..' . '/tests/unitTestSuite.php',
非常感谢任何帮助。
答案 0 :(得分:0)
我认为您的src/AdoptableFramework
目录不是必需的。您可以将其删除并将所有文件移动一级或尝试使用此语句:
use AdoptableFramework\AdoptableFramework\Core\Database;
此行"AdoptableFramework\\": "src/",
告诉自动加载器 src 文件夹中的任何类已存在于 AdoptableFramework 命名空间中。例如,如果您以这种方式Foo
创建类src/Foo.php
,则会以这种方式导入:
use AdoptableFramework\Foo;
答案 1 :(得分:0)
非常抱歉浪费每个人的时间!
php文件正在加载为文本,因为它想要
一旦我改变了所有内容,点击就位并开始工作!