我正在使用Symfony框架的guard component开发phpcas包。我的包正在工作,但我想做一些单元测试。我想测试我的CasAuthenticator。 PhpCAS library正在使用静态方法。所以我决定用Mock Aspect来嘲笑它。我在模拟方面配置中错过了什么?
我配置了看点,但我仍然有一个错误。
这是一个正在运行但失败的简化测试。
预计PhpCAS :: setDebug被调用,但它从未发生过。得到:
C:\ wamp64 \ WWW \ casguard \ casguard \厂商\ codeception \纵横模拟\ SRC \ AspectMock \代理\ Verifier.php:64
C:\ wamp64 \ WWW \ casguard \ casguard \测试\ SimpleTest.php:32
//root_dir/Tests/SimpleTest.php
namespace AlexandreT\Bundle\CasGuardBundle\Tests;
use PHPUnit\Framework\TestCase;
use AspectMock\Test as test;
use PhpCAS;
class SimpleTest extends TestCase
{
public function testAspectMock()
{
$phpCas = test::double('PhpCAS', ['setDebug' => function() {
echo 'YES I CALL THE MOCKED Debug function';
}]);
PhpCAS::setDebug();
$phpCas->verifyInvoked('setDebug', false);
}
protected function tearDown()
{
parent::tearDown();
test::clean();
}
}
输出不包含YES我CALL嘲笑调试功能,所以我认为PhpCAS不受看点嘲笑。
我仔细看了this documentation和我配置我的引导文件是这样的:
//root_dir/Tests/bootstrap.php
include __DIR__.'/../vendor/autoload.php'; // composer autoload
$kernel = \AspectMock\Kernel::getInstance();
$kernel->init([
'debug' => true,
'includePaths' => [
__DIR__.'/../vendor/jasig/phpcas',
],
]);
正如你可以看到,我增加了供应商目录,其中Cas.php
声明PhpCAS类。但它不会改变任何事情。我做了一些测试:bootstrap.php文件由phpunit加载。
我在模拟方面配置中错过了什么?