PHPUnit @dataProvider simply doesn't work

前端 未结 8 1767
后悔当初
后悔当初 2021-02-01 16:04

I\'ve read the documentation on the topic, and my code follows all requirements of a data provider implementation. First of all, here\'s the full code of the test just in case i

8条回答
  •  滥情空心
    2021-02-01 16:23

    Finally after hours of prodding this test file, I discovered that merely defining the constructor function breaks the functionality of data providers. Good to know.

    To fix it, just call the parent constructor. Here's how that looked in my case:

    public function __construct()
    {
        // Truncate the OmniDataManager tables
        R::wipe(OmniDataManager::TABLE_GROUP);
        R::wipe(OmniDataManager::TABLE_DATA);
    
        parent::__construct();   // <- Necessary
    }
    

    As David Harkness and Vasily pointed out in the comments, the constructor override must match the call signature of the base class constructor. In my case the base class constructor didn't require any arguments. I'm not sure if this has just changed in newer versions of phpunit or if it depends on your use case.

    In any case, Vasily's example might work better for you:

    public function __construct($name = null, array $data = array(), $dataName = '')
    {
        // Your setup code here
    
        parent::__construct($name, $data, $dataName)
    }
    

提交回复
热议问题