Skip to content

Commit

Permalink
Added some more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm committed Mar 21, 2020
1 parent eb8ec4c commit 7506b52
Show file tree
Hide file tree
Showing 34 changed files with 725 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tests/Fixer/Preload/ExplicitlyLoadClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ public function provideFixCases()

/** @var SplFileInfo $file */
foreach ($finder as $file) {
$path = $file->getRealPath();
$output = file_get_contents($path);
$output = file_get_contents($file->getRealPath());

$input = null;
$inputFile = substr($path, 0, -7).'In.php';
if (is_file($inputFile)) {
$input = file_get_contents($inputFile);
$inputFilePattern = substr($file->getFilename(), 0, -7).'In*.php';
$inputFinder = new Finder();
$inputFinder->in($testDir)->name($inputFilePattern);

/** @var SplFileInfo $file */
foreach ($inputFinder as $input) {
yield sprintf('%s => %s', $input->getFilename(), $file->getFilename()) => [$output, file_get_contents($input->getRealPath())];
}

yield $file->getFilename() => [$output, $input];
yield $file->getFilename() => [$output, null];
}
}
}
15 changes: 15 additions & 0 deletions tests/Fixtures/Preload/Case003_In.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

use App\Foo;

/**
* Constructor with new Foo()
*/
class Case003
{
private $foo;
public function __construct()
{
$this->foo = new Foo();
}
}
16 changes: 16 additions & 0 deletions tests/Fixtures/Preload/Case003_Out.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use App\Foo;

class_exists(Foo::class);
/**
* Constructor with new Foo()
*/
class Case003
{
private $foo;
public function __construct()
{
$this->foo = new Foo();
}
}
15 changes: 15 additions & 0 deletions tests/Fixtures/Preload/Case004_In.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

use App\Foo;

/**
* Constructor with class reference
*/
class Case004
{
private $foo;
public function __construct()
{
$this->foo = Foo::class;
}
}
16 changes: 16 additions & 0 deletions tests/Fixtures/Preload/Case004_Out.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use App\Foo;

class_exists(Foo::class);
/**
* Constructor with class reference
*/
class Case004
{
private $foo;
public function __construct()
{
$this->foo = Foo::class;
}
}
21 changes: 21 additions & 0 deletions tests/Fixtures/Preload/Case005_In.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use App\Foo;

/**
* Constructor using more complex class references
*/
class Case005
{
private $baz;
private $bazClass;
private $bar;
private $barClass;
public function __construct()
{
$this->bar = new Foo\Bar();
$this->barClass = Foo\BarClass::class;
$this->baz = new \Biz\Baz();
$this->bazClass = \Biz\BazClass::class;
}
}
25 changes: 25 additions & 0 deletions tests/Fixtures/Preload/Case005_Out.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use App\Foo;

class_exists(Foo\Bar::class);
class_exists(Foo\BarClass::class);
class_exists(\Biz\Baz::class);
class_exists(\Biz\BazClass::class);
/**
* Constructor using more complex class references
*/
class Case005
{
private $baz;
private $bazClass;
private $bar;
private $barClass;
public function __construct()
{
$this->bar = new Foo\Bar();
$this->barClass = Foo\BarClass::class;
$this->baz = new \Biz\Baz();
$this->bazClass = \Biz\BazClass::class;
}
}
22 changes: 22 additions & 0 deletions tests/Fixtures/Preload/Case006_In.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use App\Foo;

/**
* Constructor call to private method
*/
class Case006
{
private $foo;
private $bar;
public function __construct()
{
$this->bar = 2;
$this->init();
}

private function init()
{
$this->foo = new Foo();
}
}
23 changes: 23 additions & 0 deletions tests/Fixtures/Preload/Case006_Out.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use App\Foo;

class_exists(Foo::class);
/**
* Constructor call to private method
*/
class Case006
{
private $foo;
private $bar;
public function __construct()
{
$this->bar = 2;
$this->init();
}

private function init()
{
$this->foo = new Foo();
}
}
22 changes: 22 additions & 0 deletions tests/Fixtures/Preload/Case007_In.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use App\Foo;

/**
* Constructor call to public method
*/
class Case007
{
private $foo;
private $bar;
public function __construct()
{
$this->bar = 2;
$this->init();
}

public function init()
{
$this->foo = new Foo();
}
}
23 changes: 23 additions & 0 deletions tests/Fixtures/Preload/Case007_Out.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use App\Foo;

class_exists(Foo::class);
/**
* Constructor call to public method
*/
class Case007
{
private $foo;
private $bar;
public function __construct()
{
$this->bar = 2;
$this->init();
}

public function init()
{
$this->foo = new Foo();
}
}
23 changes: 23 additions & 0 deletions tests/Fixtures/Preload/Case008_In.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use App\Foo;

/**
* Constructor call to private method with parameter
*/
class Case008
{
private $foo;
private $bar;
public function __construct()
{
$this->bar = 2;
$var = new Foo();
$this->init($var);
}

private function init(Foo $foo)
{
$this->foo = $foo;
}
}
24 changes: 24 additions & 0 deletions tests/Fixtures/Preload/Case008_Out.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use App\Foo;

class_exists(Foo::class);
/**
* Constructor call to private method with parameter
*/
class Case008
{
private $foo;
private $bar;
public function __construct()
{
$this->bar = 2;
$var = new Foo();
$this->init($var);
}

private function init(Foo $foo)
{
$this->foo = $foo;
}
}
23 changes: 23 additions & 0 deletions tests/Fixtures/Preload/Case009_Out.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use App\Foo;

/**
* Constructor call to public method with parameter
*/
class Case009
{
private $foo;
private $bar;
public function __construct()
{
$this->bar = 2;
$var = new Foo();
$this->init($var);
}

public function init(Foo $foo)
{
$this->foo = $foo;
}
}
26 changes: 26 additions & 0 deletions tests/Fixtures/Preload/Case010_In.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use App\Foo;

/**
* Constructor using more complex class references
*/
class Case010
{
private $baz;
private $bazClass;
private $bar;
private $barClass;
public function __construct()
{
$this->init();
}

private function init()
{
$this->bar = new Foo\Bar();
$this->barClass = Foo\BarClass::class;
$this->baz = new \Biz\Baz();
$this->bazClass = \Biz\BazClass::class;
}
}
30 changes: 30 additions & 0 deletions tests/Fixtures/Preload/Case010_Out.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use App\Foo;

class_exists(Foo\Bar::class);
class_exists(Foo\BarClass::class);
class_exists(\Biz\Baz::class);
class_exists(\Biz\BazClass::class);
/**
* Constructor using more complex class references
*/
class Case010
{
private $baz;
private $bazClass;
private $bar;
private $barClass;
public function __construct()
{
$this->init();
}

private function init()
{
$this->bar = new Foo\Bar();
$this->barClass = Foo\BarClass::class;
$this->baz = new \Biz\Baz();
$this->bazClass = \Biz\BazClass::class;
}
}
19 changes: 19 additions & 0 deletions tests/Fixtures/Preload/Case011_In.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* Return types of public functions
*/
class Case011
{
private $foo;
public function __construct()
{
$this->init();
}

public function init(): Foo
{
$bar = new Bar();
return $bar->createFoo();
}
}

0 comments on commit 7506b52

Please sign in to comment.