-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Atomize namespace processing; Install full Sylius library to use as c…
…andidates.
- Loading branch information
Showing
8 changed files
with
154 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
# transunit | ||
Transunit | ||
=== | ||
|
||
Convert PhpSpec tests to PHPUnit | ||
|
||
Dependencies | ||
--- | ||
|
||
- nikic/php-parser | ||
- symfony/finder | ||
- symfony/filesystem |
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,48 @@ | ||
<?php | ||
|
||
namespace Transunit\Pass; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Name; | ||
use PhpParser\Node\Stmt\Namespace_; | ||
use PhpParser\NodeFinder; | ||
use Transunit\Pass; | ||
|
||
/** | ||
* ``` | ||
* + use Prophecy\Prophecy\ObjectProphecy; | ||
* + use Prophecy\PhpUnit\ProphecyTrait; | ||
* + use PHPUnit\Framework\TestCase; | ||
* ``` | ||
*/ | ||
class ImportMockingLibraryPass implements Pass | ||
{ | ||
public function find(NodeFinder $nodeFinder, $ast): array | ||
{ | ||
return [$nodeFinder->findFirstInstanceOf($ast, Namespace_::class)]; | ||
} | ||
|
||
public function rewrite(Node $node): void | ||
{ | ||
if (!$node instanceof Namespace_) { | ||
return; | ||
} | ||
|
||
$this->importMockingLibraryClasses($node); | ||
} | ||
|
||
private function importMockingLibraryClasses(Namespace_ $node): void | ||
{ | ||
array_unshift($node->stmts, new Node\Stmt\Use_([ | ||
new Node\Stmt\UseUse(new Name('Prophecy\Prophecy\ObjectProphecy')), | ||
])); | ||
|
||
array_unshift($node->stmts, new Node\Stmt\Use_([ | ||
new Node\Stmt\UseUse(new Name('Prophecy\PhpUnit\ProphecyTrait')), | ||
])); | ||
|
||
array_unshift($node->stmts, new Node\Stmt\Use_([ | ||
new Node\Stmt\UseUse(new Name('PHPUnit\Framework\TestCase')), | ||
])); | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
namespace Transunit\Pass; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Name; | ||
use PhpParser\Node\Stmt\Namespace_; | ||
use PhpParser\NodeFinder; | ||
use Transunit\Pass; | ||
|
||
/** | ||
* ``` | ||
* - namespace spec\Foo\Bar; | ||
* + namespace tests\unit\Foo\Bar; | ||
* ``` | ||
*/ | ||
class MoveNamespacePass implements Pass | ||
{ | ||
public function find(NodeFinder $nodeFinder, $ast): array | ||
{ | ||
return [$nodeFinder->findFirstInstanceOf($ast, Namespace_::class)]; | ||
} | ||
|
||
public function rewrite(Node $node): void | ||
{ | ||
if (!$node instanceof Namespace_) { | ||
return; | ||
} | ||
|
||
$this->moveToNamespace($node); | ||
} | ||
|
||
private function moveToNamespace(Namespace_ $node): void | ||
{ | ||
$ns = $node->name->getParts(); | ||
|
||
if ($ns[0] === 'spec') { | ||
array_shift($ns); | ||
$ns = array_merge(['tests', 'unit'], $ns); | ||
} | ||
|
||
$node->name = new Name($ns); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -4,5 +4,6 @@ | |
|
||
$args = $argv; | ||
array_shift($args); | ||
$args[0] = getcwd().'/'.$args[0]; | ||
|
||
\Transunit\Transunit::run(...$args); |