diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 3c564d0..981318e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
- php: [7.2, 7.3, 7.4, 8.0, 8.1]
+ php: [8.1, 8.2]
steps:
- uses: actions/checkout@v1
- uses: shivammathur/setup-php@v2
@@ -19,4 +19,20 @@ jobs:
run: composer install --prefer-dist --no-progress
- name: Run tests
run: php vendor/bin/phpspec run
+ phpunit:
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ php: [8.1, 8.2]
+ steps:
+ - uses: actions/checkout@v1
+ - uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php }}
+ - name: Validate Composer files
+ run: composer validate --no-check-all --strict
+ - name: Install Composer dependencies
+ run: composer install --prefer-dist --no-progress
+ - name: Run tests
+ run: php vendor/bin/phpunit
diff --git a/.gitignore b/.gitignore
index aa0f446..e73553f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
+.phpunit.result.cache
studio.json
composer.phar
composer.lock
-vendor/
+vendor/
\ No newline at end of file
diff --git a/composer.json b/composer.json
index 3ac6eab..1662739 100644
--- a/composer.json
+++ b/composer.json
@@ -9,16 +9,23 @@
"Studio\\": "src"
}
},
+ "autoload-dev": {
+ "psr-4": {
+ "StudioTests\\": "tests"
+ }
+ },
"require": {
- "php": ">=7.0",
- "composer-plugin-api": "^1.0 || ^2.0",
- "symfony/console": "^2.7 || ^3.0 || ^4.0 || ^5.0 || ^6.0",
- "symfony/filesystem": "^2.5 || ^3.0 || ^4.0 || ^5.0 || ^6.0",
- "symfony/process": "^2.5 || ^3.0 || ^4.0 || ^5.0 || ^6.0"
+ "php": ">=8.1",
+ "composer-plugin-api": "^2.3",
+ "symfony/console": "^6.2",
+ "symfony/filesystem": "^6.2",
+ "symfony/process": "^6.2"
},
"require-dev": {
- "composer/composer": "^2.4.2",
- "phpspec/phpspec": "^6.3 || ^7.0"
+ "composer/composer": "^2.5",
+ "phpspec/phpspec": "^7.4",
+ "phpunit/phpunit": "^9.6 | ^10",
+ "mikey179/vfsstream": "^1.6.11"
},
"replace": {
"franzliedke/studio": "self.version"
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
new file mode 100644
index 0000000..8092340
--- /dev/null
+++ b/phpunit.xml.dist
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+ tests
+ tests/**/stubs
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Creator/SkeletonCreator.php b/src/Creator/SkeletonCreator.php
index 43d0e1b..d531fe1 100644
--- a/src/Creator/SkeletonCreator.php
+++ b/src/Creator/SkeletonCreator.php
@@ -49,7 +49,7 @@ public function create()
protected function installParts()
{
- $config = new \stdClass();
+ $config = (object)[];
foreach ($this->parts as $part) {
$part->setupPackage($config, $this->directory);
diff --git a/src/Parts/Composer/Part.php b/src/Parts/Composer/Part.php
index efc7a75..126ad83 100644
--- a/src/Parts/Composer/Part.php
+++ b/src/Parts/Composer/Part.php
@@ -27,7 +27,7 @@ public function setupPackage($composer, Directory $target)
// Normalize and store the namespace
$namespace = str_replace('/', '\\', $namespace);
$namespace = rtrim($namespace, '\\');
- @$composer->autoload->{'psr-4'}->{"$namespace\\"} = 'src/';
+ $composer->autoload = (object)['psr-4' => (object)["$namespace\\" => 'src/']];
// Create an example file
$this->copyTo(
diff --git a/src/Parts/PhpSpec/Part.php b/src/Parts/PhpSpec/Part.php
index ed92c55..73a99d9 100644
--- a/src/Parts/PhpSpec/Part.php
+++ b/src/Parts/PhpSpec/Part.php
@@ -10,7 +10,7 @@ class Part extends AbstractPart
public function setupPackage($composer, Directory $target)
{
if ($this->input->confirm('Do you want to set up PhpSpec as a testing tool?')) {
- $composer->{'require-dev'}['phpspec/phpspec'] = '^4.0';
+ $composer->{'require-dev'}['phpspec/phpspec'] = '^7.4';
$psr4Autoloading = (array) $composer->autoload->{'psr-4'};
$namespace = key($psr4Autoloading).'Tests';
diff --git a/src/Parts/PhpUnit/Part.php b/src/Parts/PhpUnit/Part.php
index ab5185c..9a11037 100644
--- a/src/Parts/PhpUnit/Part.php
+++ b/src/Parts/PhpUnit/Part.php
@@ -10,13 +10,13 @@ class Part extends AbstractPart
public function setupPackage($composer, Directory $target)
{
if ($this->input->confirm('Do you want to set up PhpUnit as a testing tool?')) {
- $composer->{'require-dev'}['phpunit/phpunit'] = '^6.3';
+ $composer->{'require-dev'}['phpunit/phpunit'] = '^9.6 || ^10';
// Add autoloading rules for tests
$psr4Autoloading = (array) $composer->autoload->{'psr-4'};
$namespace = key($psr4Autoloading).'Tests';
- @$composer->{'autoload-dev'}->{'psr-4'}->{"$namespace\\"} = 'tests/';
+ $composer->{'autoload-dev'} = (object)['psr-4' => (object)["$namespace\\" => 'tests/']];
// Create an example test file
$this->copyTo(
diff --git a/tests/Console/AbstractConsoleTest.php b/tests/Console/AbstractConsoleTest.php
new file mode 100644
index 0000000..ad5b581
--- /dev/null
+++ b/tests/Console/AbstractConsoleTest.php
@@ -0,0 +1,30 @@
+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;
+}
\ No newline at end of file
diff --git a/tests/Console/CreateTest.php b/tests/Console/CreateTest.php
new file mode 100644
index 0000000..b4e27e7
--- /dev/null
+++ b/tests/Console/CreateTest.php
@@ -0,0 +1,69 @@
+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'),
+ ],
+ ],
+ ],
+ ];
+ }
+}
\ No newline at end of file
diff --git a/tests/Console/stubs/company/my-package/.gitignore b/tests/Console/stubs/company/my-package/.gitignore
new file mode 100644
index 0000000..7a8a0ad
--- /dev/null
+++ b/tests/Console/stubs/company/my-package/.gitignore
@@ -0,0 +1,3 @@
+composer.phar
+composer.lock
+vendor
diff --git a/tests/Console/stubs/company/my-package/.travis.yml b/tests/Console/stubs/company/my-package/.travis.yml
new file mode 100644
index 0000000..ac80f2d
--- /dev/null
+++ b/tests/Console/stubs/company/my-package/.travis.yml
@@ -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
diff --git a/tests/Console/stubs/company/my-package/composer.json b/tests/Console/stubs/company/my-package/composer.json
new file mode 100644
index 0000000..1498c2c
--- /dev/null
+++ b/tests/Console/stubs/company/my-package/composer.json
@@ -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/"
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/Console/stubs/company/my-package/phpspec.yml b/tests/Console/stubs/company/my-package/phpspec.yml
new file mode 100644
index 0000000..12410d7
--- /dev/null
+++ b/tests/Console/stubs/company/my-package/phpspec.yml
@@ -0,0 +1,4 @@
+suites:
+ library_suite:
+ namespace: Company\MyPackage\Tests
+ psr4_prefix: Company\MyPackage\Tests
diff --git a/tests/Console/stubs/company/my-package/phpunit.xml b/tests/Console/stubs/company/my-package/phpunit.xml
new file mode 100644
index 0000000..b423a7e
--- /dev/null
+++ b/tests/Console/stubs/company/my-package/phpunit.xml
@@ -0,0 +1,19 @@
+
+
+
+
+ ./tests/
+
+
+
diff --git a/tests/Console/stubs/company/my-package/src/Example.php b/tests/Console/stubs/company/my-package/src/Example.php
new file mode 100644
index 0000000..6204aeb
--- /dev/null
+++ b/tests/Console/stubs/company/my-package/src/Example.php
@@ -0,0 +1,8 @@
+