Skip to content

Commit

Permalink
bind commonmark as singleton (#51)
Browse files Browse the repository at this point in the history
* bin commonmark as singleton

* use simple singleton binding
  • Loading branch information
Gummibeer committed Mar 24, 2020
1 parent 81f0191 commit cc77c1d
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 30 deletions.
15 changes: 4 additions & 11 deletions src/SheetsServiceProvider.php
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\ServiceProvider;
use League\CommonMark\CommonMarkConverter;
use League\CommonMark\ConverterInterface;
use Spatie\Sheets\ContentParsers\MarkdownParser;
use Spatie\Sheets\ContentParsers\MarkdownWithFrontMatterParser;
use Spatie\Sheets\PathParsers\SlugParser;
Expand All @@ -30,17 +31,9 @@ public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/sheets.php', 'sheets');

$this->app->when(MarkdownWithFrontMatterParser::class)
->needs(CommonMarkConverter::class)
->give(function () {
return new CommonMarkConverter();
});

$this->app->when(MarkdownParser::class)
->needs(CommonMarkConverter::class)
->give(function () {
return new CommonMarkConverter();
});
if (! $this->app->bound(ConverterInterface::class)) {
$this->app->singleton(ConverterInterface::class, CommonMarkConverter::class);
}

$this->app->singleton(Sheets::class, function () {
$sheets = new Sheets();
Expand Down
4 changes: 2 additions & 2 deletions tests/ContentParsers/JsonParserTest.php
Expand Up @@ -2,15 +2,15 @@

namespace Spatie\Sheets\Tests\ContentParsers;

use PHPUnit\Framework\TestCase;
use Spatie\Sheets\Tests\TestCase;
use Spatie\Sheets\ContentParsers\JsonParser;

class JsonParserTest extends TestCase
{
/** @test */
public function it_converts_a_front_matter_document_to_attributes()
{
$jsonParser = new JsonParser();
$jsonParser = $this->app->make(JsonParser::class);

$expected = [
'title' => 'Hello, world!',
Expand Down
7 changes: 2 additions & 5 deletions tests/ContentParsers/MarkdownParserTest.php
Expand Up @@ -2,18 +2,15 @@

namespace Spatie\Sheets\Tests\ContentParsers;

use League\CommonMark\CommonMarkConverter;
use PHPUnit\Framework\TestCase;
use Spatie\Sheets\Tests\TestCase;
use Spatie\Sheets\ContentParsers\MarkdownParser;

class MarkdownParserTest extends TestCase
{
/** @test */
public function it_converts_a_front_matter_document_to_attributes()
{
$markdownParser = new MarkdownParser(
new CommonMarkConverter()
);
$markdownParser = $this->app->make(MarkdownParser::class);

$contents = '# Hello, world!';

Expand Down
6 changes: 2 additions & 4 deletions tests/ContentParsers/MarkdownWithFrontMatterParserTest.php
Expand Up @@ -3,17 +3,15 @@
namespace Spatie\Sheets\Tests\ContentParsers;

use League\CommonMark\CommonMarkConverter;
use PHPUnit\Framework\TestCase;
use Spatie\Sheets\Tests\TestCase;
use Spatie\Sheets\ContentParsers\MarkdownWithFrontMatterParser;

class MarkdownWithFrontMatterParserTest extends TestCase
{
/** @test */
public function it_converts_a_front_matter_document_to_attributes()
{
$markdownWithFrontMatterParser = new MarkdownWithFrontMatterParser(
new CommonMarkConverter()
);
$markdownWithFrontMatterParser = $this->app->make(MarkdownWithFrontMatterParser::class);

$contents = implode("\n", [
'---',
Expand Down
4 changes: 2 additions & 2 deletions tests/ContentParsers/YamlParserTest.php
Expand Up @@ -2,15 +2,15 @@

namespace Spatie\Sheets\Tests\ContentParsers;

use PHPUnit\Framework\TestCase;
use Spatie\Sheets\Tests\TestCase;
use Spatie\Sheets\ContentParsers\YamlParser;

class YamlParserTest extends TestCase
{
/** @test */
public function it_converts_a_front_matter_document_to_attributes()
{
$yamlParser = new YamlParser();
$yamlParser = $this->app->make(YamlParser::class);

$contents = implode("\n", [
'title: Hello, world!',
Expand Down
2 changes: 1 addition & 1 deletion tests/FactoryTest.php
Expand Up @@ -3,7 +3,7 @@
namespace Spatie\Sheets\Tests;

use League\CommonMark\CommonMarkConverter;
use PHPUnit\Framework\TestCase;
use Spatie\Sheets\Tests\TestCase;
use Spatie\Sheets\ContentParsers\MarkdownWithFrontMatterParser;
use Spatie\Sheets\Factory;
use Spatie\Sheets\PathParsers\SlugParser;
Expand Down
2 changes: 1 addition & 1 deletion tests/PathParsers/SlugParserTest.php
Expand Up @@ -2,7 +2,7 @@

namespace Spatie\Sheets\Tests\PathParsers;

use PHPUnit\Framework\TestCase;
use Spatie\Sheets\Tests\TestCase;
use Spatie\Sheets\PathParsers\SlugParser;

class SlugParserTest extends TestCase
Expand Down
2 changes: 1 addition & 1 deletion tests/PathParsers/SlugWithDateParserTest.php
Expand Up @@ -3,7 +3,7 @@
namespace Spatie\Sheets\Tests\PathParsers;

use Illuminate\Support\Carbon;
use PHPUnit\Framework\TestCase;
use Spatie\Sheets\Tests\TestCase;
use Spatie\Sheets\PathParsers\SlugWithDateParser;

class SlugWithDateParserTest extends TestCase
Expand Down
2 changes: 1 addition & 1 deletion tests/PathParsers/SlugWithOrderParserTest.php
Expand Up @@ -2,7 +2,7 @@

namespace Spatie\Sheets\Tests\PathParsers;

use PHPUnit\Framework\TestCase;
use Spatie\Sheets\Tests\TestCase;
use Spatie\Sheets\PathParsers\SlugWithOrderParser;

class SlugWithOrderParserTest extends TestCase
Expand Down
2 changes: 1 addition & 1 deletion tests/Repositories/FilesystemRepositoryTest.php
Expand Up @@ -3,7 +3,7 @@
namespace Spatie\Sheets\Tests\Repositories;

use Illuminate\Support\Collection;
use PHPUnit\Framework\TestCase;
use Spatie\Sheets\Tests\TestCase;
use Spatie\Sheets\Repositories\FilesystemRepository;
use Spatie\Sheets\Sheet;
use Spatie\Sheets\Tests\Concerns\UsesFactory;
Expand Down
2 changes: 1 addition & 1 deletion tests/SheetTest.php
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Jsonable;
use JsonSerializable;
use PHPUnit\Framework\TestCase;
use Spatie\Sheets\Tests\TestCase;
use ReflectionClass;
use Spatie\Sheets\Sheet;

Expand Down
16 changes: 16 additions & 0 deletions tests/TestCase.php
@@ -0,0 +1,16 @@
<?php

namespace Spatie\Sheets\Tests;

use Orchestra\Testbench\TestCase as OrchestraTestCase;
use Spatie\Sheets\SheetsServiceProvider;

abstract class TestCase extends OrchestraTestCase
{
public function getPackageProviders($app)
{
return [
SheetsServiceProvider::class,
];
}
}

0 comments on commit cc77c1d

Please sign in to comment.