From ee142bdaf06fedf3afc0fd1f48bd536d820d68ac Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Mon, 1 Feb 2021 12:56:06 +0500 Subject: [PATCH 01/17] update .editorconfig --- .editorconfig | 3 --- 1 file changed, 3 deletions(-) diff --git a/.editorconfig b/.editorconfig index 2da7375..27e2667 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,8 +14,5 @@ insert_final_newline = true [*.md] trim_trailing_whitespace = false -[*.php] -indent_style = tab - [*.yml] indent_size = 2 From 06e9992276b01c83cfc05b47836fd31246201410 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Mon, 1 Feb 2021 12:56:21 +0500 Subject: [PATCH 02/17] update .gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index c331141..41cf726 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +.php_cs.cache +.phpunit.result.cache composer.lock coverage.xml +phpcs.xml +phpunit.xml vendor/ From 29d6c37b51d60cd59b8dd1718ece7c6c1e1c8a60 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Mon, 1 Feb 2021 12:56:36 +0500 Subject: [PATCH 03/17] update .travis.yml --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7b697c1..b0e5e8d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,8 @@ matrix: - php: 7.1 - php: 7.2 - php: 7.3 + - php: 7.4 + - php: nightly fast_finish: true before_install: @@ -13,4 +15,4 @@ before_install: install: - travis_retry composer install --no-interaction --prefer-source --no-suggest -script: vendor/bin/phpunit --colors=always --coverage-text +script: php vendor/bin/phpunit --colors=always --coverage-text From ed18f6c8fccf334e72a86b476577e27423f58c19 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Mon, 1 Feb 2021 12:56:48 +0500 Subject: [PATCH 04/17] add phpcs.xml.dist --- phpcs.xml.dist | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 phpcs.xml.dist diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..be45cac --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,7 @@ + + + + + src + tests + From c9e0cb9ef24b849c6b2645b4d800a36ba229c23d Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Mon, 1 Feb 2021 12:56:59 +0500 Subject: [PATCH 05/17] update LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 4c67e86..19aa2e3 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Anatoly Fenric +Copyright (c) 2018 Sunrise // PHP Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 1a4597937bb8599d82903d41106d6b982d355ee9 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Mon, 1 Feb 2021 12:57:11 +0500 Subject: [PATCH 06/17] update README.md --- README.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0bb36d8..0b4f77a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Simple slugger for PHP 7.1+ based on ICU +# Simple slugger for PHP 7.1+ (incl. PHP8) based on ICU [![Gitter](https://badges.gitter.im/sunrise-php/support.png)](https://gitter.im/sunrise-php/support) [![Build Status](https://api.travis-ci.com/sunrise-php/slugger.svg?branch=master)](https://travis-ci.com/sunrise-php/slugger) @@ -15,7 +15,7 @@ ## Installation -``` +```bash composer require sunrise/slugger ``` @@ -73,10 +73,6 @@ $di['slugger'] = function() : \Sunrise\Slugger\SluggerInterface { $di['slugger']->slugify('Zwölf große Boxkämpfer jagen Viktor quer über den Sylter Deich.'); ``` -## Api documentation - -https://phpdoc.fenric.ru/ - ## Useful links * http://site.icu-project.org/ From c2b4a8f7f5f50b7ae5e94d5fc6018ad7092f8c67 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Mon, 1 Feb 2021 12:57:58 +0500 Subject: [PATCH 07/17] update composer.json --- composer.json | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 2bf2d93..d244550 100644 --- a/composer.json +++ b/composer.json @@ -1,20 +1,31 @@ { "name": "sunrise/slugger", - "description": "Simple slugger for PHP 7.1+ based on ICU", - "keywords": ["fenric", "sunrise", "slugger", "translit", "icu"], "homepage": "https://github.com/sunrise-php/slugger", + "description": "Simple slugger for PHP 7.1+ based on ICU", "license": "MIT", - "authors": [{ - "name": "Anatoly Fenric", - "email": "anatoly@fenric.ru", - "homepage": "https://anatoly.fenric.ru/" - }], + "keywords": [ + "fenric", + "sunrise", + "slugger", + "translit", + "icu", + "php7", + "php8" + ], + "authors": [ + { + "name": "Anatoly Fenric", + "email": "anatoly@fenric.ru", + "homepage": "https://anatoly.fenric.ru/" + } + ], "require": { - "php": "^7.1", + "php": "^7.1|^8.0", "ext-intl": "*" }, "require-dev": { - "phpunit/phpunit": "7.5.6" + "phpunit/phpunit": "7.5.20|9.5.0", + "sunrise/coding-standard": "1.0.0" }, "autoload": { "psr-4": { @@ -23,7 +34,8 @@ }, "scripts": { "test": [ - "phpunit --colors=always --coverage-text" + "phpunit --colors=always --coverage-text", + "phpcs" ] } } From d535053fba2508f05897c8eb72c97b30972fd5e6 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Mon, 1 Feb 2021 12:58:55 +0500 Subject: [PATCH 08/17] update phpunit.xml.dist --- phpunit.xml.dist | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2803627..6ad9ef1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,13 +1,13 @@ - + + + + ./src + + ./tests/ - - - ./src - - From 2f140455daa15557f88c60aff2730b4525a7b673 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Mon, 1 Feb 2021 12:59:09 +0500 Subject: [PATCH 09/17] csf --- src/Exception/UnableToCreateTransliteratorException.php | 3 ++- src/Exception/UnableToTransliterateException.php | 3 ++- src/Exception/UnsupportedTransliteratorIdentifierException.php | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Exception/UnableToCreateTransliteratorException.php b/src/Exception/UnableToCreateTransliteratorException.php index 59ed094..6713383 100644 --- a/src/Exception/UnableToCreateTransliteratorException.php +++ b/src/Exception/UnableToCreateTransliteratorException.php @@ -20,4 +20,5 @@ * UnableToCreateTransliteratorException */ class UnableToCreateTransliteratorException extends RuntimeException -{} +{ +} diff --git a/src/Exception/UnableToTransliterateException.php b/src/Exception/UnableToTransliterateException.php index 2b1b5c2..2a1b392 100644 --- a/src/Exception/UnableToTransliterateException.php +++ b/src/Exception/UnableToTransliterateException.php @@ -20,4 +20,5 @@ * UnableToTransliterateException */ class UnableToTransliterateException extends RuntimeException -{} +{ +} diff --git a/src/Exception/UnsupportedTransliteratorIdentifierException.php b/src/Exception/UnsupportedTransliteratorIdentifierException.php index 68743eb..41173e4 100644 --- a/src/Exception/UnsupportedTransliteratorIdentifierException.php +++ b/src/Exception/UnsupportedTransliteratorIdentifierException.php @@ -20,4 +20,5 @@ * UnsupportedTransliteratorIdentifierException */ class UnsupportedTransliteratorIdentifierException extends RuntimeException -{} +{ +} From b406ee8a5131b03815019be7e6900af6bc848b49 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Mon, 1 Feb 2021 12:59:38 +0500 Subject: [PATCH 10/17] code improved --- src/Slugger.php | 202 +++++++++++++++++++++++---------------- src/SluggerInterface.php | 62 +++--------- 2 files changed, 128 insertions(+), 136 deletions(-) diff --git a/src/Slugger.php b/src/Slugger.php index 73788eb..73957d4 100644 --- a/src/Slugger.php +++ b/src/Slugger.php @@ -11,95 +11,127 @@ namespace Sunrise\Slugger; +/** + * Import functions + */ +use function in_array; +use function preg_replace; +use function sprintf; +use function str_replace; +use function transliterator_create; +use function transliterator_list_ids; +use function transliterator_transliterate; +use function trim; + /** * Slugger + * + * @link http://userguide.icu-project.org/transforms/general */ class Slugger implements SluggerInterface { - /** - * Default transliterator ID - * - * @var string - */ - protected $transliteratorId = 'Russian-Latin/BGN'; - - /** - * {@inheritDoc} - */ - public function setTransliteratorId(string $transliteratorId) : void - { - $supported = $this->getSupportedTransliteratorIds(); - - if (! \in_array($transliteratorId, $supported)) - { - throw new Exception\UnsupportedTransliteratorIdentifierException( - \sprintf('The transliterator identifier "%s" is not supported', $transliteratorId) - ); - } - - $this->transliteratorId = $transliteratorId; - } - - /** - * {@inheritDoc} - */ - public function getTransliteratorId() : string - { - return $this->transliteratorId; - } - - /** - * {@inheritDoc} - */ - public function getSupportedTransliteratorIds() : array - { - return \transliterator_list_ids(); - } - - /** - * {@inheritDoc} - */ - public function transliterate(string $string, string $compound) : string - { - $id = $this->getTransliteratorId(); - - $compound = \sprintf('%s; %s', $id, $compound); - - $transliterator = \transliterator_create($compound); - - if (null === $transliterator) - { - throw new Exception\UnableToCreateTransliteratorException( - \sprintf('Unable to create transliterator with compound "%s"', $compound) - ); - } - - $transliterated = \transliterator_transliterate($transliterator, $string); - - if (false === $transliterated) - { - throw new Exception\UnableToTransliterateException( - \sprintf('Unable to transliterate string with compound "%s"', $compound) - ); - } - - return $transliterated; - } - - /** - * {@inheritDoc} - */ - public function slugify(string $string, string $delimiter = '-') : string - { - $slug = $this->transliterate($string, 'Any-Latin; Latin-ASCII; Lower(); [^\x20\x30-\x39\x41-\x5A\x61-\x7A] Remove'); - - $slug = \preg_replace('/[\x20]{2,}/', ' ', $slug); - - $slug = \trim($slug); - - $slug = \str_replace(' ', $delimiter, $slug); - - return $slug; - } + /** + * The transliterator ID + * + * @var string + */ + protected $transliteratorId = 'Russian-Latin/BGN'; + + /** + * Sets the transliterator ID + * + * @param string $transliteratorId + * + * @return void + * + * @throws Exception\UnsupportedTransliteratorIdentifierException + * + * @link http://userguide.icu-project.org/transforms/general#TOC-Basic-IDs + */ + public function setTransliteratorId(string $transliteratorId) : void + { + $supportedTransliteratorIds = $this->getSupportedTransliteratorIds(); + if (!in_array($transliteratorId, $supportedTransliteratorIds)) { + throw new Exception\UnsupportedTransliteratorIdentifierException( + sprintf('The transliterator ID "%s" is not supported', $transliteratorId) + ); + } + + $this->transliteratorId = $transliteratorId; + } + + /** + * Gets the transliterator ID + * + * @return string + */ + public function getTransliteratorId() : string + { + return $this->transliteratorId; + } + + /** + * Gets supported transliterator IDs + * + * @return string[] + */ + public function getSupportedTransliteratorIds() : array + { + return transliterator_list_ids(); + } + + /** + * Transliterates the given string using the given compound + * + * @param string $string + * @param string $compound + * + * @return string + * + * @throws Exception\UnableToCreateTransliteratorException + * @throws Exception\UnableToTransliterateException + */ + public function transliterate(string $string, string $compound) : string + { + $compound = $this->getTransliteratorId() . '; ' . $compound; + $transliterator = transliterator_create($compound); + if (null === $transliterator) { + throw new Exception\UnableToCreateTransliteratorException( + sprintf('Unable to create transliterator with compound "%s"', $compound) + ); + } + + $transliterated = transliterator_transliterate($transliterator, $string); + if (false === $transliterated) { + throw new Exception\UnableToTransliterateException( + sprintf('Unable to transliterate string with compound "%s"', $compound) + ); + } + + return $transliterated; + } + + /** + * Converts the given string to slug + * + * @param string $string + * @param string $delimiter + * + * @return string + * + * @throws Exception\UnableToCreateTransliteratorException + * @throws Exception\UnableToTransliterateException + */ + public function slugify(string $string, string $delimiter = '-') : string + { + $compound = 'Any-Latin; Latin-ASCII; Lower(); [^\x20\x30-\x39\x41-\x5A\x61-\x7A] Remove'; + + $slug = $this->transliterate($string, $compound); + $slug = preg_replace('/[\x20]{2,}/', ' ', $slug); + $slug = trim($slug); + $slug = str_replace(' ', $delimiter, $slug); + + return $slug; + } } diff --git a/src/SluggerInterface.php b/src/SluggerInterface.php index 6eb5433..f6d19fc 100644 --- a/src/SluggerInterface.php +++ b/src/SluggerInterface.php @@ -13,59 +13,19 @@ /** * SluggerInterface - * - * @link http://userguide.icu-project.org/transforms/general */ interface SluggerInterface { - /** - * Sets the transliterator ID - * - * @param string $transliteratorId - * - * @return void - * - * @throws Exception\UnsupportedTransliteratorIdentifierException - * - * @link http://userguide.icu-project.org/transforms/general#TOC-Basic-IDs - */ - public function setTransliteratorId(string $transliteratorId) : void; - - /** - * Gets the transliterator ID - * - * @return string - */ - public function getTransliteratorId() : string; - - /** - * Gets supported transliterator IDs - * - * @return array - */ - public function getSupportedTransliteratorIds() : array; - - /** - * Transliterates the given string using the given compound - * - * @param string $string - * @param string $compound - * - * @return string - * - * @throws Exception\UnableToCreateTransliteratorException - * @throws Exception\UnableToTransliterateException - */ - public function transliterate(string $string, string $compound) : string; - - /** - * Converts the given string to slug - * - * @param string $string - * @param string $delimiter - * - * @return string - */ - public function slugify(string $string, string $delimiter = '-') : string; + /** + * Converts the given string to slug + * + * @param string $string + * @param string $delimiter + * + * @return string + * + * @throws \RuntimeException + */ + public function slugify(string $string, string $delimiter) : string; } From f2bafa82aff43842064e871599d5573a247cbcf9 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Mon, 1 Feb 2021 12:59:51 +0500 Subject: [PATCH 11/17] tests improved --- tests/SluggerTest.php | 188 +++++++++++++++++++++--------------------- 1 file changed, 95 insertions(+), 93 deletions(-) diff --git a/tests/SluggerTest.php b/tests/SluggerTest.php index 77128b4..d7bbadc 100644 --- a/tests/SluggerTest.php +++ b/tests/SluggerTest.php @@ -11,135 +11,137 @@ class SluggerTest extends TestCase { - private const RUSSIAN_LATIN_TRANSLITERATOR_ID = 'Russian-Latin/BGN'; - private const CYRILLIC_LATIN_TRANSLITERATOR_ID = 'Cyrillic-Latin'; + private const RUSSIAN_LATIN_TRANSLITERATOR_ID = 'Russian-Latin/BGN'; + private const CYRILLIC_LATIN_TRANSLITERATOR_ID = 'Cyrillic-Latin'; - public function testConstructor() - { - $slugger = new Slugger(); + public function testConstructor() + { + $slugger = new Slugger(); - $this->assertInstanceOf(SluggerInterface::class, $slugger); - } + $this->assertInstanceOf(SluggerInterface::class, $slugger); + } - public function testTransliteratorId() - { - $slugger = new Slugger(); + public function testTransliteratorId() + { + $slugger = new Slugger(); - $slugger->setTransliteratorId(self::RUSSIAN_LATIN_TRANSLITERATOR_ID); - $this->assertEquals(self::RUSSIAN_LATIN_TRANSLITERATOR_ID, $slugger->getTransliteratorId()); + $slugger->setTransliteratorId(self::RUSSIAN_LATIN_TRANSLITERATOR_ID); + $this->assertEquals(self::RUSSIAN_LATIN_TRANSLITERATOR_ID, $slugger->getTransliteratorId()); - $slugger->setTransliteratorId(self::CYRILLIC_LATIN_TRANSLITERATOR_ID); - $this->assertEquals(self::CYRILLIC_LATIN_TRANSLITERATOR_ID, $slugger->getTransliteratorId()); - } + $slugger->setTransliteratorId(self::CYRILLIC_LATIN_TRANSLITERATOR_ID); + $this->assertEquals(self::CYRILLIC_LATIN_TRANSLITERATOR_ID, $slugger->getTransliteratorId()); + } - public function testDefaultTransliteratorId() - { - $slugger = new Slugger(); + public function testDefaultTransliteratorId() + { + $slugger = new Slugger(); - $this->assertEquals(self::RUSSIAN_LATIN_TRANSLITERATOR_ID, $slugger->getTransliteratorId()); - } + $this->assertEquals(self::RUSSIAN_LATIN_TRANSLITERATOR_ID, $slugger->getTransliteratorId()); + } - public function testUnsupportedTransliterationId() - { - $this->expectException(UnsupportedTransliteratorIdentifierException::class); - $this->expectExceptionMessage('The transliterator identifier "Morrowind-Oblivion/KFC" is not supported'); + public function testUnsupportedTransliterationId() + { + $this->expectException(UnsupportedTransliteratorIdentifierException::class); + $this->expectExceptionMessage('The transliterator ID "Morrowind-Oblivion/KFC" is not supported'); - $slugger = new Slugger(); + $slugger = new Slugger(); - $slugger->setTransliteratorId('Morrowind-Oblivion/KFC'); - } + $slugger->setTransliteratorId('Morrowind-Oblivion/KFC'); + } - public function testSupportedTransliteratorIds() - { - $slugger = new Slugger(); + public function testSupportedTransliteratorIds() + { + $slugger = new Slugger(); - $this->assertEquals(\transliterator_list_ids(), $slugger->getSupportedTransliteratorIds()); - } + $this->assertEquals(\transliterator_list_ids(), $slugger->getSupportedTransliteratorIds()); + } - public function testTransliterateRussianLatin() - { - $input = 'съешь ещё этих мягких французских булок, да выпей чаю'; - $output = 'syesh yeshche etikh myagkikh frantsuzskikh bulok da vypey chayu'; + public function testTransliterateRussianLatin() + { + $input = 'съешь ещё этих мягких французских булок, да выпей чаю'; + $output = 'syesh yeshche etikh myagkikh frantsuzskikh bulok da vypey chayu'; + $compound = 'Any-Latin; Latin-ASCII; [^\x20\x41-\x5A\x61-\x7A] Remove'; - $slugger = new Slugger(); + $slugger = new Slugger(); + $slugger->setTransliteratorId(self::RUSSIAN_LATIN_TRANSLITERATOR_ID); - $slugger->setTransliteratorId(self::RUSSIAN_LATIN_TRANSLITERATOR_ID); + $this->assertEquals($output, $slugger->transliterate($input, $compound)); + } - $this->assertEquals($output, $slugger->transliterate($input, 'Any-Latin; Latin-ASCII; [^\x20\x41-\x5A\x61-\x7A] Remove')); - } + public function testTransliterateCyrillicLatin() + { + $input = 'съешь ещё этих мягких французских булок, да выпей чаю'; + $output = 'ses ese etih magkih francuzskih bulok da vypej cau'; + $compound = 'Any-Latin; Latin-ASCII; [^\x20\x41-\x5A\x61-\x7A] Remove'; - public function testTransliterateCyrillicLatin() - { - $input = 'съешь ещё этих мягких французских булок, да выпей чаю'; - $output = 'ses ese etih magkih francuzskih bulok da vypej cau'; + $slugger = new Slugger(); + $slugger->setTransliteratorId(self::CYRILLIC_LATIN_TRANSLITERATOR_ID); - $slugger = new Slugger(); + $this->assertEquals($output, $slugger->transliterate($input, $compound)); + } - $slugger->setTransliteratorId(self::CYRILLIC_LATIN_TRANSLITERATOR_ID); + public function testSlugifyRussianLatin() + { + $input = 'съешь ещё этих мягких французских булок, да выпей чаю'; + $output = 'syesh-yeshche-etikh-myagkikh-frantsuzskikh-bulok-da-vypey-chayu'; - $this->assertEquals($output, $slugger->transliterate($input, 'Any-Latin; Latin-ASCII; [^\x20\x41-\x5A\x61-\x7A] Remove')); - } + $slugger = new Slugger(); - public function testSlugifyRussianLatin() - { - $input = 'съешь ещё этих мягких французских булок, да выпей чаю'; - $output = 'syesh-yeshche-etikh-myagkikh-frantsuzskikh-bulok-da-vypey-chayu'; + $slugger->setTransliteratorId(self::RUSSIAN_LATIN_TRANSLITERATOR_ID); - $slugger = new Slugger(); + $this->assertEquals($output, $slugger->slugify($input)); + } - $slugger->setTransliteratorId(self::RUSSIAN_LATIN_TRANSLITERATOR_ID); + public function testSlugifyCyrillicLatin() + { + $input = 'съешь ещё этих мягких французских булок, да выпей чаю'; + $output = 'ses-ese-etih-magkih-francuzskih-bulok-da-vypej-cau'; - $this->assertEquals($output, $slugger->slugify($input)); - } + $slugger = new Slugger(); - public function testSlugifyCyrillicLatin() - { - $input = 'съешь ещё этих мягких французских булок, да выпей чаю'; - $output = 'ses-ese-etih-magkih-francuzskih-bulok-da-vypej-cau'; + $slugger->setTransliteratorId(self::CYRILLIC_LATIN_TRANSLITERATOR_ID); - $slugger = new Slugger(); + $this->assertEquals($output, $slugger->slugify($input)); + } - $slugger->setTransliteratorId(self::CYRILLIC_LATIN_TRANSLITERATOR_ID); + public function testSlugifyWithDelimiter() + { + $input = ' А Б В '; + $output = 'a_b_v'; - $this->assertEquals($output, $slugger->slugify($input)); - } + $slugger = new Slugger(); - public function testSlugifyWithDelimiter() - { - $input = ' А Б В '; - $output = 'a_b_v'; + $slugger->setTransliteratorId(self::RUSSIAN_LATIN_TRANSLITERATOR_ID); - $slugger = new Slugger(); + $this->assertEquals($output, $slugger->slugify($input, '_')); + } - $slugger->setTransliteratorId(self::RUSSIAN_LATIN_TRANSLITERATOR_ID); + public function testSlugifyWithNumbers() + { + $input = '0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz'; + $output = '0123456789-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz'; - $this->assertEquals($output, $slugger->slugify($input, '_')); - } + $slugger = new Slugger(); - public function testSlugifyWithNumbers() - { - $input = '0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz'; - $output = '0123456789-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz'; + $this->assertEquals($output, $slugger->slugify($input)); + } - $slugger = new Slugger(); + public function testTransliterateWithInvalidCompound() + { + $expectedMessage = 'Unable to create transliterator with compound "Russian-Latin/BGN; UndefinedCommand()"'; - $this->assertEquals($output, $slugger->slugify($input)); - } + $this->expectException(UnableToCreateTransliteratorException::class); + $this->expectExceptionMessage($expectedMessage); - public function testTransliterateWithInvalidCompound() - { - $this->expectException(UnableToCreateTransliteratorException::class); - $this->expectExceptionMessage('Unable to create transliterator with compound "Russian-Latin/BGN; UndefinedCommand()"'); + $slugger = new Slugger(); - $slugger = new Slugger(); + $slugger->transliterate('', 'UndefinedCommand()'); + } - $slugger->transliterate('', 'UndefinedCommand()'); - } - - public function testExceptions() - { - $this->assertInstanceOf(\RuntimeException::class, new UnableToCreateTransliteratorException('')); - $this->assertInstanceOf(\RuntimeException::class, new UnableToTransliterateException('')); - $this->assertInstanceOf(\RuntimeException::class, new UnsupportedTransliteratorIdentifierException('')); - } + public function testExceptions() + { + $this->assertInstanceOf(\RuntimeException::class, new UnableToCreateTransliteratorException('')); + $this->assertInstanceOf(\RuntimeException::class, new UnableToTransliterateException('')); + $this->assertInstanceOf(\RuntimeException::class, new UnsupportedTransliteratorIdentifierException('')); + } } From 20930ebbcd031d7fd9a2e351d88106ea926eabd6 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Mon, 1 Feb 2021 13:04:25 +0500 Subject: [PATCH 12/17] integrate circleci --- .circleci/config.yml | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..dd89dfb --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,55 @@ +# PHP CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-php/ for more details +# +version: 2 +jobs: + php71: + docker: + - image: circleci/php:7.1-cli-node-browsers + steps: + - checkout + - run: php -v + - run: composer install --no-interaction --prefer-source --no-suggest + - run: php vendor/bin/phpunit --colors=always + php72: + docker: + - image: circleci/php:7.2-cli-node-browsers + steps: + - checkout + - run: php -v + - run: composer install --no-interaction --prefer-source --no-suggest + - run: php vendor/bin/phpunit --colors=always + php73: + docker: + - image: circleci/php:7.3-cli-node-browsers + steps: + - checkout + - run: php -v + - run: composer install --no-interaction --prefer-source --no-suggest + - run: php vendor/bin/phpunit --colors=always + php74: + docker: + - image: circleci/php:7.4-cli-node-browsers + steps: + - checkout + - run: php -v + - run: composer install --no-interaction --prefer-source --no-suggest + - run: php vendor/bin/phpunit --colors=always + php80: + docker: + - image: circleci/php:8.0-cli-node-browsers + steps: + - checkout + - run: php -v + - run: composer install --no-interaction --prefer-source --no-suggest + - run: php vendor/bin/phpunit --colors=always +workflows: + version: 2 + build: + jobs: + - php71 + - php72 + - php73 + - php74 + - php80 From fa140e60ce06e091c94a3602104c6506644e13ec Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Mon, 1 Feb 2021 13:09:46 +0500 Subject: [PATCH 13/17] update README.md --- README.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0b4f77a..fa41528 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,11 @@ # Simple slugger for PHP 7.1+ (incl. PHP8) based on ICU [![Gitter](https://badges.gitter.im/sunrise-php/support.png)](https://gitter.im/sunrise-php/support) -[![Build Status](https://api.travis-ci.com/sunrise-php/slugger.svg?branch=master)](https://travis-ci.com/sunrise-php/slugger) -[![CodeFactor](https://www.codefactor.io/repository/github/sunrise-php/slugger/badge)](https://www.codefactor.io/repository/github/sunrise-php/slugger) -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/sunrise-php/slugger/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/sunrise-php/slugger/?branch=master) +[![Build Status](https://circleci.com/gh/sunrise-php/slugger.svg?style=shield)](https://circleci.com/gh/sunrise-php/slugger) [![Code Coverage](https://scrutinizer-ci.com/g/sunrise-php/slugger/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/sunrise-php/slugger/?branch=master) -[![Latest Stable Version](https://poser.pugx.org/sunrise/slugger/v/stable?format=flat)](https://packagist.org/packages/sunrise/slugger) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/sunrise-php/slugger/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/sunrise-php/slugger/?branch=master) [![Total Downloads](https://poser.pugx.org/sunrise/slugger/downloads?format=flat)](https://packagist.org/packages/sunrise/slugger) +[![Latest Stable Version](https://poser.pugx.org/sunrise/slugger/v/stable?format=flat)](https://packagist.org/packages/sunrise/slugger) [![License](https://poser.pugx.org/sunrise/slugger/license?format=flat)](https://packagist.org/packages/sunrise/slugger) ## Awards @@ -26,7 +25,7 @@ composer require sunrise/slugger ```php $slugger = new \Sunrise\Slugger\Slugger(); -// "syesh-yeshche-etikh-myagkikh-frantsuzskikh-bulok-da-vypey-chayu" +// syesh-yeshche-etikh-myagkikh-frantsuzskikh-bulok-da-vypey-chayu $slugger->slugify('Съешь ещё этих мягких французских булок, да выпей чаю'); ``` @@ -36,7 +35,7 @@ $slugger->slugify('Съешь ещё этих мягких французски $slugger = new \Sunrise\Slugger\Slugger(); $slugger->setTransliteratorId('de-ASCII'); -// "falsches-ueben-von-xylophonmusik-quaelt-jeden-groesseren-zwerg" +// falsches-ueben-von-xylophonmusik-quaelt-jeden-groesseren-zwerg $slugger->slugify('Falsches Üben von Xylophonmusik quält jeden größeren Zwerg'); ``` @@ -46,7 +45,7 @@ $slugger->slugify('Falsches Üben von Xylophonmusik quält jeden größeren Zwer $slugger = new \Sunrise\Slugger\Slugger(); $slugger->setTransliteratorId('Hiragana-Latin'); -// "irohanihoheto chirinuruwo wakayotareso tsunenaramu uwinookuyama kefukoete asakiyumemishi wehimosesu" +// irohanihoheto chirinuruwo wakayotareso tsunenaramu uwinookuyama kefukoete asakiyumemishi wehimosesu $slugger->transliterate('いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす', ''); ``` @@ -56,17 +55,19 @@ $slugger->transliterate('いろはにほへと ちりぬるを わかよたれ $slugger = new \Sunrise\Slugger\Slugger(); $slugger->setTransliteratorId('Greek-Latin/BGN'); -// "takhisti alopix vafis psimeni yi dhraskelizi iper nothrou kinos" +// takhisti alopix vafis psimeni yi dhraskelizi iper nothrou kinos $slugger->transliterate('Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός', 'Any-Latin; Latin-ASCII; Lower(); [^\x20\x30-\x39\x41-\x5A\x61-\x7A] Remove'); ``` #### Using DI Container ```php -$di['slugger'] = function() : \Sunrise\Slugger\SluggerInterface { - $slugger = new \Sunrise\Slugger\Slugger(); - $slugger->setTransliteratorId('de-ASCII'); +use Sunrise\Slugger\Slugger; +use Sunrise\Slugger\SluggerInterface; +$di['slugger'] = function () : SluggerInterface { + $slugger = new Slugger(); + $slugger->setTransliteratorId('de-ASCII'); return $slugger; }; From a1d6e14c30481d0d9cc61eca64139916e65beee8 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Mon, 1 Feb 2021 20:40:22 +0500 Subject: [PATCH 14/17] update README.md --- README.md | 44 ++++++-------------------------------------- 1 file changed, 6 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index fa41528..49169d5 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,9 @@ composer require sunrise/slugger #### Russian to Latin (default) ```php -$slugger = new \Sunrise\Slugger\Slugger(); +use Sunrise\Slugger\Slugger; + +$slugger = new Slugger(); // syesh-yeshche-etikh-myagkikh-frantsuzskikh-bulok-da-vypey-chayu $slugger->slugify('Съешь ещё этих мягких французских булок, да выпей чаю'); @@ -31,47 +33,13 @@ $slugger->slugify('Съешь ещё этих мягких французски #### Deutsch to Latin -```php -$slugger = new \Sunrise\Slugger\Slugger(); -$slugger->setTransliteratorId('de-ASCII'); - -// falsches-ueben-von-xylophonmusik-quaelt-jeden-groesseren-zwerg -$slugger->slugify('Falsches Üben von Xylophonmusik quält jeden größeren Zwerg'); -``` - -#### Only transliteration - -```php -$slugger = new \Sunrise\Slugger\Slugger(); -$slugger->setTransliteratorId('Hiragana-Latin'); - -// irohanihoheto chirinuruwo wakayotareso tsunenaramu uwinookuyama kefukoete asakiyumemishi wehimosesu -$slugger->transliterate('いろはにほへと ちりぬるを わかよたれそ つねならむ うゐのおくやま けふこえて あさきゆめみし ゑひもせす', ''); -``` - -#### Customization - -```php -$slugger = new \Sunrise\Slugger\Slugger(); -$slugger->setTransliteratorId('Greek-Latin/BGN'); - -// takhisti alopix vafis psimeni yi dhraskelizi iper nothrou kinos -$slugger->transliterate('Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός', 'Any-Latin; Latin-ASCII; Lower(); [^\x20\x30-\x39\x41-\x5A\x61-\x7A] Remove'); -``` - -#### Using DI Container - ```php use Sunrise\Slugger\Slugger; -use Sunrise\Slugger\SluggerInterface; -$di['slugger'] = function () : SluggerInterface { - $slugger = new Slugger(); - $slugger->setTransliteratorId('de-ASCII'); - return $slugger; -}; +$slugger = new Slugger('de-ASCII'); -$di['slugger']->slugify('Zwölf große Boxkämpfer jagen Viktor quer über den Sylter Deich.'); +// falsches-ueben-von-xylophonmusik-quaelt-jeden-groesseren-zwerg +$slugger->slugify('Falsches Üben von Xylophonmusik quält jeden größeren Zwerg'); ``` ## Useful links From effd00fbaa77820f04f65148d02a59265c8c2287 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Mon, 1 Feb 2021 20:40:58 +0500 Subject: [PATCH 15/17] general exception --- src/Exception/Exception.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/Exception/Exception.php diff --git a/src/Exception/Exception.php b/src/Exception/Exception.php new file mode 100644 index 0000000..1e4d11e --- /dev/null +++ b/src/Exception/Exception.php @@ -0,0 +1,24 @@ + + * @copyright Copyright (c) 2018, Anatoly Fenric + * @license https://github.com/sunrise-php/slugger/blob/master/LICENSE + * @link https://github.com/sunrise-php/slugger + */ + +namespace Sunrise\Slugger\Exception; + +/** + * Import classes + */ +use RuntimeException; + +/** + * Exception + */ +class Exception extends RuntimeException +{ +} From 0b09a2a5bb15c6cae9360ffbad4c468b55d2c551 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Mon, 1 Feb 2021 20:42:11 +0500 Subject: [PATCH 16/17] v2 --- .../UnableToCreateTransliteratorException.php | 7 +- .../UnableToTransliterateException.php | 7 +- src/Slugger.php | 104 +++--------- tests/SluggerTest.php | 155 ++++++++---------- 4 files changed, 93 insertions(+), 180 deletions(-) diff --git a/src/Exception/UnableToCreateTransliteratorException.php b/src/Exception/UnableToCreateTransliteratorException.php index 6713383..e593250 100644 --- a/src/Exception/UnableToCreateTransliteratorException.php +++ b/src/Exception/UnableToCreateTransliteratorException.php @@ -11,14 +11,9 @@ namespace Sunrise\Slugger\Exception; -/** - * Import classes - */ -use RuntimeException; - /** * UnableToCreateTransliteratorException */ -class UnableToCreateTransliteratorException extends RuntimeException +class UnableToCreateTransliteratorException extends Exception { } diff --git a/src/Exception/UnableToTransliterateException.php b/src/Exception/UnableToTransliterateException.php index 2a1b392..2cf424e 100644 --- a/src/Exception/UnableToTransliterateException.php +++ b/src/Exception/UnableToTransliterateException.php @@ -11,14 +11,9 @@ namespace Sunrise\Slugger\Exception; -/** - * Import classes - */ -use RuntimeException; - /** * UnableToTransliterateException */ -class UnableToTransliterateException extends RuntimeException +class UnableToTransliterateException extends Exception { } diff --git a/src/Slugger.php b/src/Slugger.php index 73957d4..f84f5b3 100644 --- a/src/Slugger.php +++ b/src/Slugger.php @@ -11,105 +11,52 @@ namespace Sunrise\Slugger; +/** + * Import classes + */ +use Transliterator; +use Sunrise\Slugger\Exception\UnableToCreateTransliteratorException; +use Sunrise\Slugger\Exception\UnableToTransliterateException; + /** * Import functions */ -use function in_array; use function preg_replace; -use function sprintf; use function str_replace; -use function transliterator_create; -use function transliterator_list_ids; -use function transliterator_transliterate; use function trim; /** * Slugger - * - * @link http://userguide.icu-project.org/transforms/general */ class Slugger implements SluggerInterface { /** - * The transliterator ID + * Transliterator instance * - * @var string + * @var Transliterator */ - protected $transliteratorId = 'Russian-Latin/BGN'; + private $transliterator; /** - * Sets the transliterator ID - * - * @param string $transliteratorId + * Constructor of the class * - * @return void + * @param string $basicId * - * @throws Exception\UnsupportedTransliteratorIdentifierException - * - * @link http://userguide.icu-project.org/transforms/general#TOC-Basic-IDs + * @throws UnableToCreateTransliteratorException */ - public function setTransliteratorId(string $transliteratorId) : void + public function __construct(string $basicId = 'Russian-Latin/BGN') { - $supportedTransliteratorIds = $this->getSupportedTransliteratorIds(); - if (!in_array($transliteratorId, $supportedTransliteratorIds)) { - throw new Exception\UnsupportedTransliteratorIdentifierException( - sprintf('The transliterator ID "%s" is not supported', $transliteratorId) - ); - } - - $this->transliteratorId = $transliteratorId; - } + // http://userguide.icu-project.org/transforms/general#TOC-Basic-IDs + // http://userguide.icu-project.org/transforms/general#TOC-Compound-IDs + $compoundIds = $basicId . '; Any-Latin; Latin-ASCII; Lower(); [^\x20\x30-\x39\x41-\x5A\x61-\x7A] Remove'; - /** - * Gets the transliterator ID - * - * @return string - */ - public function getTransliteratorId() : string - { - return $this->transliteratorId; - } - - /** - * Gets supported transliterator IDs - * - * @return string[] - */ - public function getSupportedTransliteratorIds() : array - { - return transliterator_list_ids(); - } - - /** - * Transliterates the given string using the given compound - * - * @param string $string - * @param string $compound - * - * @return string - * - * @throws Exception\UnableToCreateTransliteratorException - * @throws Exception\UnableToTransliterateException - */ - public function transliterate(string $string, string $compound) : string - { - $compound = $this->getTransliteratorId() . '; ' . $compound; - $transliterator = transliterator_create($compound); + $transliterator = Transliterator::create($compoundIds, Transliterator::FORWARD); if (null === $transliterator) { - throw new Exception\UnableToCreateTransliteratorException( - sprintf('Unable to create transliterator with compound "%s"', $compound) - ); - } - - $transliterated = transliterator_transliterate($transliterator, $string); - if (false === $transliterated) { - throw new Exception\UnableToTransliterateException( - sprintf('Unable to transliterate string with compound "%s"', $compound) - ); + throw new UnableToCreateTransliteratorException('Unable to create transliterator'); } - return $transliterated; + $this->transliterator = $transliterator; } /** @@ -120,15 +67,16 @@ public function transliterate(string $string, string $compound) : string * * @return string * - * @throws Exception\UnableToCreateTransliteratorException - * @throws Exception\UnableToTransliterateException + * @throws UnableToTransliterateException */ public function slugify(string $string, string $delimiter = '-') : string { - $compound = 'Any-Latin; Latin-ASCII; Lower(); [^\x20\x30-\x39\x41-\x5A\x61-\x7A] Remove'; + $transliteratedString = $this->transliterator->transliterate($string); + if (false === $transliteratedString) { + throw new UnableToTransliterateException('Unable to transliterate'); + } - $slug = $this->transliterate($string, $compound); - $slug = preg_replace('/[\x20]{2,}/', ' ', $slug); + $slug = preg_replace('/[\x20]{2,}/', ' ', $transliteratedString); $slug = trim($slug); $slug = str_replace(' ', $delimiter, $slug); diff --git a/tests/SluggerTest.php b/tests/SluggerTest.php index d7bbadc..f4a9c75 100644 --- a/tests/SluggerTest.php +++ b/tests/SluggerTest.php @@ -1,147 +1,122 @@ -assertInstanceOf(SluggerInterface::class, $slugger); - } - - public function testTransliteratorId() - { - $slugger = new Slugger(); - - $slugger->setTransliteratorId(self::RUSSIAN_LATIN_TRANSLITERATOR_ID); - $this->assertEquals(self::RUSSIAN_LATIN_TRANSLITERATOR_ID, $slugger->getTransliteratorId()); - - $slugger->setTransliteratorId(self::CYRILLIC_LATIN_TRANSLITERATOR_ID); - $this->assertEquals(self::CYRILLIC_LATIN_TRANSLITERATOR_ID, $slugger->getTransliteratorId()); - } - - public function testDefaultTransliteratorId() - { - $slugger = new Slugger(); + /** + * @var string + */ + private const RUSSIAN_LATIN_TRANSLITERATOR_BASIC_ID = 'Russian-Latin/BGN'; - $this->assertEquals(self::RUSSIAN_LATIN_TRANSLITERATOR_ID, $slugger->getTransliteratorId()); - } - - public function testUnsupportedTransliterationId() - { - $this->expectException(UnsupportedTransliteratorIdentifierException::class); - $this->expectExceptionMessage('The transliterator ID "Morrowind-Oblivion/KFC" is not supported'); - - $slugger = new Slugger(); - - $slugger->setTransliteratorId('Morrowind-Oblivion/KFC'); - } + /** + * @var string + */ + private const CYRILLIC_LATIN_TRANSLITERATOR_BASIC_ID = 'Cyrillic-Latin'; - public function testSupportedTransliteratorIds() + /** + * @return void + */ + public function testConstructor() : void { $slugger = new Slugger(); - $this->assertEquals(\transliterator_list_ids(), $slugger->getSupportedTransliteratorIds()); - } - - public function testTransliterateRussianLatin() - { - $input = 'съешь ещё этих мягких французских булок, да выпей чаю'; - $output = 'syesh yeshche etikh myagkikh frantsuzskikh bulok da vypey chayu'; - $compound = 'Any-Latin; Latin-ASCII; [^\x20\x41-\x5A\x61-\x7A] Remove'; - - $slugger = new Slugger(); - $slugger->setTransliteratorId(self::RUSSIAN_LATIN_TRANSLITERATOR_ID); - - $this->assertEquals($output, $slugger->transliterate($input, $compound)); + $this->assertInstanceOf(SluggerInterface::class, $slugger); } - public function testTransliterateCyrillicLatin() + /** + * @return void + */ + public function testConstructorWithUnsupportedTransliteratorBasicId() : void { - $input = 'съешь ещё этих мягких французских булок, да выпей чаю'; - $output = 'ses ese etih magkih francuzskih bulok da vypej cau'; - $compound = 'Any-Latin; Latin-ASCII; [^\x20\x41-\x5A\x61-\x7A] Remove'; - - $slugger = new Slugger(); - $slugger->setTransliteratorId(self::CYRILLIC_LATIN_TRANSLITERATOR_ID); + $this->expectException(UnableToCreateTransliteratorException::class); + $this->expectExceptionMessage('Unable to create transliterator'); - $this->assertEquals($output, $slugger->transliterate($input, $compound)); + new Slugger('Morrowind-Oblivion/KFC'); } - public function testSlugifyRussianLatin() + /** + * @return void + */ + public function testSlugify() : void { $input = 'съешь ещё этих мягких французских булок, да выпей чаю'; $output = 'syesh-yeshche-etikh-myagkikh-frantsuzskikh-bulok-da-vypey-chayu'; - $slugger = new Slugger(); - $slugger->setTransliteratorId(self::RUSSIAN_LATIN_TRANSLITERATOR_ID); - $this->assertEquals($output, $slugger->slugify($input)); } - public function testSlugifyCyrillicLatin() + /** + * @return void + */ + public function testSlugifyWithNumbers() : void { - $input = 'съешь ещё этих мягких французских булок, да выпей чаю'; - $output = 'ses-ese-etih-magkih-francuzskih-bulok-da-vypej-cau'; - + $input = '0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz'; + $output = '0123456789-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz'; $slugger = new Slugger(); - $slugger->setTransliteratorId(self::CYRILLIC_LATIN_TRANSLITERATOR_ID); - $this->assertEquals($output, $slugger->slugify($input)); } - public function testSlugifyWithDelimiter() + /** + * @return void + */ + public function testSlugifyWithDelimiter() : void { $input = ' А Б В '; $output = 'a_b_v'; - $slugger = new Slugger(); - $slugger->setTransliteratorId(self::RUSSIAN_LATIN_TRANSLITERATOR_ID); - $this->assertEquals($output, $slugger->slugify($input, '_')); } - public function testSlugifyWithNumbers() + /** + * @return void + */ + public function testSlugifyWithRussianLatinTransliteratorBasicId() : void { - $input = '0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz'; - $output = '0123456789-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz'; - - $slugger = new Slugger(); + $input = 'съешь ещё этих мягких французских булок, да выпей чаю'; + $output = 'syesh-yeshche-etikh-myagkikh-frantsuzskikh-bulok-da-vypey-chayu'; + $slugger = new Slugger(self::RUSSIAN_LATIN_TRANSLITERATOR_BASIC_ID); $this->assertEquals($output, $slugger->slugify($input)); } - public function testTransliterateWithInvalidCompound() + /** + * @return void + */ + public function testSlugifyWithCyrillicLatinTransliteratorBasicId() : void { - $expectedMessage = 'Unable to create transliterator with compound "Russian-Latin/BGN; UndefinedCommand()"'; - - $this->expectException(UnableToCreateTransliteratorException::class); - $this->expectExceptionMessage($expectedMessage); - - $slugger = new Slugger(); + $input = 'съешь ещё этих мягких французских булок, да выпей чаю'; + $output = 'ses-ese-etih-magkih-francuzskih-bulok-da-vypej-cau'; + $slugger = new Slugger(self::CYRILLIC_LATIN_TRANSLITERATOR_BASIC_ID); - $slugger->transliterate('', 'UndefinedCommand()'); + $this->assertEquals($output, $slugger->slugify($input)); } - public function testExceptions() + /** + * @return void + */ + public function testExceptions() : void { - $this->assertInstanceOf(\RuntimeException::class, new UnableToCreateTransliteratorException('')); - $this->assertInstanceOf(\RuntimeException::class, new UnableToTransliterateException('')); - $this->assertInstanceOf(\RuntimeException::class, new UnsupportedTransliteratorIdentifierException('')); + $this->assertInstanceOf(\RuntimeException::class, new Exception()); + $this->assertInstanceOf(Exception::class, new UnableToCreateTransliteratorException()); + $this->assertInstanceOf(Exception::class, new UnableToTransliterateException()); } } From dd852dcb34ec4b0ed4176b3d95ca44c7bc68821e Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Mon, 1 Feb 2021 20:42:24 +0500 Subject: [PATCH 17/17] delete --- ...ortedTransliteratorIdentifierException.php | 24 ------------------- 1 file changed, 24 deletions(-) delete mode 100644 src/Exception/UnsupportedTransliteratorIdentifierException.php diff --git a/src/Exception/UnsupportedTransliteratorIdentifierException.php b/src/Exception/UnsupportedTransliteratorIdentifierException.php deleted file mode 100644 index 41173e4..0000000 --- a/src/Exception/UnsupportedTransliteratorIdentifierException.php +++ /dev/null @@ -1,24 +0,0 @@ - - * @copyright Copyright (c) 2018, Anatoly Fenric - * @license https://github.com/sunrise-php/slugger/blob/master/LICENSE - * @link https://github.com/sunrise-php/slugger - */ - -namespace Sunrise\Slugger\Exception; - -/** - * Import classes - */ -use RuntimeException; - -/** - * UnsupportedTransliteratorIdentifierException - */ -class UnsupportedTransliteratorIdentifierException extends RuntimeException -{ -}