Skip to content

Anonyomus classes in 2.3 (test data provider) #21555

Closed
@oskar1233

Description

@oskar1233

Preconditions (*)

  1. Magento 2.3
  2. PHP 7.2

Steps to reproduce (*)

  1. Create a new module
  2. Create a test with data provider returning anonymous class
  3. ./bin/magento setup:di:compile

Expected result (*)

  1. Compilation succed

Actual result (*)

  1. Notice: Uninitialized string offset: 1 in /var/www/setup/src/Magento/Setup/Module/Di/Code/Scanner/PhpScanner.php on line 219

My sample test class looks like this:

<?php

namespace OskarLaska\Xyz\Test\Unit;

class TestTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @param $theObject
     *
     * @dataProvider someProvider
     */
    public function testX($theObject)
    {
        $this->assertEquals('It works!', $theObject->callMe());
    }

    public function someProvider()
    {
        return [
            'test' => [
                new class {
                    public function callMe() {
                        return 'It works!';
                    }
                }
            ]
        ];
    }
}

Not sure if the anonymous class needs to be in data provider of PHPUnit's test. I saw other issues with anonymous classes resolved hence I provide my specific case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fixed in 2.4.xThe issue has been fixed in 2.4-develop branchIssue: Format is validGate 1 Passed. Automatic verification of issue format passed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions