-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
95 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.phpunit.result.cache | ||
studio.json | ||
composer.phar | ||
composer.lock | ||
vendor/ | ||
vendor/ |
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,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit bootstrap = "vendor/autoload.php" colors = "true"> | ||
|
||
<testsuites> | ||
<testsuite name="Project Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<php> | ||
<env name="APP_ENV" value="testing"/> | ||
<env name="APP_VERSION" value="0.15.0"/> | ||
</php> | ||
|
||
</phpunit> |
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,30 @@ | ||
<?php | ||
|
||
namespace StudioTests\Console; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Studio\Console\CreateCommand; | ||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
abstract class AbstractConsoleTest extends TestCase | ||
{ | ||
protected function executeCommand(array $arguments, array $inputs = []): CommandTester | ||
{ | ||
$application = new Application('studio', getenv('APP_VERSION')); | ||
$application->add(new CreateCommand); | ||
|
||
// this uses a special testing container that allows you to fetch private services | ||
/** @var Command $command */ | ||
$command = $application->get($this->getCommandFqcn()); | ||
|
||
$commandTester = new CommandTester($command); | ||
$commandTester->setInputs($inputs); | ||
$commandTester->execute($arguments); | ||
|
||
return $commandTester; | ||
} | ||
|
||
abstract protected function getCommandFqcn(): string; | ||
} |
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,36 @@ | ||
<?php | ||
|
||
namespace StudioTests\Console; | ||
|
||
use org\bovigo\vfs\vfsStream; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
class CreateTest extends AbstractConsoleTest | ||
{ | ||
private $root; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->root = vfsStream::setup(); | ||
} | ||
|
||
function testExecute(): void | ||
{ | ||
$commandTester = $this->executeCommand( | ||
['path' => $this->root->url() . '/company/my-package'], | ||
[ | ||
// package name | ||
'company/my-package', | ||
// default namespace (psr-4) | ||
'Company/MyPackage', | ||
] | ||
); | ||
|
||
$this->assertTrue($this->root->hasChild('company/my-package')); | ||
} | ||
|
||
protected function getCommandFqcn(): string | ||
{ | ||
return 'create'; | ||
} | ||
} |