如何测试ZF2服务

时间:2015-09-29 09:47:07

标签: php service zend-framework2 phpunit

我想测试我的服务,这些服务主要由我的控制器调用。 我实现了这个:

  class FMaiAffaireServiceTest extends TestCase
    {
        public function setUp()
        {
            $this->myService = new FMaiAffaireService();
        }

        public function listAffairesCountTest()
        {
            $this->myService->listAffairesCount();
        }
    }

但PHPUnit在此处无法识别任何测试。我怎么能实现我的小测试:)?感谢。

这是我的功能(我没有提到数据库模拟意图)

class FMaiAffaireService
{
    public function __construct(
        FMaiAffaireTable $maiAffaireTable
    ) {
        $this->maiAffaireTable      = $maiAffaireTable;
    }

    public function listAffairesCount()
    {
        return $this->maiAffaireTable->listAffairesCount();
    }
}

1 个答案:

答案 0 :(得分:2)

PHPUnit将识别以//Upload image function upload($path,$token,$fb) { $image = [ 'message' => 'My awesome photo upload example.', 'source' => $fb->fileToUpload($path), // $fb is instance ]; try { // Returns a `Facebook\FacebookResponse` object $response = $fb->post('/me/photos', $image, $token); } catch(Facebook\Exceptions\FacebookResponseException $e) { echo 'Graph returned an error: ' . $e->getMessage(); exit; } catch(Facebook\Exceptions\FacebookSDKException $e) { echo 'Facebook SDK returned an error: ' . $e->getMessage(); exit; } $graphNode = $response->getGraphNode(); debug_to_console($graphNode); echo " \n Photo ID: " . $graphNode['id']; } 开头的任何public function作为测试。因此,test代替listAffairesCountTest,您的测试需要命名为testListAffairesCount

https://phpunit.de/getting-started.html