There is the following test. On my computer, the test works OK. On a computer of another developer, the testRoleDictFields method gives an error:

Argument # 2 (No Value) of PHPUnit_Framework_Assert :: assertObjectHasAttribute () must be a object

Those. $dict is not passed to it. The settings and versions of php, PHPUnit, config file and bootstrap are identical on both computers. What else could I miss?

  class RolesDictTest extends \PHPUnit_Framework_TestCase { public function testRoleDictGetById() { $dict = Dicts\Role::getByID(330); $this->assertInstanceOf(Dicts\Role::class, $dict); return $dict; } /** * @depends testRoleDictGetById * * @param $dict Dicts\Role */ public function testRoleDictFields($dict) { $this->assertObjectHasAttribute('id', $dict, 'Field "id" not defined'); $this->assertObjectHasAttribute('code', $dict, 'Field "code" not defined'); $this->assertObjectHasAttribute('name', $dict, 'Field "name" not defined'); $this->assertObjectHasAttribute('active', $dict, 'Field "active" not defined'); $this->assertObjectHasAttribute('sort', $dict, 'Field "sort" not defined'); } } 

UPD. I tried to rewrite the test using the provider.

Now the test looks like this:

 class RolesDictTest extends \PHPUnit_Framework_TestCase { /** * @dataProvider rolesIdProvider * * @param $dict Dicts\Role */ public function testRoleDictClass($dict) { $this->assertInstanceOf(Dicts\Role::class, $dict); } /** * @dataProvider rolesIdProvider * @depends testRoleDictClass * * @param $dict Dicts\Role */ public function testRoleDictFields($dict) { $this->assertObjectHasAttribute('id', $dict, 'Field "id" not defined'); $this->assertObjectHasAttribute('code', $dict, 'Field "code" not defined'); $this->assertObjectHasAttribute('name', $dict, 'Field "name" not defined'); $this->assertObjectHasAttribute('active', $dict, 'Field "active" not defined'); $this->assertObjectHasAttribute('sort', $dict, 'Field "sort" not defined'); } public function rolesIdProvider() { return [ 'with ID#330' => [Dicts\Role::getByID(330)], 'with ID#331' => [Dicts\Role::getByID(331)], 'with ID#333' => [Dicts\Role::getByID(333)], ]; } } 

The result is the same. Everything is OK on my computer. On another, testRoleDictFields does not receive input data.

    2 answers 2

    He does not have to. @Depends is not an indication of the method that creates the data, it is an indication that the annotated test should be run after that specified in @Depends , eg if a separate component and the entire system are tested, the second test indicates the dependence on the first through @Depends , so that In case of failure of the first test, do not drive the second, which also fails automatically.

    Obviously, you are looking for a data provider .

    • From the manual @depends "passed the result of that depended-upon test as its argument" It transmits the result of the producer’s execution as an argument to the consumer. ( phpunit.de/manual/current/en/en ... ) And, as mentioned, this test works out completely on my computer. - Dmitry Kozlov
    • @DmitryKozlov and I’ll tell you that you should not use dependency management to transfer data. Regarding a specific case - obviously, the versions still do not match, perhaps for some reason another version of phpunit is loaded before the composer, via the include path or else. - etki
    • "skis do not go skiing ..." generally redid the test for the use of the provider. The result is the same. On my computer, the test is processed, and on the other data is not transmitted to the input. I can't imagine where to dig now - Dmitry Kozlov
    • one
      @DmitryKozlov check again where phpunit loads from, if everything from the vendor and composer.lock matches - write issue to the maintainer. - etki
    • Evil found. The "victim" was included OpCache - Dmitry Kozlov

    OpCache was turned on on the problematic computer. Disconnect solved problem