-
-
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
13 changed files
with
216 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
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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit bootstrap = "vendor/autoload.php" colors = "true"> | ||
|
||
<testsuites> | ||
<testsuite name="Project Test Suite"> | ||
<directory>tests</directory> | ||
<exclude>tests/**/stubs</exclude> | ||
</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,69 @@ | ||
<?php | ||
|
||
namespace StudioTests\Console; | ||
|
||
use org\bovigo\vfs\vfsStream; | ||
use org\bovigo\vfs\visitor\vfsStreamStructureVisitor; | ||
|
||
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', | ||
// set up PhpUnit | ||
'yes', | ||
// set up PhpSpec | ||
'yes', | ||
// set up TravisCI | ||
'yes' | ||
] | ||
); | ||
|
||
$this->assertEquals( | ||
self::getStructure(), | ||
vfsStream::inspect(new vfsStreamStructureVisitor())->getStructure() | ||
); | ||
} | ||
|
||
protected function getCommandFqcn(): string | ||
{ | ||
return 'create'; | ||
} | ||
|
||
protected static function getStructure(): array | ||
{ | ||
return [ | ||
'root' => [ | ||
'company' => [ | ||
'my-package' => [ | ||
'spec' => [], | ||
'src' => [ | ||
'Example.php' => file_get_contents(__DIR__ . '/stubs/company/my-package/src/Example.php'), | ||
], | ||
'tests' => [ | ||
'ExampleTest.php' => file_get_contents(__DIR__ . '/stubs/company/my-package/tests/ExampleTest.php'), | ||
], | ||
'.gitignore' => file_get_contents(__DIR__ . '/stubs/company/my-package/.gitignore'), | ||
'.travis.yml' => file_get_contents(__DIR__ . '/stubs/company/my-package/.travis.yml'), | ||
'composer.json' => file_get_contents(__DIR__ . '/stubs/company/my-package/composer.json'), | ||
'phpspec.yml' => file_get_contents(__DIR__ . '/stubs/company/my-package/phpspec.yml'), | ||
'phpunit.xml' => file_get_contents(__DIR__ . '/stubs/company/my-package/phpunit.xml'), | ||
], | ||
], | ||
], | ||
]; | ||
} | ||
} |
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,3 @@ | ||
composer.phar | ||
composer.lock | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
language: php | ||
|
||
php: | ||
- 5.5 | ||
- 5.6 | ||
- 7.0 | ||
- hhvm | ||
|
||
before_script: | ||
- travis_retry composer self-update | ||
- travis_retry composer install --prefer-source --no-interaction --dev | ||
|
||
script: 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,17 @@ | ||
{ | ||
"name": "company/my-package", | ||
"autoload": { | ||
"psr-4": { | ||
"Company\\MyPackage\\": "src/" | ||
} | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9.6 || ^10", | ||
"phpspec/phpspec": "^7.4" | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Company\\MyPackage\\Tests\\": "tests/" | ||
} | ||
} | ||
} |
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,4 @@ | ||
suites: | ||
library_suite: | ||
namespace: Company\MyPackage\Tests | ||
psr4_prefix: Company\MyPackage\Tests |
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,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
verbose="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Package Test Suite"> | ||
<directory suffix=".php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</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,8 @@ | ||
<?php | ||
|
||
namespace Company\MyPackage; | ||
|
||
class Example | ||
{ | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
tests/Console/stubs/company/my-package/tests/ExampleTest.php
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,10 @@ | ||
<?php | ||
|
||
namespace Company\MyPackage\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class ExampleTest extends TestCase | ||
{ | ||
|
||
} |