-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added ClassType::fromCode() & PhpFile::fromCode() [Closes #79]
- Loading branch information
Showing
13 changed files
with
710 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\PhpGenerator\ClassType; | ||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
$class = ClassType::fromCode(file_get_contents(__DIR__ . '/fixtures/classes.php')); | ||
Assert::type(ClassType::class, $class); | ||
Assert::match(<<<'XX' | ||
/** | ||
* Interface | ||
* @author John Doe | ||
*/ | ||
interface Interface1 | ||
{ | ||
function func1(); | ||
} | ||
XX | ||
, (string) $class); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\PhpGenerator\Factory & code | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\PhpGenerator\Factory; | ||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
$factory = new Factory; | ||
|
||
$class = $factory->fromClassCode(file_get_contents(__DIR__ . '/fixtures/classes.php')); | ||
Assert::type(Nette\PhpGenerator\ClassType::class, $class); | ||
Assert::match(<<<'XX' | ||
/** | ||
* Interface | ||
* @author John Doe | ||
*/ | ||
interface Interface1 | ||
{ | ||
function func1(); | ||
} | ||
XX | ||
, (string) $class); | ||
|
||
|
||
$file = $factory->fromCode(file_get_contents(__DIR__ . '/fixtures/classes.php')); | ||
Assert::type(Nette\PhpGenerator\PhpFile::class, $file); | ||
sameFile(__DIR__ . '/expected/Factory.fromCode.expect', (string) $file); | ||
|
||
$file = $factory->fromCode(file_get_contents(__DIR__ . '/fixtures/classes.74.php')); | ||
sameFile(__DIR__ . '/expected/Factory.fromCode.74.expect', (string) $file); | ||
|
||
$file = $factory->fromCode(file_get_contents(__DIR__ . '/fixtures/classes.80.php')); | ||
sameFile(__DIR__ . '/expected/Factory.fromCode.80.expect', (string) $file); | ||
|
||
//$file = $factory->fromCode(file_get_contents(__DIR__ . '/fixtures/classes.81.php')); | ||
//sameFile(__DIR__ . '/expected/Factory.fromCode.81.expect', (string) $file); | ||
|
||
$file = $factory->fromCode(file_get_contents(__DIR__ . '/fixtures/enum.php')); | ||
sameFile(__DIR__ . '/expected/Factory.fromCode.enum.expect', (string) $file); | ||
|
||
$file = $factory->fromCode(file_get_contents(__DIR__ . '/fixtures/traits.php')); | ||
sameFile(__DIR__ . '/expected/Factory.fromCode.traits.expect', (string) $file); | ||
|
||
$file = $factory->fromCode(file_get_contents(__DIR__ . '/fixtures/bodies.php')); | ||
sameFile(__DIR__ . '/expected/Factory.fromCode.bodies.expect', (string) $file); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Abc; | ||
|
||
class Class7 | ||
{ | ||
public \A $a; | ||
public ?\B $b; | ||
public ?\C $c = null; | ||
public ?int $i = 1; | ||
} |
Oops, something went wrong.