如何解决;“未找到类”;在PHPUnit测试中?

如何解决;“未找到类”;在PHPUnit测试中?,phpunit,symfony-2.8,Phpunit,Symfony 2.8,我刚刚通过升级到最新版本(6.2.1)解决了一些PHPUnit问题,但是现在我可以运行我的测试了 但是,我有一个无法解决的新错误: 1) BackBundle\Tests\Service\LdapServiceTest::testgetLdapConnect 错误:找不到类“BackBundle\Service\LdapService” 这是我的班级考试: <?php namespace BackBundle\Tests\Service; use PHPUnit\Framework\T

我刚刚通过升级到最新版本(6.2.1)解决了一些PHPUnit问题,但是现在我可以运行我的测试了

但是,我有一个无法解决的新错误:

1) BackBundle\Tests\Service\LdapServiceTest::testgetLdapConnect 错误:找不到类“BackBundle\Service\LdapService”

这是我的班级考试:

<?php

namespace BackBundle\Tests\Service;

use PHPUnit\Framework\TestCase;
use BackBundle\Service\LdapService;
use PHPUnit_Framework_MockObject_InvocationMocker;

class LdapServiceTest extends TestCase {

    public function testgetLdapConnect()
    {
        $ldap = new LdapService('10.0.0.100','10.0.0.100','mike','password',389,3,false,false);
        $ldapMock = $this->getMockBuilder( 'LdapService')->setMethods(array('getldapBind'))->disableOriginalConstructor()->getMock();
        $ldapMock->expects($this->any())
                ->method('getLdapBind')
            ->with(array('ldap_bind', 'mike', 'password'))
            ->will($this->returnValue(true));

        $this->assertTrue($ldap->getLdapBind());

//        $LdapService = new LdapService();
//        $LdapService.getLdapBind();
//        $ldapMock->isAuthorized('mike', 'password');
    }
}

为什么您的配置看起来像一个phing文件?我猜这是一个权限问题。尝试删除
sudo
,或者让我们知道您使用它的原因-使用root权限运行PHPUnit是非常罕见的。即使我尝试不使用sudo,也会得到相同的结果errors@user7791590:回复某人时,请使用他们的手柄,如
@halfer
。我没有看到您的答复,只是碰巧看到了。您能否在问题中编辑(1)如何启动PHPUnit,特别是使用的开关/标志,(2)您的
PHPUnit.xml
配置。我觉得您需要在测试引导中包含您的
供应商/autoload.php
,但您没有这样做。
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
         backupGlobals="false"
         colors="true"
         bootstrap="app"
>
    <php>
        <ini name="error_reporting" value="-1" />
        <server name="KERNEL_DIR" value="app/" />
    </php>

    <testsuites>
        <testsuite name="Project Test Suite">
            <directory>Tests</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory>src</directory>
            <exclude>
                <directory>src/*Bundle/Resources</directory>
                <directory>src/*/*Bundle/Resources</directory>
                <directory>src/*/Bundle/*Bundle/Resources</directory>
            </exclude>
        </whitelist>
    </filter>
</phpunit>
<?php
if (!defined('TEST_FILES_PATH')) {
    define('TEST_FILES_PATH', __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR);
}

ini_set('precision', 14);
ini_set('serialize_precision', 14);

require_once __DIR__ . '/../vendor/autoload.php';

// TODO: Figure out why (some of) these are required (the classes should be autoloaded instead)
require_once TEST_FILES_PATH . 'BeforeAndAfterTest.php';
require_once TEST_FILES_PATH . 'BeforeClassAndAfterClassTest.php';
require_once TEST_FILES_PATH . 'TestWithTest.php';
require_once TEST_FILES_PATH . 'BeforeClassWithOnlyDataProviderTest.php';
require_once TEST_FILES_PATH . 'DataProviderSkippedTest.php';
require_once TEST_FILES_PATH . 'DataProviderDependencyTest.php';
require_once TEST_FILES_PATH . 'DataProviderIncompleteTest.php';
require_once TEST_FILES_PATH . 'InheritedTestCase.php';
require_once TEST_FILES_PATH . 'NoTestCaseClass.php';
require_once TEST_FILES_PATH . 'NoTestCases.php';
require_once TEST_FILES_PATH . 'NotPublicTestCase.php';
require_once TEST_FILES_PATH . 'NotVoidTestCase.php';
require_once TEST_FILES_PATH . 'OverrideTestCase.php';
require_once TEST_FILES_PATH . 'RequirementsClassBeforeClassHookTest.php';
require_once TEST_FILES_PATH . 'NoArgTestCaseTest.php';
require_once TEST_FILES_PATH . 'Singleton.php';
require_once TEST_FILES_PATH . 'Mockable.php';
require_once TEST_FILES_PATH . 'CoverageNamespacedFunctionTest.php';
require_once TEST_FILES_PATH . 'NamespaceCoveredFunction.php';