1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Refactor include tests to allow checking multiple files per test cc @ernunion

This commit is contained in:
Matthew Brown 2017-06-01 23:16:45 -04:00
parent fa4678912f
commit e99150b403

View File

@ -8,25 +8,29 @@ class IncludeTest extends TestCase
/**
* @dataProvider providerTestValidIncludes
*
* @param string $file
* @param string $code
* @param array $files_to_check
* @param array $files
* @param array<string,string> $includes
*
* @return void
*/
public function testBasicRequire($file, $code, $includes = [])
public function testBasicRequire(array $files, array $files_to_check)
{
foreach ($includes as $filename => $contents) {
foreach ($files as $filename => $contents) {
$this->project_checker->registerFile($filename, $contents);
}
$file_checker = new FileChecker(
$file,
$this->project_checker,
self::$parser->parse($code)
);
foreach ($files_to_check as $filename) {
$contents = $files[$filename];
$file_checker->visitAndAnalyzeMethods();
$file_checker = new FileChecker(
$filename,
$this->project_checker,
self::$parser->parse($contents)
);
$file_checker->visitAndAnalyzeMethods();
}
}
/**
@ -36,94 +40,103 @@ class IncludeTest extends TestCase
{
return [
'basicRequire' => [
'file' => getcwd() . DIRECTORY_SEPARATOR . 'file2.php',
'code' => '<?php
require("file1.php");
class B {
public function foo() : void {
(new A);
}
}',
'includes' => [
getcwd() . DIRECTORY_SEPARATOR . 'file1.php' => '<?php
class A{
'files' => [
getcwd() . DIRECTORY_SEPARATOR . 'file2.php' => '<?php
require("file1.php");
class B {
public function foo() : void {
(new A);
}
}',
getcwd() . DIRECTORY_SEPARATOR . 'file1.php' => '<?php
class A{}',
],
'files_to_check' => [
getcwd() . DIRECTORY_SEPARATOR . 'file2.php'
],
],
'nestedRequire' => [
'file' => getcwd() . DIRECTORY_SEPARATOR . 'file3.php',
'code' => '<?php
require("file2.php");
class C extends B {
public function doFoo() : void {
$this->fooFoo();
}
}',
'includes' => [
'files' => [
getcwd() . DIRECTORY_SEPARATOR . 'file1.php' => '<?php
class A{
public function fooFoo() : void {
}
}',
getcwd() . DIRECTORY_SEPARATOR . 'file2.php' => '<?php
require("file1.php");
class B extends A{
}',
getcwd() . DIRECTORY_SEPARATOR . 'file3.php' => '<?php
require("file2.php");
class C extends B {
public function doFoo() : void {
$this->fooFoo();
}
}',
],
'files_to_check' => [
getcwd() . DIRECTORY_SEPARATOR . 'file3.php'
],
],
'requireNamespace' => [
'file' => getcwd() . DIRECTORY_SEPARATOR . 'file2.php',
'code' => '<?php
require("file1.php");
class B {
public function foo() : void {
(new Foo\A);
}
}',
'includes' => [
'files' => [
getcwd() . DIRECTORY_SEPARATOR . 'file1.php' => '<?php
namespace Foo;
class A{
}',
getcwd() . DIRECTORY_SEPARATOR . 'file2.php' => '<?php
require("file1.php");
class B {
public function foo() : void {
(new Foo\A);
}
}',
],
'files_to_check' => [
getcwd() . DIRECTORY_SEPARATOR . 'file2.php'
],
],
'requireFunction' => [
'file' => getcwd() . DIRECTORY_SEPARATOR . 'file2.php',
'code' => '<?php
require("file1.php");
fooFoo();',
'includes' => [
'files' => [
getcwd() . DIRECTORY_SEPARATOR . 'file1.php' => '<?php
function fooFoo() : void {
}',
getcwd() . DIRECTORY_SEPARATOR . 'file2.php' => '<?php
require("file1.php");
fooFoo();',
],
'files_to_check' => [
getcwd() . DIRECTORY_SEPARATOR . 'file2.php'
],
],
'requireNamespacedWithUse' => [
'file' => getcwd() . DIRECTORY_SEPARATOR . 'file2.php',
'code' => '<?php
require("file1.php");
use Foo\A;
class B {
public function foo() : void {
(new A);
}
}',
'includes' => [
'files' => [
getcwd() . DIRECTORY_SEPARATOR . 'file1.php' => '<?php
namespace Foo;
class A{
}',
getcwd() . DIRECTORY_SEPARATOR . 'file2.php' => '<?php
require("file1.php");
use Foo\A;
class B {
public function foo() : void {
(new A);
}
}',
],
'files_to_check' => [
getcwd() . DIRECTORY_SEPARATOR . 'file2.php'
],
],
];