Skip to content

Commit

Permalink
Created initial version of bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
hason committed Aug 8, 2015
0 parents commit 41a5a20
Show file tree
Hide file tree
Showing 20 changed files with 648 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitattributes
@@ -0,0 +1,6 @@
/spec export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php_cs export-ignore
/.travis.yml export-ignore
/phpspec.yml.dist export-ignore
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
/composer.lock
/vendor/
phpspec.yml
28 changes: 28 additions & 0 deletions .php_cs
@@ -0,0 +1,28 @@
<?php

$header = <<<EOF
This is part of the webuni/commonmark-bundle package.
(c) Martin Hasoň <martin.hason@gmail.com>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF;

Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($header);

$finder = Symfony\CS\Finder\DefaultFinder::create()
->in(['src', 'spec'])
;

return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
->fixers([
'header_comment',
'align_double_arrow',
'newline_after_open_tag',
'ordered_use',
'short_array_syntax',
])
->finder($finder)
;
23 changes: 23 additions & 0 deletions .travis.yml
@@ -0,0 +1,23 @@
language: php

sudo: false

php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm

cache:
directories:
- $HOME/.composer/cache
- vendor

before_script:
- composer self-update
- composer install --prefer-source --no-interaction

script:
- php vendor/bin/phpspec run
- php vendor/bin/php-cs-fixer fix --dry-run
8 changes: 8 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,8 @@
CHANGELOG
=========

0.1.0
-----

* Initial version

19 changes: 19 additions & 0 deletions LICENSE
@@ -0,0 +1,19 @@
Copyright (c) 2015 Martin Hasoň <martin.hason@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
30 changes: 30 additions & 0 deletions README.md
@@ -0,0 +1,30 @@
CommonMark Bundle
=================

[![Packagist](https://img.shields.io/packagist/v/webuni/commonmark-bundle.svg?style=flat-square)](https://packagist.org/packages/webuni/commonmark-bundle)
[![Build Status](https://img.shields.io/travis/webuni/commonmark-bundle.svg?style=flat-square)](https://travis-ci.org/webuni/commonmark-bundle)
[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/webuni/commonmark-bundle.svg?style=flat-square)](https://scrutinizer-ci.com/g/webuni/commonmark-bundle)
[![SensioLabsInsight](https://img.shields.io/sensiolabs/i/29bd3e8e-1b60-4ad5-aa6a-e04efb41e9e2.svg?style=flat-square)](https://insight.sensiolabs.com/projects/29bd3e8e-1b60-4ad5-aa6a-e04efb41e9e2)

Symfony bundle that integrates the league/commonmark markdown parser.

Installation
------------

This project can be installed via Composer:

composer require webuni/commonmark-bundle

Add WebuniCommonMarkBundle to your application kernel

```php
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new Webuni\Bundle\CommonMarkBundle\WebuniCommonMarkBundle(),
// ...
);
}
```
38 changes: 38 additions & 0 deletions composer.json
@@ -0,0 +1,38 @@
{
"name": "webuni/commonmark-bundle",
"type": "symfony-bundle",
"description": "The table extension for CommonMark PHP implementation",
"keywords": ["markdown","symfony","bundle","commonmark"],
"homepage": "https://github.com/webuni/commonmark-bundle",
"license": "MIT",
"authors": [
{
"name": "Martin Hasoň",
"email": "martin.hason@gmail.com",
"role": "Lead Developer"
}
],
"require": {
"php": ">=5.4",
"symfony/http-kernel": "^2.3",
"symfony/config": "^2.3",
"symfony/dependency-injection": "^2.3",
"league/commonmark": "~0.7"
},
"require-dev": {
"phpspec/phpspec": "^2.2",
"coduo/phpspec-data-provider-extension": "^1.0",
"bossa/phpspec2-expect": "^1.0",
"fabpot/php-cs-fixer": "^1.9"
},
"autoload": {
"psr-4": {
"Webuni\\Bundle\\CommonMarkBundle\\": "src"
}
},
"extra": {
"branch-alias": {
"dev-master": "0.1-dev"
}
}
}
7 changes: 7 additions & 0 deletions phpspec.yml.dist
@@ -0,0 +1,7 @@
suites:
default:
namespace: Webuni\Bundle\CommonMarkBundle
psr4_prefix: Webuni\Bundle\CommonMarkBundle

extensions:
- Coduo\PhpSpec\DataProvider\DataProviderExtension
14 changes: 14 additions & 0 deletions spec/ConverterRegistrySpec.php
@@ -0,0 +1,14 @@
<?php

namespace spec\Webuni\Bundle\CommonMarkBundle;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class ConverterRegistrySpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Webuni\Bundle\CommonMarkBundle\ConverterRegistry');
}
}
56 changes: 56 additions & 0 deletions spec/DependencyInjection/Compiler/CommonMarkExtensionPassSpec.php
@@ -0,0 +1,56 @@
<?php

/*
* This is part of the webuni/commonmark-bundle package.
*
* (c) Martin Hasoň <martin.hason@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace spec\Webuni\Bundle\CommonMarkBundle\DependencyInjection\Compiler;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

/**
* @mixin CompilerPassInterface
*/
class CommonMarkExtensionPassSpec extends ObjectBehavior
{
const SERVICE_ENV = 'webuni_commonmark.default_environment';
const EXTENSION_TAG = 'webuni_commonmark.extension';

public function it_is_initializable()
{
$this->shouldHaveType('Webuni\Bundle\CommonMarkBundle\DependencyInjection\Compiler\CommonMarkExtensionPass');
}

/**
* @param Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
public function it_should_not_register_extension_if_extension_is_not_loaded($container)
{
$container->hasDefinition(self::SERVICE_ENV)->willReturn(false);
$container->getDefinition(self::SERVICE_ENV)->shouldNotBeCalled();

$this->process($container);
}

/**
* @param Symfony\Component\DependencyInjection\ContainerBuilder $container
* @param Symfony\Component\DependencyInjection\Definition $definition
*/
public function it_should_register_extension($container, $definition)
{
$container->hasDefinition(self::SERVICE_ENV)->willReturn(true);
$container->getDefinition(self::SERVICE_ENV)->willReturn($definition);
$container->findTaggedServiceIds(self::EXTENSION_TAG)->willReturn(['my_service' => []]);

$definition->addMethodCall('addExtension', Argument::containing(Argument::type('Symfony\Component\DependencyInjection\Reference')))->shouldBeCalled();

$this->process($container);
}
}
80 changes: 80 additions & 0 deletions spec/DependencyInjection/ConfigurationSpec.php
@@ -0,0 +1,80 @@
<?php

/*
* This is part of the webuni/commonmark-bundle package.
*
* (c) Martin Hasoň <martin.hason@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace spec\Webuni\Bundle\CommonMarkBundle\DependencyInjection;

use PhpSpec\ObjectBehavior;
use Symfony\Component\Config\Definition\Processor;
use Webuni\Bundle\CommonMarkBundle\DependencyInjection\Configuration;

/**
* @mixin Configuration
*/
class ConfigurationSpec extends ObjectBehavior
{
public function it_is_initializable()
{
$this->shouldHaveType('Webuni\Bundle\CommonMarkBundle\DependencyInjection\Configuration');
}

/**
* @dataProvider get_configuration
*/
public function it_should_process_configuration(array $config, array $expected)
{
$processor = new Processor();

expect($processor->processConfiguration(new Configuration(), [$config]))->shouldBe($expected);
}

public function get_configuration()
{
$converter = [
'converter' => 'webuni_commonmark.converter',
'environment' => 'webuni_commonmark.default_environment',
'parser' => 'webuni_commonmark.docparser',
'renderer' => 'webuni_commonmark.htmlrenderer',
'config' => [],
'extensions' => [],
];

return [
[
[],
[
'default_converter' => 'default',
'converters' => [
'default' => $converter,
]
],
],
[
['converters' => ['custom' => null,]],
[
'converters' => [
'default' => $converter,
'custom' => $converter,
],
'default_converter' => 'default',
],
],
[
['converters' => ['default' => ['config' => ['foo' => 'bar']]]],
[
'converters' => [
'default' => ['config' => ['foo' => 'bar']] + $converter,
],
'default_converter' => 'default',
],
],
];
}
}
52 changes: 52 additions & 0 deletions spec/DependencyInjection/WebuniCommonMarkExtensionSpec.php
@@ -0,0 +1,52 @@
<?php

/*
* This is part of the webuni/commonmark-bundle package.
*
* (c) Martin Hasoň <martin.hason@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace spec\Webuni\Bundle\CommonMarkBundle\DependencyInjection;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Webuni\Bundle\CommonMarkBundle\DependencyInjection\WebuniCommonMarkExtension;

/**
* @mixin WebuniCommonMarkExtension
*/
class WebuniCommonMarkExtensionSpec extends ObjectBehavior
{
public function it_is_initializable()
{
$this->shouldHaveType('Webuni\Bundle\CommonMarkBundle\DependencyInjection\WebuniCommonMarkExtension');
}

public function it_should_have_correct_name()
{
$this->getAlias()->shouldBe('webuni_commonmark');
}

public function it_should_create_default_converter()
{
$builder = new ContainerBuilder();

$this->load([], $builder);

$converters = $builder->getDefinition('webuni_commonmark.converter_registry')->getArgument(0);
expect($converters)->shouldHaveKey('default');
}

public function it_should_be_compilabl()
{
$builder = new ContainerBuilder();

$this->load([], $builder);
$builder->compile();
var_dump($builder->get('webuni_commonmark.converter_registry'));
}
}

0 comments on commit 41a5a20

Please sign in to comment.