BjyAuthorize和PHPUnit

BjyAuthorize和PHPUnit,phpunit,zfcuser,bjyauthorize,Phpunit,Zfcuser,Bjyauthorize,我开始使用ZfcUser+BjyAuthorize为Zend Framework 2项目进行单元测试 我不是单元测试专家,所以我找到了如何模仿ZfcUser的方法 现在我也不得不嘲笑BjyAuthorize。以前有人这样做过吗?好吧,现在回应这个问题肯定太晚了 我已经找到了一个使用Mock对象的解决方案,我不喜欢使用Mock…,我找不到一种方法来正确初始化BjyAuthorize 我的测试控制器扩展自AbstractHttpControllerTestCase 在testController::

我开始使用ZfcUser+BjyAuthorize为Zend Framework 2项目进行单元测试

我不是单元测试专家,所以我找到了如何模仿ZfcUser的方法


现在我也不得不嘲笑BjyAuthorize。以前有人这样做过吗?

好吧,现在回应这个问题肯定太晚了

我已经找到了一个使用Mock对象的解决方案,我不喜欢使用Mock…,我找不到一种方法来正确初始化BjyAuthorize

我的测试控制器扩展自AbstractHttpControllerTestCase

在testController::setUp中,我创建了如下模拟对象:

    // Creating mock
    $mockBjy = $this->getMock("BjyAuthorize\Service\Authorize", array("isAllowed"), array($this->getApplicationConfig(), $this->getApplication()->getServiceManager()));

    // Bypass auth, force true
    $mockBjy->expects($this->any())
            ->method('isAllowed')
            ->will($this->returnValue(true)); 

    // Overriding BjyAuthorize\Service\Authorize service
    $this->getApplication()
         ->getServiceManager()
         ->setAllowOverride(true)
         ->setService('BjyAuthorize\Service\Authorize', $mockBjy);

虽然我不喜欢这个解决方案,但我觉得它确实很难看,但我找不到其他方法来解决这个问题。

好吧,现在回应这个问题肯定太晚了

我已经找到了一个使用Mock对象的解决方案,我不喜欢使用Mock…,我找不到一种方法来正确初始化BjyAuthorize

我的测试控制器扩展自AbstractHttpControllerTestCase

在testController::setUp中,我创建了如下模拟对象:

    // Creating mock
    $mockBjy = $this->getMock("BjyAuthorize\Service\Authorize", array("isAllowed"), array($this->getApplicationConfig(), $this->getApplication()->getServiceManager()));

    // Bypass auth, force true
    $mockBjy->expects($this->any())
            ->method('isAllowed')
            ->will($this->returnValue(true)); 

    // Overriding BjyAuthorize\Service\Authorize service
    $this->getApplication()
         ->getServiceManager()
         ->setAllowOverride(true)
         ->setService('BjyAuthorize\Service\Authorize', $mockBjy);

虽然我不喜欢这个解决方案,但我觉得它很难看,但我找不到其他方法来实现它。

确实很晚了,我最终切换到Selenium+PHPUnit来测试我的网站,它看起来很有希望,因为它易于使用,并且可以测试JavaScript,同时我的一半代码实际上是JavaScript。确实很晚了,我最终切换到Selenium+PHPUnit来测试我的网站,它看起来很有希望,因为它易于使用,并且可以同时测试JavaScript,而我的一半代码实际上是JavaScript。