我刚刚通过升级到最新版本(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');
}
}
这是我的phpunit.xml:
<?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>
以下是bootstrap.php的内容:
<?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';