Skip to content

Commit

Permalink
bump version to stable phalcon 5.0.0; minor adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
someson committed Sep 23, 2022
1 parent 72050d7 commit 4fce236
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 82 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ jobs:
sudo pecl install xdebug
- run:
name: Install Phalcon v5.0.0RC1
name: Install Phalcon v5.0.0
command: |
sudo apt install gcc libpcre3-dev -y
sudo pecl channel-update pecl.php.net
sudo pecl install phalcon-5.0.0RC1
sudo pecl install phalcon-5.0.0
- run: sudo composer selfupdate
- restore_cache:
Expand Down
19 changes: 9 additions & 10 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
FROM php:8.0-fpm

RUN apt-get update && apt-get install -y --no-install-recommends \
git \
libzip-dev \
libyaml-dev \
zip \
libssl-dev \
git \
libicu-dev \
&& rm -rf /var/lib/apt/lists/*

ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/
RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && install-php-extensions yaml

ENV APCU_VERSION=5.1.21
RUN set -xe \
&& pecl install apcu-${APCU_VERSION} xdebug \
&& pecl install xdebug apcu-${APCU_VERSION} \
&& docker-php-ext-enable xdebug apcu \
&& docker-php-ext-configure pdo_mysql --with-pdo-mysql \
&& docker-php-ext-configure intl --enable-intl \
&& docker-php-ext-install -j$(nproc) \
zip \
calendar \
intl \
pdo_mysql \
&& docker-php-ext-install -j$(nproc) zip calendar intl pdo_mysql \
&& pecl clear-cache

ENV PHALCON_VERSION=5.0.0RC1 \
ENV PHALCON_VERSION=5.0.0 \
PSR_VERSION=1.1.0

RUN set -xe \
&& curl -LO https://github.com/jbboehr/php-psr/archive/refs/tags/v${PSR_VERSION}.tar.gz \
&& tar xzf ${PWD}/v${PSR_VERSION}.tar.gz \
Expand Down
56 changes: 6 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,65 +153,21 @@ return [

[Codeception](https://codeception.com/) used

To run tests, run the following command:

```
$ docker-compose exec php-service ./vendor/bin/codecept run unit [-vv]
$ docker-compose exec i18n ./vendor/bin/codecept build
```

To run tests, run the following command:
```
$ docker-compose exec php-service ./vendor/bin/codecept run --coverage
Codeception PHP Testing Framework v4.1.31 https://helpukrainewin.org
Powered by PHPUnit 9.5.20 #StandWithUkraine
Unit Tests (29) ----------------------------------------------------------
✔ AdapterTest: Json found and initialized (0.23s)
✔ AdapterTest: Json may throw exceptions (0.10s)
✔ ConfigTest: Must be functional with config service (0.11s)
✔ ConfigTest: Must be functionable without config service (0.02s)
✔ ConfigTest: Must be functionable with wrong config (0.01s)
✔ DecoratorTest: No decoration (0.02s)
✔ DecoratorTest: Decorate as text pattern (0.02s)
✔ DecoratorTest: Decorate as html (0.02s)
✔ HandlerTest: Check keys shifting | #0 (0.01s)
✔ HandlerTest: Check keys shifting | #1 (0.01s)
✔ HandlerTest: Check keys shifting | #2 (0.01s)
✔ InterpolatorTest: Should handle default placeholders (0.00s)
✔ InterpolatorTest: Should handle custom placeholders (0.00s)
✔ LoaderTest: Files loader | #0 (0.08s)
✔ LoaderTest: Files loader | #1 (0.02s)
✔ TranslatorTest: Fallback loaded (0.03s)
✔ TranslatorTest: Wrong fallback lang defined (0.01s)
✔ TranslatorTest: Default instance (0.01s)
✔ TranslatorTest: Change language (0.00s)
✔ TranslatorTest: Change scope (0.00s)
✔ TranslatorTest: Changed scope should return a new collection (0.02s)
✔ TranslatorTest: Check if translation exists (0.03s)
✔ TranslatorTest: Plural (0.02s)
✔ TranslatorTest: Context (0.02s)
✔ TranslatorTest: Missing translations (0.02s)
✔ TranslatorTest: Simple translation without parameters (0.02s)
✔ TranslatorTest: Simple translation with parameters (0.02s)
✔ TranslatorTest: Translation with deeper level (0.02s)
--------------------------------------------------------------------------
Time: 00:09.936, Memory: 26.00 MB
OK (28 tests, 52 assertions)
Code Coverage Report Summary:
Classes: 75.00% (6/8)
Methods: 93.10% (27/29)
Lines: 98.59% (140/142)
$ docker-compose exec i18n ./vendor/bin/codecept run [-vv]
```

For code coverage info run
```
$ docker-compose exec php-service ./vendor/bin/codecept run --coverage --coverage-html
$ docker-compose exec i18n ./vendor/bin/codecept run --coverage --coverage-html
```
and open `tests/_output/coverage/index.html` in your browser

### Static analyzer

`$ docker-compose exec php-service ./vendor/bin/phpstan analyse src --level max`
`$ docker-compose exec i18n ./vendor/bin/phpstan analyse src --level max`
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
"require": {
"php": "8.0.*",
"ext-json": "*",
"ext-phalcon": "5.0.*"
"ext-phalcon": "^5.0"
},
"require-dev": {
"codeception/codeception": "^4.1",
"codeception/module-asserts": "^1.3",
"codeception/module-phalcon5": "^1.0",
"phalcon/ide-stubs": "v5.0.0-RC1",
"phpstan/phpstan": "^0.12"
"codeception/codeception": "^5.0",
"codeception/module-asserts": "^3.0",
"codeception/module-phalcon5": "^2.0",
"phalcon/ide-stubs": "^v5.0",
"phpstan/phpstan": "^1.8"
},
"authors": [
{
Expand Down
9 changes: 3 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
version: "3.8"
services:
php-service:

i18n:
build:
context: .docker
dockerfile: Dockerfile
container_name: i18n-container
container_name: i18n
env_file:
- ./.docker/.php.env
volumes:
- .:/var/www/html:cached
- ~/composer:/root/.composer
tty: true
networks:
- i18n
networks:
i18n:
5 changes: 3 additions & 2 deletions src/Adapter/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Phalcon\I18n\Adapter;

use JsonException;
use LengthException;
use Phalcon\Support\Collection;
use Phalcon\I18n\Interfaces\AdapterInterface;
Expand All @@ -11,7 +12,7 @@ class Json extends Collection implements AdapterInterface
{
/**
* @param string $filePath
* @throws \JsonException
* @throws JsonException
*/
public function __construct(string $filePath)
{
Expand All @@ -22,7 +23,7 @@ public function __construct(string $filePath)
throw new LengthException('Empty content');
}
$data = json_decode($content, true, 100, JSON_THROW_ON_ERROR);
parent::__construct($data, false);
parent::__construct((array) $data, false);
}

public static function getFileExtensions(): array
Expand Down
3 changes: 1 addition & 2 deletions src/Interpolator/AssocArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ public function __construct(?string $left = null, ?string $right = null)

/**
* Replaces placeholders by the values passed
*
* @param string $translation
* @param array<string, mixed> $placeholders
* @param array<string, string|array> $placeholders
* @return string
*/
public function replacePlaceholders(string $translation, array $placeholders = []): string
Expand Down
6 changes: 2 additions & 4 deletions src/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Phalcon\Translate\Exception as TException;
use Phalcon\Translate\Interpolator\InterpolatorInterface;
use ReflectionClass, ReflectionException, UnexpectedValueException;
use function call_user_func_array;

final class Translator
{
Expand Down Expand Up @@ -81,8 +80,7 @@ public function getScopeName(): ?string
*/
public function getScope(string $name): array
{
$allByLang = $this->_loadTranslations();
return $allByLang->getByScope($name) ?? [];
return $this->_loadTranslations()->getByScope($name);
}

public function setLang(string $lang): self
Expand Down Expand Up @@ -123,7 +121,7 @@ public function exists(string $key): bool

/**
* @param string $key 'scope:a.b.c'
* @param array<string, mixed> $params
* @param array<string, string> $params
* @param bool $pluralize
* @return string
* @throws ReflectionException|TException
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
use Phalcon\I18n\Handler\NativeArray;
use Phalcon\I18n\Interpolator\AssocArray;
use Phalcon\I18n\Loader\Files;
use Phalcon\Translate\Exception;

class HandlerTest extends Unit
{
protected \UnitTester $tester;

public function getShiftVariants(): array
{
return [
Expand All @@ -33,4 +36,11 @@ public function testCheckKeysShifting(int $shiftLevel, array $shiftKeys, string
}
self::assertTrue($handler->has($tKey));
}

public function testMayThrowException(): void
{
$this->tester->expectThrowable(new Exception('Translation content was not provided'), function() {
new NativeArray(new AssocArray('{{', '}}'), []);
});
}
}

0 comments on commit 4fce236

Please sign in to comment.