Skip to content

Commit

Permalink
Remove tests for partially stubbed classes introduced in vimeo#849, a…
Browse files Browse the repository at this point in the history
…s this didn't work correctly and lead to errors not being reported at all in many cases (since the error was reported for the stubs file and therefore suppressed)

With the previous commit "Fix for classes what vimeo#8503 fixed for functions", the stubs of classes where the actual file is in the analyzed files are ignored completely.
  • Loading branch information
kkmuffme committed Nov 15, 2023
1 parent 04d6d88 commit e2a5bcb
Showing 1 changed file with 4 additions and 92 deletions.
96 changes: 4 additions & 92 deletions tests/StubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,10 @@ public function testPhpStormMetaParsingFile(): void
'<?php
namespace Ns {
class MyClass {
public const OBJECT = "object";
private const EXCEPTION = "exception";
/**
* @return mixed
* @psalm-suppress InvalidReturnType
Expand All @@ -332,7 +332,7 @@ public function create(string $s) {}
* @psalm-suppress InvalidReturnType
*/
public function create2(string $s) {}
/**
* @return mixed
* @psalm-suppress InvalidReturnType
Expand Down Expand Up @@ -384,7 +384,7 @@ function bar(array $a) {}
$y1 = (new \Ns\MyClass)->creAte2("object");
$y2 = (new \Ns\MyClass)->creaTe2("exception");
$const1 = (new \Ns\MyClass)->creAte3(\Ns\MyClass::OBJECT);
$const2 = (new \Ns\MyClass)->creaTe3("exception");
Expand Down Expand Up @@ -1194,94 +1194,6 @@ class Bar extends PartiallyStubbedClass {}
$this->analyzeFile($file_path, new Context());
}

public function testStubFileWithPartialClassDefinitionWithCoercion(): void
{
$this->expectExceptionMessage('TypeCoercion');
$this->expectException(CodeException::class);
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
TestConfig::loadFromXML(
dirname(__DIR__),
'<?xml version="1.0"?>
<psalm
errorLevel="1"
>
<projectFiles>
<directory name="src" />
</projectFiles>
<stubs>
<file name="tests/fixtures/stubs/partial_class.phpstub" />
</stubs>
</psalm>',
),
);

$file_path = getcwd() . '/src/somefile.php';

$this->addFile(
$file_path,
'<?php
namespace Foo;
class PartiallyStubbedClass {
/**
* @param string $a
* @return object
*/
public function foo(string $a) {
return new self;
}
}
(new PartiallyStubbedClass())->foo("dasda");',
);

$this->analyzeFile($file_path, new Context());
}

public function testStubFileWithPartialClassDefinitionGeneralReturnType(): void
{
$this->expectExceptionMessage('InvalidReturnStatement');
$this->expectException(CodeException::class);
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
TestConfig::loadFromXML(
dirname(__DIR__),
'<?xml version="1.0"?>
<psalm
errorLevel="1"
>
<projectFiles>
<directory name="src" />
</projectFiles>
<stubs>
<file name="tests/fixtures/stubs/partial_class.phpstub" />
</stubs>
</psalm>',
),
);

$file_path = getcwd() . '/src/somefile.php';

$this->addFile(
$file_path,
'<?php
namespace Foo;
class PartiallyStubbedClass {
/**
* @param string $a
* @return object
*/
public function foo(string $a) {
return new \stdClass;
}
}',
);

$this->analyzeFile($file_path, new Context());
}

public function testStubFileWithTemplatedClassDefinitionAndMagicMethodOverride(): void
{
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
Expand Down

0 comments on commit e2a5bcb

Please sign in to comment.