Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type error on using getMockFromWsdl() #4535

Closed
bretrzaun opened this issue Dec 2, 2020 · 5 comments
Closed

Type error on using getMockFromWsdl() #4535

bretrzaun opened this issue Dec 2, 2020 · 5 comments
Assignees
Labels
feature/test-doubles Stubs and Mock Objects type/bug Something is broken

Comments

@bretrzaun
Copy link

Q A
PHPUnit version 9.4.4
PHP version 7.4.12
Installation Method Composer

Summary

Type error from getMockFromWsdl()

Current behavior

Test exists with: "substr() expects parameter 2 to be int, bool given"

How to reproduce

Create a mock SOAP client with the attached WSDL file.
mantis.wsdl.zip

protected function setUp(): void
    {
        parent::setUp();
        $this->soapclient = $this->getMockFromWsdl(__DIR__ . '/../../data/wsdl/mantis.wsdl');
       ...

Expected behavior

SoapClient should be created without error.

@bretrzaun bretrzaun added the type/bug Something is broken label Dec 2, 2020
@bretrzaun
Copy link
Author

btw: was working before upgrading from PHPUnit 7.5

@bretrzaun
Copy link
Author

bretrzaun commented Dec 2, 2020

Some further digging I found this stack trace - maybe this helps:

^ TypeError {#777
  #message: "substr() expects parameter 2 to be int, bool given"
  #code: 0
  #file: "./bin/.phpunit/phpunit-9-0/src/Framework/MockObject/Generator.php"
  #line: 416
  trace: {
    ./bin/.phpunit/phpunit-9-0/src/Framework/MockObject/Generator.php:416 {
      PHPUnit\Framework\MockObject\Generator->generateClassFromWsdl(string $wsdlFile, string $className, array $methods = [], array $options = []): string^
      › foreach (range(0, count($args) - 1) as $i) {
      ›     $args[$i] = substr($args[$i], strpos($args[$i], '$'));
      › }
      arguments: {
        $str: ""
        $start: false
      }
    }
    ./bin/.phpunit/phpunit-9-0/src/Framework/TestCase.php:1861 { …}
    ./tests/Ticketing/Adapter/MantisAdapterTest.php:40 { …}
    ./bin/.phpunit/phpunit-9-0/src/Framework/TestCase.php:1136 { …}
    ./bin/.phpunit/phpunit-9-0/src/Framework/TestResult.php:730 { …}
    ./bin/.phpunit/phpunit-9-0/src/Framework/TestCase.php:884 { …}
    ./bin/.phpunit/phpunit-9-0/src/Framework/TestSuite.php:677 { …}
    ./bin/.phpunit/phpunit-9-0/src/Framework/TestSuite.php:677 { …}
    ./bin/.phpunit/phpunit-9-0/src/Framework/TestSuite.php:677 { …}
    ./bin/.phpunit/phpunit-9-0/src/TextUI/TestRunner.php:667 { …}
    ./bin/.phpunit/phpunit-9-0/src/TextUI/Command.php:148 { …}
    ./bin/.phpunit/phpunit-9-0/src/TextUI/Command.php:101 { …}
    ./bin/.phpunit/phpunit-9-0/phpunit:22 { …}
    ./vendor/symfony/phpunit-bridge/bin/simple-phpunit.php:404 { …}
    ./bin/phpunit:13 { …}
  }

The error seems to happen with the soap method "mc_version" which has no parameters.

@sebastianbergmann
Copy link
Owner

Are you sure you use PHPUnit 9.4? The phpunit-9-0 in your path makes me think you might be using PHPUnit 9.0.

@sebastianbergmann sebastianbergmann self-assigned this Dec 3, 2020
@sebastianbergmann sebastianbergmann added the feature/test-doubles Stubs and Mock Objects label Dec 3, 2020
@bretrzaun
Copy link
Author

Yes - I am pretty sure to use version 9.4.4. The output confirms that:

PHPUnit 9.4.4 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.4.12
Configuration: /var/www/phpunit.xml.dist
Warning:       XDEBUG_MODE=coverage or xdebug.mode=coverage has to be set

Testing 
^ TypeError {#777
  #message: "substr() expects parameter 2 to be int, bool given"
  #code: 0
  #file: "./vendor/bin/.phpunit/phpunit-9.4.4-0/src/Framework/MockObject/Generator.php"
  #line: 416

The path is now more obivous since I changed:

   <server name="SYMFONY_PHPUNIT_VERSION" value="9"/>

to

   <server name="SYMFONY_PHPUNIT_VERSION" value="9.4.4"/>

However the error still persists, because line 416 in phpunit-9.4.4-0/src/Framework/MockObject/Generator.php still says:

                    $args[$i] = substr($args[$i], strpos($args[$i], '$'));

and does not include the changes you mention from the commit above.
See: https://github.com/sebastianbergmann/phpunit/blob/9.4.4/src/Framework/MockObject/Generator.php#L416

@sebastianbergmann
Copy link
Owner

075d8ee has not made it into a release yet, correct.

This was referenced Mar 12, 2021
This was referenced Mar 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/test-doubles Stubs and Mock Objects type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

2 participants