diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 925a091..d566ecb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,8 @@ jobs: run: composer validate --no-check-all --strict - name: Install Composer dependencies run: composer install --prefer-dist --no-progress - - name: Run tests + - name: Run spec tests run: php vendor/bin/phpspec run + - name: Run unit 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 02397fe..1662739 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,11 @@ "Studio\\": "src" } }, + "autoload-dev": { + "psr-4": { + "StudioTests\\": "tests" + } + }, "require": { "php": ">=8.1", "composer-plugin-api": "^2.3", @@ -18,7 +23,9 @@ }, "require-dev": { "composer/composer": "^2.5", - "phpspec/phpspec": "^7.4" + "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..085e796 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,16 @@ + + + + + + + tests + + + + + + + + + \ No newline at end of file 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..f8f4911 --- /dev/null +++ b/tests/Console/CreateTest.php @@ -0,0 +1,36 @@ +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'; + } +} \ No newline at end of file