2016-12-15 01:24:33 +01:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
|
|
|
use Psalm\Checker\FileChecker;
|
|
|
|
use Psalm\Context;
|
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class MethodSignatureTest extends TestCase
|
2016-12-15 01:24:33 +01:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
use Traits\FileCheckerInvalidCodeParseTestTrait;
|
2017-02-09 23:49:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExtendDocblockParamType()
|
|
|
|
{
|
2017-04-11 22:02:18 +02:00
|
|
|
if (class_exists('SoapClient') === false) {
|
2017-04-25 05:45:02 +02:00
|
|
|
$this->markTestSkipped('Cannot run test, base class "SoapClient" does not exist!');
|
2017-05-25 04:07:49 +02:00
|
|
|
|
2017-04-11 22:02:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-04-25 05:45:02 +02:00
|
|
|
|
2017-02-09 23:49:13 +01:00
|
|
|
$stmts = self::$parser->parse('<?php
|
|
|
|
class A extends SoapClient
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param string $function_name
|
|
|
|
* @param array<mixed> $arguments
|
|
|
|
* @param array<mixed> $options default null
|
|
|
|
* @param array<mixed> $input_headers default null
|
|
|
|
* @param array<mixed> $output_headers default null
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function __soapCall(
|
|
|
|
$function_name,
|
|
|
|
$arguments,
|
|
|
|
$options = [],
|
|
|
|
$input_headers = [],
|
|
|
|
&$output_headers = []
|
|
|
|
) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
');
|
|
|
|
|
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
|
|
|
$context = new Context();
|
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Psalm\Exception\CodeException
|
|
|
|
* @expectedExceptionMessage MethodSignatureMismatch
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-02-09 23:49:13 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExtendDocblockParamTypeWithWrongParam()
|
|
|
|
{
|
2017-04-11 22:02:18 +02:00
|
|
|
if (class_exists('SoapClient') === false) {
|
2017-04-25 05:45:02 +02:00
|
|
|
$this->markTestSkipped('Cannot run test, base class "SoapClient" does not exist!');
|
2017-05-25 04:07:49 +02:00
|
|
|
|
2017-04-11 22:02:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-04-25 05:45:02 +02:00
|
|
|
|
2017-02-09 23:49:13 +01:00
|
|
|
$stmts = self::$parser->parse('<?php
|
|
|
|
class A extends SoapClient
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param string $function_name
|
|
|
|
* @param string $arguments
|
|
|
|
* @param array<mixed> $options default null
|
|
|
|
* @param array<mixed> $input_headers default null
|
|
|
|
* @param array<mixed> $output_headers default null
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function __soapCall(
|
|
|
|
$function_name,
|
|
|
|
string $arguments,
|
|
|
|
$options = [],
|
|
|
|
$input_headers = [],
|
|
|
|
&$output_headers = []
|
|
|
|
) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
');
|
|
|
|
|
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
|
|
|
$context = new Context();
|
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
|
|
|
}
|
2017-04-25 05:45:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function providerFileCheckerInvalidCodeParse()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'moreArguments' => [
|
|
|
|
'<?php
|
|
|
|
class A {
|
|
|
|
public function fooFoo(int $a, bool $b) : void {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
|
|
|
public function fooFoo(int $a, bool $b, array $c) : void {
|
|
|
|
|
|
|
|
}
|
|
|
|
}',
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_message' => 'Method B::fooFoo has more arguments than parent method A::fooFoo',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'fewerArguments' => [
|
|
|
|
'<?php
|
|
|
|
class A {
|
|
|
|
public function fooFoo(int $a, bool $b) : void {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
|
|
|
public function fooFoo(int $a) : void {
|
|
|
|
|
|
|
|
}
|
|
|
|
}',
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_message' => 'Method B::fooFoo has fewer arguments than parent method A::fooFoo',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'differentArguments' => [
|
|
|
|
'<?php
|
|
|
|
class A {
|
|
|
|
public function fooFoo(int $a, bool $b) : void {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
|
|
|
public function fooFoo(bool $b, int $a) : void {
|
|
|
|
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'error_message' => 'Argument 1 of B::fooFoo has wrong type \'bool\', expecting \'int\' as defined ' .
|
2017-05-27 02:05:57 +02:00
|
|
|
'by A::foo',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
];
|
|
|
|
}
|
2016-12-15 01:24:33 +01:00
|
|
|
}
|