From 4c93e609c7a1a6b5908ed422c624897d0a8e3404 Mon Sep 17 00:00:00 2001 From: Samson Endale Date: Mon, 20 Feb 2017 01:52:07 +0300 Subject: [PATCH] Version 1.1 is ready * Bump up the PHP version * Bump up PHPUnit version * Used a PHP 5.6 Constant expressions * Fixed some typos * Added more tests * Updated the README.md file --- .travis.yml | 4 +-- README.md | 39 +++++++++++++++----------- composer.json | 4 +-- src/Converter/AsciiConverter.php | 2 +- src/Converter/Converter.php | 6 ++-- src/Converter/GeezConverter.php | 6 ++-- src/Helper/GeezCalculator.php | 4 +-- src/Helper/GeezParser.php | 2 +- tests/GeezifyTest.php | 48 ++++++++++++++++++++++++++++++++ tests/TestCase.php | 2 +- 10 files changed, 84 insertions(+), 33 deletions(-) diff --git a/.travis.yml b/.travis.yml index a1ae3ea..5c54fb1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,13 @@ language: php php: - - 5.4 - - 5.5 - 5.6 - 7.0 - 7.1 install: travis_retry composer install --no-interaction --prefer-source -script: phpunit --coverage-clover=coverage.clover +script: vendor/bin/phpunit --coverage-clover=coverage.clover after_script: - wget https://scrutinizer-ci.com/ocular.phar diff --git a/README.md b/README.md index 628a492..f0f0741 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -Andegna Geezify +Andegna Geezify ![From Ethiopia](https://img.shields.io/badge/From-Ethiopia-brightgreen.svg) =============== [![Build Status](https://travis-ci.org/andegna/geezify.svg?branch=master)](https://travis-ci.org/andegna/geezify) [![StyleCI](https://styleci.io/repos/68031629/shield?branch=master)](https://styleci.io/repos/68031629) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/andegna/geezify/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/andegna/geezify/?branch=master) -[![Code Coverage](https://scrutinizer-ci.com/g/andegna/geezify/badges/coverage.png?b=develop)](https://scrutinizer-ci.com/g/andegna/geezify/?branch=develop) +[![Code Coverage](https://scrutinizer-ci.com/g/andegna/geezify/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/andegna/geezify/?branch=master) [![Total Downloads](https://poser.pugx.org/andegna/geezify/d/total.svg)](https://packagist.org/packages/andegna/geezify) [![Latest Stable Version](https://poser.pugx.org/andegna/geezify/v/stable.svg)](https://packagist.org/packages/andegna/geezify) [![Latest Unstable Version](https://poser.pugx.org/andegna/geezify/v/unstable.svg)](https://packagist.org/packages/andegna/geezify) @@ -12,20 +12,27 @@ Andegna Geezify [![SensioLabsInsight](https://insight.sensiolabs.com/projects/a3519698-fee9-494c-adbb-c5c2f8abc422/big.png)](https://insight.sensiolabs.com/projects/a3519698-fee9-494c-adbb-c5c2f8abc422) -This package is a simple library to convert ascii number '**3456**' to geez number '**፴፬፻፶፮**'. +This package is a library to convert ascii number like '**3456**' to geez number '**፴፬፻፶፮**' and vise versa. -Installation ------------- + > Ge'ez (ግዕዝ) is an ancient South Semitic language that originated in Eritrea and the northern region of Ethiopia in the Horn of Africa. It later became the official language of the Kingdom of Aksum and Ethiopian imperial court. + +click [here](https://en.wikipedia.org/wiki/Ge%27ez) to read more. -### Prerequisites -geezify requires PHP 5.4 or greater. +Prerequisites +------------- +`geezify` requires **PHP** 5.6 or greater. -### Setup through composer +Installation +------------ ```sh composer require andegna/geezify ``` -A simple example + > If you never used `composer` before, please check out + > [this link](https://getcomposer.org) + > before you write any **PHP** code again! + +Usage ---------------- ```php toGeez(123) . PHP_EOL; // ፻፳፫ -echo $geez->toGeez(1234) . PHP_EOL; // ፲፪፻፴፬ -echo $geez->toGeez(1986) . PHP_EOL; // ፲፱፻፹፮ +echo $geez->toGeez(123) . PHP_EOL; // ፻፳፫ +echo $geez->toGeez(1234) . PHP_EOL; // ፲፪፻፴፬ +echo $geez->toGeez(1986) . PHP_EOL; // ፲፱፻፹፮ echo $geez->toGeez(1000000) . PHP_EOL; // ፻፼ // or you can even do the reverse -echo $geez->toAscii('፻፳፫') . PHP_EOL; // 123 -echo $geez->toAscii('፲፪፻፴፬') . PHP_EOL; // 1234 -echo $geez->toAscii('፲፱፻፹፮') . PHP_EOL; // 1986 -echo $geez->toAscii('፻፼') . PHP_EOL; // 1000000 +echo $geez->toAscii('፻፳፫') . PHP_EOL; // 123 +echo $geez->toAscii('፲፪፻፴፬') . PHP_EOL; // 1234 +echo $geez->toAscii('፲፱፻፹፮') . PHP_EOL; // 1986 +echo $geez->toAscii('፻፼') . PHP_EOL; // 1000000 ``` License diff --git a/composer.json b/composer.json index c1b68b9..216711d 100644 --- a/composer.json +++ b/composer.json @@ -10,10 +10,10 @@ } ], "require": { - "php": ">=5.4|7.*" + "php": ">=5.6|7.*" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "^5.0" }, "autoload": { "psr-4": { diff --git a/src/Converter/AsciiConverter.php b/src/Converter/AsciiConverter.php index c547744..36df450 100644 --- a/src/Converter/AsciiConverter.php +++ b/src/Converter/AsciiConverter.php @@ -56,7 +56,7 @@ protected function parse($geez_number) protected function calculate(Queue $parsed) { $calculator = new GeezCalculator($parsed); - $calculator->calculator(); + $calculator->calculate(); return $calculator->getCalculated(); } diff --git a/src/Converter/Converter.php b/src/Converter/Converter.php index f0822b9..8ac0ccc 100644 --- a/src/Converter/Converter.php +++ b/src/Converter/Converter.php @@ -14,9 +14,7 @@ abstract class Converter // space, it's just an empty string const EMPTY_CHARACTER = ''; - // PHP never thought of declaring (const | define) arrays till 5.6 - // This is the second best thing for 5.4 - public static $GEEZ_NUMBERS = [ + const GEEZ_NUMBERS = [ 0 => '', '፩', '፪', '፫', '፬', '፭', '፮', '፯', '፰', '፱', '፲', 20 => '፳', 30 => '፴', @@ -66,7 +64,7 @@ protected function isGeezNumberHundred($geez_number) */ protected function isGeezNumber($geez_number, $number) { - return $geez_number === self::$GEEZ_NUMBERS[$number]; + return $geez_number === self::GEEZ_NUMBERS[$number]; } /** diff --git a/src/Converter/GeezConverter.php b/src/Converter/GeezConverter.php index 9329d40..a8d76ae 100644 --- a/src/Converter/GeezConverter.php +++ b/src/Converter/GeezConverter.php @@ -159,7 +159,7 @@ protected function getGeezNumberOfTheBlock($number, $index) $once = (int) $block[1]; return - static::$GEEZ_NUMBERS[($tenth * 10)].static::$GEEZ_NUMBERS[$once]; + static::GEEZ_NUMBERS[($tenth * 10)].static::GEEZ_NUMBERS[$once]; } /** @@ -204,9 +204,9 @@ protected function getGeezSeparator($bet) if ($this->isZero($bet)) { return static::EMPTY_CHARACTER; } elseif ($this->isOdd($bet)) { - return static::$GEEZ_NUMBERS[100]; + return static::GEEZ_NUMBERS[100]; } else { - return static::$GEEZ_NUMBERS[10000]; + return static::GEEZ_NUMBERS[10000]; } } diff --git a/src/Helper/GeezCalculator.php b/src/Helper/GeezCalculator.php index ec4d8c6..1f40112 100644 --- a/src/Helper/GeezCalculator.php +++ b/src/Helper/GeezCalculator.php @@ -47,7 +47,7 @@ public function __construct(Queue $queue) /** * Do the magic. */ - public function calculator() + public function calculate() { $this->resetSubTotalToZero(); @@ -118,7 +118,7 @@ protected function processBySeparator($block, $separator) * * @param $block * - * @return int + * @return void */ protected function addToTotal($block) { diff --git a/src/Helper/GeezParser.php b/src/Helper/GeezParser.php index e1fedb1..940f0b0 100644 --- a/src/Helper/GeezParser.php +++ b/src/Helper/GeezParser.php @@ -143,7 +143,7 @@ protected function getCharacterAt($geez_number, $index) */ protected function getAsciiNumber($geez_number) { - $ascii_number = array_search($geez_number, Converter::$GEEZ_NUMBERS, true); + $ascii_number = array_search($geez_number, Converter::GEEZ_NUMBERS, true); if ($ascii_number === false) { throw new NotGeezArgumentException($geez_number); diff --git a/tests/GeezifyTest.php b/tests/GeezifyTest.php index e9bb595..e1e5306 100644 --- a/tests/GeezifyTest.php +++ b/tests/GeezifyTest.php @@ -2,10 +2,26 @@ namespace Andegna\Geez\PHPUnit; +use Andegna\Geez\Converter\AsciiConverter; +use Andegna\Geez\Converter\GeezConverter; use Andegna\Geez\Geezify; +use Prophecy\Prophet; class GeezifyTest extends TestCase { + /** @var Prophet */ + protected $prophet; + + protected function setup() + { + $this->prophet = new Prophet(); + } + + protected function tearDown() + { + $this->prophet->checkPredictions(); + } + public function test_random_numbers() { $geezify = Geezify::create(); @@ -19,4 +35,36 @@ public function test_random_numbers() $this->assertEquals($random_number, $ascii_number); } } + + public function test_geezify_build_process() + { + // let prophesize ;) + $geez = $this->prophet->prophesize(GeezConverter::class); + $ascii = $this->prophet->prophesize(AsciiConverter::class); + + // build out thing + $geezify = new Geezify($geez->reveal(), $ascii->reveal()); + + // promise + $geez->convert(123)->willReturn('giber gaber'); + $ascii->convert('lorem ipsum')->willReturn(321); + + // assert the response + $this->assertEquals(321, $geezify->toAscii('lorem ipsum')); + $this->assertEquals('giber gaber', $geezify->toGeez(123)); + } + + public function test_setter_and_getters() + { + $geezify = Geezify::create(); + + $geez_dummy = $this->prophet->prophesize(GeezConverter::class)->reveal(); + $ascii_dummy = $this->prophet->prophesize(AsciiConverter::class)->reveal(); + + $geezify->setGeezConverter($geez_dummy); + $geezify->setAsciiConverter($ascii_dummy); + + $this->assertEquals($geez_dummy, $geezify->getGeezConverter()); + $this->assertEquals($ascii_dummy, $geezify->getAsciiConverter()); + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 1e072e5..e0fe5eb 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,7 +2,7 @@ namespace Andegna\Geez\PHPUnit; -class TestCase extends \PHPUnit_Framework_TestCase +class TestCase extends \PHPUnit\Framework\TestCase { public function geezNumberTestDataProvider() {