Skip to content

Commit

Permalink
Fixxed issue with symfony translator dependency, upgraded php, phpuni…
Browse files Browse the repository at this point in the history
…t and phpspec dependencies
  • Loading branch information
norberttech committed Jul 8, 2020
1 parent f989a91 commit fa52e62
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ vendor/
bin/
composer.lock
composer.phar
.php_cs.cache
*.cache
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ matrix:
- php: 7.1
- php: 7.2
- php: 7.3
- php: 7.4

before_install:
- composer self-update
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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": {
Expand Down
3 changes: 1 addition & 2 deletions spec/Coduo/PHPHumanizer/Collection/FormatterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion spec/Coduo/PHPHumanizer/Collection/OxfordSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
10 changes: 4 additions & 6 deletions spec/Coduo/PHPHumanizer/DateTime/FormatterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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');
}

Expand All @@ -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');
}
}
16 changes: 6 additions & 10 deletions spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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');
Expand All @@ -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 часов');
}
}
6 changes: 3 additions & 3 deletions src/Coduo/PHPHumanizer/Collection/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions src/Coduo/PHPHumanizer/DateTime/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
7 changes: 3 additions & 4 deletions src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Coduo/PHPHumanizer/Number/RomanNumeral.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion tests/Coduo/PHPHumanizer/Tests/CollectionHumanizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/Coduo/PHPHumanizer/Tests/DateTimeHumanizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 13 additions & 15 deletions tests/Coduo/PHPHumanizer/Tests/NumberHumanizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}

Expand All @@ -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);
}

Expand All @@ -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');
}

Expand Down Expand Up @@ -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);
}

Expand Down
Loading

0 comments on commit fa52e62

Please sign in to comment.