2017-02-11 03:27:12 +01:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
use Psalm\Context;
|
2017-02-11 03:27:12 +01:00
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class BadFormatTest extends TestCase
|
2017-02-11 03:27:12 +01:00
|
|
|
{
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testMissingSemicolon(): void
|
2017-02-11 03:27:12 +01:00
|
|
|
{
|
2019-05-17 00:36:36 +02:00
|
|
|
$this->expectExceptionMessage('ParseError - somefile.php:9');
|
|
|
|
$this->expectException(\Psalm\Exception\CodeException::class);
|
2017-07-25 22:11:02 +02:00
|
|
|
$this->addFile(
|
2017-04-25 05:45:02 +02:00
|
|
|
'somefile.php',
|
2017-02-11 03:27:12 +01:00
|
|
|
'<?php
|
2017-07-25 22:11:02 +02:00
|
|
|
class A {
|
|
|
|
/** @var int|null */
|
|
|
|
protected $hello;
|
2017-02-11 03:27:12 +01:00
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
/** @return void */
|
|
|
|
function foo() {
|
|
|
|
$this->hello = 5
|
|
|
|
}
|
|
|
|
}'
|
2017-02-11 03:27:12 +01:00
|
|
|
);
|
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
2017-02-11 03:27:12 +01:00
|
|
|
}
|
2018-10-26 06:59:14 +02:00
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testClassMethodWithNoStmts(): void
|
2019-01-19 18:19:51 +01:00
|
|
|
{
|
2019-05-17 00:36:36 +02:00
|
|
|
$this->expectExceptionMessage('ParseError - somefile.php:3');
|
|
|
|
$this->expectException(\Psalm\Exception\CodeException::class);
|
2019-01-19 18:19:51 +01:00
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
class A {
|
|
|
|
public function foo() : void;
|
|
|
|
}'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testInterfaceWithProperties(): void
|
2019-05-23 16:21:56 +02:00
|
|
|
{
|
|
|
|
$this->expectExceptionMessage('ParseError - somefile.php:3');
|
|
|
|
$this->expectException(\Psalm\Exception\CodeException::class);
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
interface foo {
|
|
|
|
public static $foo = ["bar"];
|
|
|
|
}'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testTypingReturnType(): void
|
2018-10-26 06:59:14 +02:00
|
|
|
{
|
2019-05-17 00:36:36 +02:00
|
|
|
$this->expectExceptionMessage('ParseError - somefile.php:5');
|
|
|
|
$this->expectException(\Psalm\Exception\CodeException::class);
|
2018-10-26 06:59:14 +02:00
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
class A {
|
|
|
|
/** @return void */
|
|
|
|
protected function _getCollaborators(User $user, User $cur_user = null) :
|
|
|
|
{
|
|
|
|
return $a;
|
|
|
|
}
|
|
|
|
}'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
|
|
|
}
|
2019-01-20 17:10:12 +01:00
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testOverriddenUse(): void
|
2019-01-20 17:10:12 +01:00
|
|
|
{
|
2019-05-17 00:36:36 +02:00
|
|
|
$this->expectExceptionMessage('ParseError - somefile.php:6');
|
|
|
|
$this->expectException(\Psalm\Exception\CodeException::class);
|
2019-01-20 17:10:12 +01:00
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
namespace Demo;
|
|
|
|
|
|
|
|
use A\B;
|
|
|
|
|
|
|
|
interface B {}'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
|
|
|
}
|
2020-01-04 22:33:02 +01:00
|
|
|
|
2020-01-04 22:35:06 +01:00
|
|
|
public function testBadArray() : void
|
2020-01-04 22:33:02 +01:00
|
|
|
{
|
|
|
|
$this->expectExceptionMessage('ParseError - somefile.php:2');
|
|
|
|
$this->expectException(\Psalm\Exception\CodeException::class);
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
[1,,2];'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', new Context());
|
|
|
|
}
|
2017-02-11 03:27:12 +01:00
|
|
|
}
|