From 8b17ec9aafd3048e4fb69f3a5f47ebf31ef305f5 Mon Sep 17 00:00:00 2001 From: Ryan Chandler Date: Mon, 2 Oct 2023 00:46:04 +0100 Subject: [PATCH] wip --- composer.json | 4 ++- phpunit.xml | 18 ++++++++++++ src/Contracts/Driver.php | 18 ++++++++++++ src/Contracts/Orbital.php | 10 +++++++ src/Drivers/Driver.php | 10 +++++++ src/Drivers/Markdown.php | 29 +++++++++++++++++++ src/OrbitServiceProvider.php | 15 +++++++++- tests/Feature/.gitkeep | 0 tests/Pest.php | 45 +++++++++++++++++++++++++++++ tests/TestCase.php | 10 +++++++ tests/Unit/Drivers/MarkdownTest.php | 31 ++++++++++++++++++++ 11 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 phpunit.xml create mode 100644 src/Contracts/Driver.php create mode 100644 src/Contracts/Orbital.php create mode 100644 src/Drivers/Driver.php create mode 100644 src/Drivers/Markdown.php create mode 100644 tests/Feature/.gitkeep create mode 100644 tests/Pest.php create mode 100644 tests/TestCase.php create mode 100644 tests/Unit/Drivers/MarkdownTest.php diff --git a/composer.json b/composer.json index 0a53cd1..d6b7574 100644 --- a/composer.json +++ b/composer.json @@ -25,10 +25,12 @@ "laravel/scout": "^9.4", "nunomaduro/larastan": "^2.0", "orchestra/testbench": "^8.0", + "pestphp/pest": "^2.20", + "pestphp/pest-plugin-laravel": "^2.2", "phpstan/extension-installer": "^1.1", "phpstan/phpstan-deprecation-rules": "^1.0", "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^10.0" }, "extra": { "laravel": { diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..7d0904f --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,18 @@ + + + + + ./tests + + + + + ./app + ./src + + + diff --git a/src/Contracts/Driver.php b/src/Contracts/Driver.php new file mode 100644 index 0000000..0c5cdc2 --- /dev/null +++ b/src/Contracts/Driver.php @@ -0,0 +1,18 @@ +matter(), + 'content' => trim($document->body()), + ]; + } + + public function compile(array $attributes): string + { + $content = $attributes['content'] ?? null; + + unset($attributes['content']); + + return sprintf("---\n%s\n---\n\n%s", Yaml::dump($attributes), $content); + } +} diff --git a/src/OrbitServiceProvider.php b/src/OrbitServiceProvider.php index 1b9827c..aeea920 100644 --- a/src/OrbitServiceProvider.php +++ b/src/OrbitServiceProvider.php @@ -2,6 +2,8 @@ namespace Orbit; +use Illuminate\Filesystem\Filesystem; +use Spatie\LaravelPackageTools\Commands\InstallCommand; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; @@ -10,6 +12,17 @@ class OrbitServiceProvider extends PackageServiceProvider public function configurePackage(Package $package): void { $package - ->name('orbit'); + ->name('orbit') + ->hasInstallCommand(function (InstallCommand $command) { + $command + ->startWith(function () { + $fs = new Filesystem(); + + $fs->ensureDirectoryExists(base_path('content')); + $fs->ensureDirectoryExists(storage_path('framework/cache/orbit')); + $fs->ensureDirectoryExists(storage_path('framework/cache/orbit/database.sqlite')); + }) + ->askToStarRepoOnGitHub('ryangjchandler/orbit'); + }); } } diff --git a/tests/Feature/.gitkeep b/tests/Feature/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/Pest.php b/tests/Pest.php new file mode 100644 index 0000000..5949c61 --- /dev/null +++ b/tests/Pest.php @@ -0,0 +1,45 @@ +in('Feature'); + +/* +|-------------------------------------------------------------------------- +| Expectations +|-------------------------------------------------------------------------- +| +| When you're writing tests, you often need to check that values meet certain conditions. The +| "expect()" function gives you access to a set of "expectations" methods that you can use +| to assert different things. Of course, you may extend the Expectation API at any time. +| +*/ + +expect()->extend('toBeOne', function () { + return $this->toBe(1); +}); + +/* +|-------------------------------------------------------------------------- +| Functions +|-------------------------------------------------------------------------- +| +| While Pest is very powerful out-of-the-box, you may have some testing code specific to your +| project that you don't want to repeat in every file. Here you can also expose helpers as +| global functions to help you to reduce the number of lines of code in your test files. +| +*/ + +function something() +{ + // .. +} diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..cfb05b6 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,10 @@ +parse($markdown)) + ->toBeArray() + ->toBe([ + 'name' => 'Ryan', + 'categories' => [1, 'foo'], + 'published_at' => 1696032000, + 'is_published' => true, + 'content' => '# Here is the content of the file!', + ]); +});