mirror of
https://github.com/ivuorinen/bbcodeparser.git
synced 2026-01-26 03:13:57 +00:00
29
.github/workflows/composer-diff.yml
vendored
Normal file
29
.github/workflows/composer-diff.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
name: Composer Diff
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- 'composer.lock'
|
||||
jobs:
|
||||
composer-diff:
|
||||
name: Composer Diff
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0 # Required to make it possible to compare with PR base branch
|
||||
|
||||
- name: Generate composer diff
|
||||
id: composer_diff # To reference the output in comment
|
||||
uses: IonBazan/composer-diff-action@v1
|
||||
|
||||
- uses: marocchino/sticky-pull-request-comment@v2
|
||||
with:
|
||||
header: composer-diff # Creates a collapsed comment with the report
|
||||
message: |
|
||||
<details>
|
||||
<summary>Composer package changes</summary>
|
||||
|
||||
${{ steps.composer_diff.outputs.composer_diff }}
|
||||
|
||||
</details>
|
||||
49
.github/workflows/php.yml
vendored
Normal file
49
.github/workflows/php.yml
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
name: PHP Composer
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.operating-system }}
|
||||
continue-on-error: true
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
operating-system: ['ubuntu-latest', 'windows-latest', 'macos-latest']
|
||||
php-versions: ['7.4', '8.0', '8.1']
|
||||
phpunit-versions: ['latest']
|
||||
|
||||
steps:
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php-versions }}
|
||||
extensions: mbstring, intl, fileinfo
|
||||
ini-values: post_max_size=256M, max_execution_time=180
|
||||
coverage: xdebug
|
||||
tools: php-cs-fixer, phpunit:${{ matrix.phpunit-versions }}
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Validate composer.json and composer.lock
|
||||
run: composer validate --strict
|
||||
|
||||
- name: Cache Composer packages
|
||||
id: composer-cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: vendor
|
||||
key: ${{ runner.os }}-php-${{ matrix.php-versions }}-${{ hashFiles('**/composer.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-php-${{ matrix.php-versions }}-
|
||||
${{ runner.os }}-php-
|
||||
|
||||
- name: Install dependencies
|
||||
run: composer install --prefer-dist --no-progress
|
||||
|
||||
- name: Run test suite
|
||||
run: composer test
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,2 @@
|
||||
/vendor
|
||||
composer.lock
|
||||
composer.lock
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
language: php
|
||||
php:
|
||||
- 7.0
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
- 7.4
|
||||
- 8.0
|
||||
- 8.1
|
||||
- nightly
|
||||
matrix:
|
||||
allow_failures:
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
{
|
||||
"name": "ivuorinen/bbcodeparser",
|
||||
"description": "Parse your BBCode easy with this library.",
|
||||
"keywords": ["bbcode", "parser", "laravel", "psr-1", "psr-2", "psr-4"],
|
||||
"homepage": "https://github.com/ivuorinen/bbcodeparser",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"support": {
|
||||
"issues": "https://github.com/ivuorinen/bbcodeparser/issues"
|
||||
"type": "library",
|
||||
"keywords": [
|
||||
"bbcode",
|
||||
"parser",
|
||||
"laravel",
|
||||
"psr-1",
|
||||
"psr-2",
|
||||
"psr-4"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "vendor/bin/phpunit",
|
||||
"lint": "vendor/bin/phpcs",
|
||||
"lint-fix": "vendor/bin/phpcbf"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
@@ -20,37 +28,50 @@
|
||||
"homepage": "https://github.com/golonka/"
|
||||
}
|
||||
],
|
||||
"homepage": "https://github.com/ivuorinen/bbcodeparser",
|
||||
"support": {
|
||||
"issues": "https://github.com/ivuorinen/bbcodeparser/issues"
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7"
|
||||
"php": ">=7.4 || ^8.0 || ^8.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "5.7.27",
|
||||
"squizlabs/php_codesniffer": "2.9.2",
|
||||
"orchestra/testbench": "3.9.4"
|
||||
"dms/phpunit-arraysubset-asserts": "v0.3.1",
|
||||
"ergebnis/composer-normalize": "2.23.1",
|
||||
"orchestra/testbench": "v6.24.1",
|
||||
"phpunit/phpunit": "9.5.13",
|
||||
"squizlabs/php_codesniffer": "3.6.2"
|
||||
},
|
||||
"replace": {
|
||||
"golonka/bbcodeparser": "*"
|
||||
},
|
||||
"minimum-stability": "stable",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"ivuorinen\\BBCode\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": { "ivuorinen\\BBCode\\Tests\\": "tests/" },
|
||||
"psr-4": {
|
||||
"ivuorinen\\BBCode\\Tests\\": "tests/"
|
||||
},
|
||||
"classmap": [
|
||||
"tests/"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "stable",
|
||||
"replace": {
|
||||
"golonka/bbcodeparser": "*"
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"ergebnis/composer-normalize": true
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"ivuorinen\\BBCode\\BBCodeParserServiceProvider"
|
||||
],
|
||||
"aliases": {
|
||||
"BBCode": "ivuorinen\\BBCode\\Facades\\BBCodeParser"
|
||||
}
|
||||
},
|
||||
"providers": [
|
||||
"ivuorinen\\BBCode\\BBCodeParserServiceProvider"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
16
phpcs.xml
Normal file
16
phpcs.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="Basic Project Coding Standards">
|
||||
<rule ref="PSR2" />
|
||||
|
||||
<rule ref="Generic.CodeAnalysis.EmptyStatement" />
|
||||
<rule ref="Generic.Classes.DuplicateClassName"/>
|
||||
<rule ref="Generic.CodeAnalysis.EmptyStatement"/>
|
||||
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
|
||||
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/>
|
||||
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
|
||||
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
|
||||
<rule ref="Squiz.PHP.NonExecutableCode"/>
|
||||
|
||||
<file>./src</file>
|
||||
<file>./tests</file>
|
||||
</ruleset>
|
||||
32
phpunit.xml
32
phpunit.xml
@@ -1,21 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
bootstrap="vendor/autoload.php"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false">
|
||||
<testsuites>
|
||||
<testsuite name="Tests">
|
||||
<directory suffix="Test.php">./tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">./src</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||
<coverage processUncoveredFiles="true">
|
||||
<include>
|
||||
<directory suffix=".php">./src</directory>
|
||||
</include>
|
||||
</coverage>
|
||||
<testsuites>
|
||||
<testsuite name="Tests">
|
||||
<directory suffix="Test.php">./tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
|
||||
@@ -107,7 +107,8 @@ class BBCodeParser
|
||||
],
|
||||
'youtube' => [
|
||||
'pattern' => '/\[youtube\](.*?)\[\/youtube\]/s',
|
||||
'replace' => '<iframe width="560" height="315" src="//www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>',
|
||||
'replace' => '<iframe width="560" height="315" src="//www.youtube.com/embed/$1"' .
|
||||
' frameborder="0" allowfullscreen></iframe>',
|
||||
'content' => '$1'
|
||||
],
|
||||
'linebreak' => [
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace ivuorinen\BBCode\Tests;
|
||||
|
||||
use ivuorinen\BBCode\Traits\ArrayTrait;
|
||||
|
||||
class ArrayTraitHelper
|
||||
|
||||
@@ -2,24 +2,21 @@
|
||||
|
||||
namespace ivuorinen\BBCode\Tests;
|
||||
|
||||
use ArrayTraitHelper;
|
||||
use TestCase;
|
||||
|
||||
class ArrayTraitTest extends TestCase
|
||||
{
|
||||
private $class;
|
||||
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->class = new ArrayTraitHelper();
|
||||
}
|
||||
|
||||
public function test_array_only()
|
||||
public function testArrayOnly()
|
||||
{
|
||||
$this->assertTrue(\method_exists($this->class, 'arrayOnly'));
|
||||
}
|
||||
|
||||
public function test_array_except()
|
||||
public function testArrayExcept()
|
||||
{
|
||||
$this->assertTrue(\method_exists($this->class, 'arrayExcept'));
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace ivuorinen\BBCode\Tests;
|
||||
|
||||
class BBCodeParserFacadeTest extends TestCase
|
||||
{
|
||||
public function test_facade_exists_and_has_bbcode()
|
||||
public function testFacadeExistsAndHasBbcode()
|
||||
{
|
||||
try {
|
||||
$method = $this->callMethod(
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace ivuorinen\BBCode\Tests;
|
||||
|
||||
use ivuorinen\BBCode\BBCodeParserServiceProvider;
|
||||
|
||||
class BBCodeParserServiceProviderTest extends TestCase
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace ivuorinen\BBCode\Tests;
|
||||
|
||||
use ivuorinen\BBCode\BBCodeParser;
|
||||
|
||||
class BBCodeParserTest extends TestCase
|
||||
@@ -93,7 +95,8 @@ class BBCodeParserTest extends TestCase
|
||||
),
|
||||
'youtube' => array(
|
||||
'bbcode' => 'youtube',
|
||||
'expected_test' => '<iframe width="560" height="315" src="//www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>',
|
||||
'expected_test' => '<iframe width="560" height="315" src="//www.youtube.com/embed/%s"' .
|
||||
' frameborder="0" allowfullscreen></iframe>',
|
||||
'values' => ['dQw4w9WgXcQ']
|
||||
),
|
||||
'listitem' => array(
|
||||
@@ -135,14 +138,13 @@ class BBCodeParserTest extends TestCase
|
||||
['bbcode' => '[I]Result[/i]', 'expected' => '<em>Result</em>'],
|
||||
);
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->parser = new BBCodeParser();
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function test_it_has_known_parsers()
|
||||
public function testItHasKnownParsers()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->parser->parsers,
|
||||
@@ -150,7 +152,7 @@ class BBCodeParserTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function test_parsers_have_required_keys()
|
||||
public function testParsersHaveRequiredKeys()
|
||||
{
|
||||
$keys = array('pattern', 'replace', 'content');
|
||||
$parsers = $this->parser->getParsers();
|
||||
@@ -166,7 +168,7 @@ class BBCodeParserTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function test_parser_regexp_is_valid()
|
||||
public function testParserRegexpIsValid()
|
||||
{
|
||||
$parsers = $this->parser->getParsers();
|
||||
foreach ($parsers as $parserName => $parser) {
|
||||
@@ -179,7 +181,7 @@ class BBCodeParserTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function test_parser_default()
|
||||
public function testParserDefault()
|
||||
{
|
||||
foreach ($this->testedParsers as $name => $options) {
|
||||
$test = $this->createTest($options, $name);
|
||||
@@ -189,7 +191,7 @@ class BBCodeParserTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function test_parser_sensitive()
|
||||
public function testParserSensitive()
|
||||
{
|
||||
$testTemp = 'Test: %s / bbcode: %s / Actual: %s / Expected: %s';
|
||||
|
||||
@@ -203,7 +205,11 @@ class BBCodeParserTest extends TestCase
|
||||
|
||||
$result = $this->parser->parseCaseSensitive($bbcode);
|
||||
$this->assertEquals($expected, $result, sprintf(
|
||||
$testTemp, 'lowercase, sensitive', $bbcode, $result, $expected
|
||||
$testTemp,
|
||||
'lowercase, sensitive',
|
||||
$bbcode,
|
||||
$result,
|
||||
$expected
|
||||
));
|
||||
}
|
||||
|
||||
@@ -217,7 +223,11 @@ class BBCodeParserTest extends TestCase
|
||||
|
||||
$result = $this->parser->parseCaseSensitive($bbcode);
|
||||
$this->assertNotEquals($expected, $result, sprintf(
|
||||
$testTemp, 'uppercase, sensitive', $bbcode, $result, $expected
|
||||
$testTemp,
|
||||
'uppercase, sensitive',
|
||||
$bbcode,
|
||||
$result,
|
||||
$expected
|
||||
));
|
||||
}
|
||||
|
||||
@@ -231,12 +241,16 @@ class BBCodeParserTest extends TestCase
|
||||
|
||||
$result = $this->parser->parseCaseSensitive($bbcode);
|
||||
$this->assertNotEquals($expected, $result, sprintf(
|
||||
$testTemp, 'mixed case, sensitive', $bbcode, $result, $expected
|
||||
$testTemp,
|
||||
'mixed case, sensitive',
|
||||
$bbcode,
|
||||
$result,
|
||||
$expected
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function test_parser_insensitive()
|
||||
public function testParserInsensitive()
|
||||
{
|
||||
/**
|
||||
* Now we run with insensitive case turned on, so everything
|
||||
@@ -253,7 +267,8 @@ class BBCodeParserTest extends TestCase
|
||||
$bbcode = $case['bbcode'];
|
||||
$expected = $case['expected'];
|
||||
$this->assertEquals(
|
||||
$expected, $this->parser->parse($bbcode, true)
|
||||
$expected,
|
||||
$this->parser->parse($bbcode, true)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
@@ -263,7 +278,7 @@ class BBCodeParserTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function test_stripBBCodeTags()
|
||||
public function testStripBBCodeTags()
|
||||
{
|
||||
foreach ($this->mixedCaseTests as $test) {
|
||||
$this->assertEquals(
|
||||
@@ -273,7 +288,7 @@ class BBCodeParserTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function test_only()
|
||||
public function testOnly()
|
||||
{
|
||||
$keys = array('bold', 'underline');
|
||||
|
||||
@@ -284,7 +299,7 @@ class BBCodeParserTest extends TestCase
|
||||
$this->assertNotEquals(array_keys($parsers), array_keys($onlyFew));
|
||||
}
|
||||
|
||||
public function test_except()
|
||||
public function testExcept()
|
||||
{
|
||||
$keys = array('bold', 'underline');
|
||||
|
||||
@@ -295,7 +310,7 @@ class BBCodeParserTest extends TestCase
|
||||
$this->assertNotEquals(array_keys($parsers), array_keys($exceptFew));
|
||||
}
|
||||
|
||||
public function test_adding_a_new_parser()
|
||||
public function testAddingNewParser()
|
||||
{
|
||||
$this->parser->setParser('test', 'x', 'y', 'z');
|
||||
$expected = array('pattern' => 'x', 'replace' => 'y', 'content' => 'z');
|
||||
@@ -305,7 +320,7 @@ class BBCodeParserTest extends TestCase
|
||||
$this->assertArraySubset($expected, $parsers['test']);
|
||||
}
|
||||
|
||||
public function test_we_have_all_parsers_tested()
|
||||
public function testWeHaveAllParsersTested()
|
||||
{
|
||||
$parsers = array_keys($this->parser->except($this->skipParsers)->getParsers());
|
||||
$missing = array();
|
||||
@@ -336,10 +351,10 @@ class BBCodeParserTest extends TestCase
|
||||
* rules for automated test generation. Automation ftw.
|
||||
*
|
||||
* @param array $options
|
||||
* @param $name
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
public function createTest($options = [], $name)
|
||||
public function createTest($options = [], $name = '')
|
||||
{
|
||||
if (!isset($options['bbcode'])) {
|
||||
$options['bbcode'] = $name;
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
<?php
|
||||
|
||||
class TestCase extends Orchestra\Testbench\TestCase
|
||||
namespace ivuorinen\BBCode\Tests;
|
||||
|
||||
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||
|
||||
class TestCase extends \Orchestra\Testbench\TestCase
|
||||
{
|
||||
use ArraySubsetAsserts;
|
||||
|
||||
protected function getPackageProviders($app)
|
||||
{
|
||||
unset($app);
|
||||
return ['ivuorinen\BBCode\BBCodeParserServiceProvider'];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user