From fa52e6223eef2f19fbd0a290432b5a878317dca2 Mon Sep 17 00:00:00 2001 From: Norbert Orzechowicz Date: Wed, 8 Jul 2020 14:28:58 +0200 Subject: [PATCH] Fixxed issue with symfony translator dependency, upgraded php, phpunit and phpspec dependencies --- .gitignore | 2 +- .travis.yml | 1 + README.md | 6 ++-- composer.json | 18 ++++++------ .../PHPHumanizer/Collection/FormatterSpec.php | 3 +- .../PHPHumanizer/Collection/OxfordSpec.php | 2 +- .../PHPHumanizer/DateTime/FormatterSpec.php | 10 +++---- .../DateTime/PreciseFormatterSpec.php | 16 ++++------- .../PHPHumanizer/Collection/Formatter.php | 6 ++-- src/Coduo/PHPHumanizer/DateTime/Formatter.php | 7 ++--- .../DateTime/PreciseFormatter.php | 7 ++--- .../PHPHumanizer/Number/RomanNumeral.php | 4 +-- .../Tests/CollectionHumanizerTest.php | 3 +- .../Tests/DateTimeHumanizerTest.php | 3 +- .../Tests/NumberHumanizerTest.php | 28 +++++++++---------- .../Tests/StringHumanizerTest.php | 4 +-- 16 files changed, 56 insertions(+), 64 deletions(-) diff --git a/.gitignore b/.gitignore index f0bf8a2..e0a7c66 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ vendor/ bin/ composer.lock composer.phar -.php_cs.cache \ No newline at end of file +*.cache \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index dd1b745..2d6b0e9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ matrix: - php: 7.1 - php: 7.2 - php: 7.3 + - php: 7.4 before_install: - composer self-update diff --git a/README.md b/README.md index 5546d71..49c184c 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ # PHP Humanizer -[![Build Status](https://travis-ci.com/coduo/php-humanizer.svg?branch=master)](https://travis-ci.com/coduo/php-humanizer) +[![Build Status](https://travis-ci.com/coduo/php-humanizer.svg?branch=4.x)](https://travis-ci.com/coduo/php-humanizer) [![Latest Stable Version](https://poser.pugx.org/coduo/php-humanizer/v/stable)](https://packagist.org/packages/coduo/php-humanizer) [![Total Downloads](https://poser.pugx.org/coduo/php-humanizer/downloads)](https://packagist.org/packages/coduo/php-humanizer) [![Latest Unstable Version](https://poser.pugx.org/coduo/php-humanizer/v/unstable)](https://packagist.org/packages/coduo/php-humanizer) [![License](https://poser.pugx.org/coduo/php-humanizer/license)](https://packagist.org/packages/coduo/php-humanizer) ### Tests -* [![Build Status](https://travis-ci.com/coduo/php-humanizer.svg?branch=master)](https://travis-ci.com/coduo/php-humanizer) - master (3.1) +* [![Build Status](https://travis-ci.com/coduo/php-humanizer.svg?branch=4.x)](https://travis-ci.com/coduo/php-humanizer) - 4.x * [![Build Status](https://travis-ci.com/coduo/php-humanizer.svg?branch=3.0)](https://travis-ci.com/coduo/php-humanizer) - 3.0 -[Readme for master (3.1) version](https://github.com/coduo/php-humanizer/tree/master/README.md) +[Readme for 4.x version](https://github.com/coduo/php-humanizer/tree/4.x/README.md) [Readme for 3.0 version](https://github.com/coduo/php-humanizer/tree/3.0/README.md) diff --git a/composer.json b/composer.json index 9159b28..098b493 100644 --- a/composer.json +++ b/composer.json @@ -15,16 +15,16 @@ } ], "require": { - "php": ">=7.0.0", - "symfony/config": "^2.3|^3.0|^4|^5", - "symfony/translation": "^2.3|^3.0|^4|^5", - "symfony/yaml": "^2.3|^3.0|^4|^5" + "php": ">=7.3", + "symfony/config": "^4.4|^5.0", + "symfony/translation": "^4.4|^5.0", + "symfony/yaml": "^4.4|^5.0" }, "require-dev": { "thunderer/shortcode": "^0.7", - "phpspec/phpspec": "^2", - "phpunit/phpunit": "^4.5|^5.0", - "friendsofphp/php-cs-fixer": "^2.14" + "phpspec/phpspec": "^6.0", + "phpunit/phpunit": "^8.4", + "friendsofphp/php-cs-fixer": "^2.16" }, "config": { "bin-dir": "bin" @@ -36,12 +36,12 @@ }, "autoload-dev": { "psr-4": { - "Coduo\\PHPHumanizer\\Tests\\": "tests/" + "": "tests/" } }, "extra": { "branch-alias": { - "dev-master": "3.1-dev" + "dev-master": "4.0-dev" } }, "suggest": { diff --git a/spec/Coduo/PHPHumanizer/Collection/FormatterSpec.php b/spec/Coduo/PHPHumanizer/Collection/FormatterSpec.php index 81164ef..e7bc4a8 100644 --- a/spec/Coduo/PHPHumanizer/Collection/FormatterSpec.php +++ b/spec/Coduo/PHPHumanizer/Collection/FormatterSpec.php @@ -17,9 +17,8 @@ function let(Translator $translator) 'oxford' )->willReturn('Michal and Norbert'); - $translator->transChoice( + $translator->trans( 'comma_separated_with_limit', - 1, array('%count%' => 1, "%list%" => 'Michal, Norbert'), 'oxford' )->willReturn('Michal, Norbert and 1 more'); diff --git a/spec/Coduo/PHPHumanizer/Collection/OxfordSpec.php b/spec/Coduo/PHPHumanizer/Collection/OxfordSpec.php index 0a6b56f..536e4d3 100644 --- a/spec/Coduo/PHPHumanizer/Collection/OxfordSpec.php +++ b/spec/Coduo/PHPHumanizer/Collection/OxfordSpec.php @@ -5,7 +5,7 @@ use Coduo\PHPHumanizer\Collection\Formatter; use PhpSpec\ObjectBehavior; use Prophecy\Argument; -use Symfony\Component\Translation\TranslatorInterface; +use Symfony\Contracts\Translation\TranslatorInterface; class OxfordSpec extends ObjectBehavior { diff --git a/spec/Coduo/PHPHumanizer/DateTime/FormatterSpec.php b/spec/Coduo/PHPHumanizer/DateTime/FormatterSpec.php index 4bf48ae..1372ad3 100644 --- a/spec/Coduo/PHPHumanizer/DateTime/FormatterSpec.php +++ b/spec/Coduo/PHPHumanizer/DateTime/FormatterSpec.php @@ -13,17 +13,15 @@ class FormatterSpec extends ObjectBehavior function let(Translator $translator) { $this->beConstructedWith($translator); - $translator->transChoice( + $translator->trans( 'minute.past', - 10, array('%count%' => 10), 'difference', 'en' )->willReturn('10 minutes ago'); - $translator->transChoice( + $translator->trans( 'minute.past', - 10, array('%count%' => 10), 'difference', 'pl' @@ -36,7 +34,7 @@ function it_format_datetime_diff() new \DateTime("2015-01-01 00:10:00"), new \DateTime("2015-01-01 00:00:00") ); - + $this->formatDifference($diff)->shouldReturn('10 minutes ago'); } @@ -46,7 +44,7 @@ function it_format_datetime_diff_for_specific_locale() new \DateTime("2015-01-01 00:10:00"), new \DateTime("2015-01-01 00:00:00") ); - + $this->formatDifference($diff, 'pl')->shouldReturn('10 minut temu'); } } diff --git a/spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php b/spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php index 1ecf75e..5228235 100644 --- a/spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php +++ b/spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php @@ -15,17 +15,15 @@ class PreciseFormatterSpec extends ObjectBehavior function let(Translator $translator) { $this->beConstructedWith($translator); - $translator->transChoice( + $translator->trans( 'compound.day', - 10, array('%count%' => 10), 'difference', 'en' )->willReturn('10 days'); - $translator->transChoice( + $translator->trans( 'compound.hour', - 5, array('%count%' => 5), 'difference', 'en' @@ -38,17 +36,15 @@ function let(Translator $translator) 'en' )->willReturn('10 days, 5 hours from now'); - $translator->transChoice( + $translator->trans( 'compound.day', - 10, array('%count%' => 10), 'difference', 'ru' )->willReturn('10 дней'); - $translator->transChoice( + $translator->trans( 'compound.hour', - 5, array('%count%' => 5), 'difference', 'ru' @@ -66,7 +62,7 @@ function it_format_compound_datetime_diff() { $diff = new PreciseDifference( new \DateTime("2015-01-01 00:00:00"), - new \DateTime("2015-01-11 05:00:00") + new \DateTime("2015-01-11 05:00:00") ); $this->formatDifference($diff)->shouldReturn('10 days, 5 hours from now'); @@ -78,7 +74,7 @@ function it_format_compound_datetime_diff_for_specific_locale() new \DateTime("2015-01-01 00:00:00"), new \DateTime("2015-01-11 05:00:00") ); - + $this->formatDifference($diff, 'ru')->shouldReturn('через 10 дней, 5 часов'); } } diff --git a/src/Coduo/PHPHumanizer/Collection/Formatter.php b/src/Coduo/PHPHumanizer/Collection/Formatter.php index ec28b4b..aa0798a 100644 --- a/src/Coduo/PHPHumanizer/Collection/Formatter.php +++ b/src/Coduo/PHPHumanizer/Collection/Formatter.php @@ -11,12 +11,12 @@ namespace Coduo\PHPHumanizer\Collection; -use Symfony\Component\Translation\TranslatorInterface; +use Symfony\Contracts\Translation\TranslatorInterface; final class Formatter { /** - * @var \Symfony\Component\Translation\TranslatorInterface + * @var TranslatorInterface */ private $translator; @@ -72,7 +72,7 @@ private function formatCommaSeparatedWithLimit($collection, $limit, $count) $moreCount = $count - \count($display); - return $this->translator->transChoice('comma_separated_with_limit', $moreCount, [ + return $this->translator->trans('comma_separated_with_limit', [ '%list%' => \implode(', ', $display), '%count%' => $moreCount, ], $this->catalogue); diff --git a/src/Coduo/PHPHumanizer/DateTime/Formatter.php b/src/Coduo/PHPHumanizer/DateTime/Formatter.php index 781fc3d..a5d7c2f 100644 --- a/src/Coduo/PHPHumanizer/DateTime/Formatter.php +++ b/src/Coduo/PHPHumanizer/DateTime/Formatter.php @@ -11,12 +11,12 @@ namespace Coduo\PHPHumanizer\DateTime; -use Symfony\Component\Translation\TranslatorInterface; +use Symfony\Contracts\Translation\TranslatorInterface; final class Formatter { /** - * @var \Symfony\Component\Translation\TranslatorInterface + * @var TranslatorInterface */ private $translator; @@ -38,9 +38,8 @@ public function formatDifference(Difference $difference, $locale = 'en') { $translationKey = \sprintf('%s.%s', $difference->getUnit()->getName(), $difference->isPast() ? 'past' : 'future'); - return $this->translator->transChoice( + return $this->translator->trans( $translationKey, - $difference->getQuantity(), ['%count%' => $difference->getQuantity()], 'difference', $locale diff --git a/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php b/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php index 66800a1..a47fe67 100644 --- a/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php +++ b/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php @@ -11,12 +11,12 @@ namespace Coduo\PHPHumanizer\DateTime; -use Symfony\Component\Translation\TranslatorInterface; +use Symfony\Contracts\Translation\TranslatorInterface; final class PreciseFormatter { /** - * @var \Symfony\Component\Translation\TranslatorInterface + * @var TranslatorInterface */ private $translator; @@ -39,9 +39,8 @@ public function formatDifference(PreciseDifference $difference, $locale = 'en') $diff = []; foreach ($difference->getCompoundResults() as $result) { - $diff[] = $this->translator->transChoice( + $diff[] = $this->translator->trans( 'compound.'.$result->getUnit()->getName(), - $result->getQuantity(), ['%count%' => $result->getQuantity()], 'difference', $locale diff --git a/src/Coduo/PHPHumanizer/Number/RomanNumeral.php b/src/Coduo/PHPHumanizer/Number/RomanNumeral.php index 745c60c..4e184a9 100644 --- a/src/Coduo/PHPHumanizer/Number/RomanNumeral.php +++ b/src/Coduo/PHPHumanizer/Number/RomanNumeral.php @@ -78,10 +78,10 @@ public function fromRoman($string) $i = \mb_strlen($string); while ($i > 0) { - $digit = $this->map[$string{--$i}]; + $digit = $this->map[$string[--$i]]; if ($i > 0) { - $previousDigit = $this->map[$string{$i - 1}]; + $previousDigit = $this->map[$string[$i - 1]]; if ($previousDigit < $digit) { $digit -= $previousDigit; diff --git a/tests/Coduo/PHPHumanizer/Tests/CollectionHumanizerTest.php b/tests/Coduo/PHPHumanizer/Tests/CollectionHumanizerTest.php index 29933a9..0753e23 100644 --- a/tests/Coduo/PHPHumanizer/Tests/CollectionHumanizerTest.php +++ b/tests/Coduo/PHPHumanizer/Tests/CollectionHumanizerTest.php @@ -12,8 +12,9 @@ namespace Coduo\PHPHumanizer\Tests; use Coduo\PHPHumanizer\CollectionHumanizer; +use PHPUnit\Framework\TestCase; -final class CollectionHumanizerTest extends \PHPUnit_Framework_TestCase +final class CollectionHumanizerTest extends TestCase { /** * @dataProvider oxfordCollectionProvider diff --git a/tests/Coduo/PHPHumanizer/Tests/DateTimeHumanizerTest.php b/tests/Coduo/PHPHumanizer/Tests/DateTimeHumanizerTest.php index efa9d95..a50a16d 100644 --- a/tests/Coduo/PHPHumanizer/Tests/DateTimeHumanizerTest.php +++ b/tests/Coduo/PHPHumanizer/Tests/DateTimeHumanizerTest.php @@ -12,8 +12,9 @@ namespace Coduo\PHPHumanizer\Tests; use Coduo\PHPHumanizer\DateTimeHumanizer; +use PHPUnit\Framework\TestCase; -class DateTimeHumanizerTest extends \PHPUnit_Framework_TestCase +class DateTimeHumanizerTest extends TestCase { /** * @test diff --git a/tests/Coduo/PHPHumanizer/Tests/NumberHumanizerTest.php b/tests/Coduo/PHPHumanizer/Tests/NumberHumanizerTest.php index ae40dbc..a0a9847 100644 --- a/tests/Coduo/PHPHumanizer/Tests/NumberHumanizerTest.php +++ b/tests/Coduo/PHPHumanizer/Tests/NumberHumanizerTest.php @@ -12,8 +12,9 @@ namespace Coduo\PHPHumanizer\Tests; use Coduo\PHPHumanizer\NumberHumanizer; +use PHPUnit\Framework\TestCase; -class NumberHumanizerTest extends \PHPUnit_Framework_TestCase +class NumberHumanizerTest extends TestCase { /** * @dataProvider ordinalIndicatorProvider @@ -184,11 +185,9 @@ public function test_convert_number_to_string_with_binary_suffix($expected, $num $this->assertEquals($expected, NumberHumanizer::binarySuffix($number, $locale)); } - /** - * @expectedException \InvalidArgumentException - */ public function test_statically_throw_exception_when_converting_to_string_with_binary_suffix_non_numeric_values() { + $this->expectException(\InvalidArgumentException::class); NumberHumanizer::binarySuffix('as12'); } @@ -205,19 +204,17 @@ public function test_convert_number_to_string_with_precise_binary_suffix($expect $this->assertEquals($expected, NumberHumanizer::preciseBinarySuffix($number, $precision, $locale)); } - /** - * @expectedException \InvalidArgumentException - */ public function test_statically_throw_exception_when_converting_to_string_with_precise_binary_suffix_negative_precision() { + $this->expectException(\InvalidArgumentException::class); + NumberHumanizer::preciseBinarySuffix(1, -1); } - /** - * @expectedException \InvalidArgumentException - */ public function test_statically_throw_exception_when_converting_to_string_with_precise_binary_suffix_large_precision() { + $this->expectException(\InvalidArgumentException::class); + NumberHumanizer::preciseBinarySuffix(1, 4); } @@ -233,11 +230,10 @@ public function test_convert_number_to_string_with_metric_suffix($expected, $num $this->assertEquals($expected, NumberHumanizer::metricSuffix($number, $locale)); } - /** - * @expectedException \InvalidArgumentException - */ public function test_statically_throw_exception_when_converting_to_string_with_metric_suffix_non_numeric_values() { + $this->expectException(\InvalidArgumentException::class); + NumberHumanizer::metricSuffix('as12'); } @@ -265,23 +261,25 @@ public function test_convert_roman_numbers_to_arabic($number, $expected) /** * @dataProvider romanExceptionProvider - * @expectedException \InvalidArgumentException * * @param $number */ public function test_statically_throw_exception_when_converting_number_is_out_of_range($number) { + $this->expectException(\InvalidArgumentException::class); + NumberHumanizer::toRoman($number); } /** * @dataProvider arabicExceptionProvider - * @expectedException \InvalidArgumentException * * @param $number */ public function test_statically_throw_exception_when_converting_roman_number_is_invalid($number) { + $this->expectException(\InvalidArgumentException::class); + NumberHumanizer::fromRoman($number); } diff --git a/tests/Coduo/PHPHumanizer/Tests/StringHumanizerTest.php b/tests/Coduo/PHPHumanizer/Tests/StringHumanizerTest.php index c3f1f51..6f318b3 100644 --- a/tests/Coduo/PHPHumanizer/Tests/StringHumanizerTest.php +++ b/tests/Coduo/PHPHumanizer/Tests/StringHumanizerTest.php @@ -12,9 +12,9 @@ namespace Coduo\PHPHumanizer\Tests; use Coduo\PHPHumanizer\StringHumanizer; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; -class StringHumanizerTest extends PHPUnit_Framework_TestCase +class StringHumanizerTest extends TestCase { /** * @dataProvider humanizeStringProvider