Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangjchandler committed Oct 1, 2023
1 parent e6d956a commit 8b17ec9
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 2 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
18 changes: 18 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./app</directory>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
18 changes: 18 additions & 0 deletions src/Contracts/Driver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Orbit\Contracts;

use SplFileInfo;

interface Driver
{
/**
* Use the given file to generate an array of model attributes.
*/
public function parse(string $fileContents): array;

/**
* Use the given array of attributes to generate the contents of a file.
*/
public function compile(array $attributes): string;
}
10 changes: 10 additions & 0 deletions src/Contracts/Orbital.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Orbit\Contracts;

use Illuminate\Database\Schema\Blueprint;

interface Orbital
{
public static function schema(Blueprint $table): void;
}
10 changes: 10 additions & 0 deletions src/Drivers/Driver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Orbit\Drivers;

use Orbit\Contracts\Driver as DriverContract;

abstract class Driver implements DriverContract
{
//
}
29 changes: 29 additions & 0 deletions src/Drivers/Markdown.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Orbit\Drivers;

use Spatie\YamlFrontMatter\YamlFrontMatter;
use SplFileInfo;
use Symfony\Component\Yaml\Yaml;

class Markdown extends Driver
{
public function parse(string $fileContents): array
{
$document = YamlFrontMatter::parse($fileContents);

return [
...$document->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);
}
}
15 changes: 14 additions & 1 deletion src/OrbitServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Orbit;

use Illuminate\Filesystem\Filesystem;
use Spatie\LaravelPackageTools\Commands\InstallCommand;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;

Expand All @@ -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');
});
}
}
Empty file added tests/Feature/.gitkeep
Empty file.
45 changes: 45 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/*
|--------------------------------------------------------------------------
| Test Case
|--------------------------------------------------------------------------
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
| need to change it using the "uses()" function to bind a different classes or traits.
|
*/

// uses(Tests\TestCase::class)->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()
{
// ..
}
10 changes: 10 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Tests;

use PHPUnit\Framework\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
//
}
31 changes: 31 additions & 0 deletions tests/Unit/Drivers/MarkdownTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Orbit\Drivers\Markdown;
use PHPUnit\Framework\TestCase;

uses(TestCase::class);

it('can parse a markdown file into an array of attributes', function () {
$markdown = <<<'MD'
---
name: Ryan
categories: [1, 'foo']
published_at: 2023-09-30 00:00:00
is_published: true
---
# Here is the content of the file!
MD;

$driver = new Markdown();

expect($driver->parse($markdown))
->toBeArray()
->toBe([
'name' => 'Ryan',
'categories' => [1, 'foo'],
'published_at' => 1696032000,
'is_published' => true,
'content' => '# Here is the content of the file!',
]);
});

0 comments on commit 8b17ec9

Please sign in to comment.