Skip to content

Commit

Permalink
Merge pull request #15968 from niden/T15902-nativearray
Browse files Browse the repository at this point in the history
T15902 nativearray
  • Loading branch information
niden committed May 23, 2022
2 parents ba6ded0 + e90878d commit 3d864e3
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG-5.0.md
Expand Up @@ -35,7 +35,8 @@
- `Phalcon\Html\Link\Interfaces\LinkProviderInterface`
- `Phalcon\Html\Link\AbstractLink`
- `Phalcon\Html\Link\AbstractLinkProvider` to be used in the link class but also the proxy-psr13 repo [#15930](https://github.com/phalcon/cphalcon/issues/15930)

- Added `Phalcon\Translate\Adapter\Csv::toArray()` and `Phalcon\Translate\Adapter\NativeArray::toArray()` to return the translation array back [#15902](https://github.com/phalcon/cphalcon/issues/15902)
-
## Removed
- Removed `Phalcon\Container\Container` and moved its contents to the `proxy-psr11` repo [#15928](https://github.com/phalcon/cphalcon/issues/15928)
- Removed `Phalcon\Http\Message\*` and `Phalcon\Http\Server\*` classes. This removes PSR from Phalcon. PSR-7 available in v6 [#15929](https://github.com/phalcon/cphalcon/issues/15929)
Expand Down
10 changes: 10 additions & 0 deletions phalcon/Translate/Adapter/Csv.zep
Expand Up @@ -150,6 +150,16 @@ class Csv extends AbstractAdapter implements ArrayAccess
fclose(fileHandler);
}

/**
* Returns the internal array
*
* @return array
*/
public function toArray() -> array
{
return this->translate;
}

/**
* @todo to be removed when we get traits
*/
Expand Down
10 changes: 10 additions & 0 deletions phalcon/Translate/Adapter/NativeArray.zep
Expand Up @@ -129,4 +129,14 @@ class NativeArray extends AbstractAdapter implements ArrayAccess

return this->replacePlaceholders(translation, placeholders);
}

/**
* Returns the internal array
*
* @return array
*/
public function toArray() -> array
{
return this->translate;
}
}
49 changes: 49 additions & 0 deletions tests/unit/Translate/Adapter/Csv/ToArrayCest.php
@@ -0,0 +1,49 @@
<?php

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Phalcon\Tests\Unit\Translate\Adapter\Csv;

use Phalcon\Tests\Fixtures\Traits\TranslateCsvTrait;
use Phalcon\Translate\Adapter\Csv;
use Phalcon\Translate\InterpolatorFactory;
use UnitTester;

class ToArrayCest
{
use TranslateCsvTrait;

/**
* Tests Phalcon\Translate\Adapter\Csv :: toArray()
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalcon.io>
* @since 2020-09-09
*/
public function translateAdapterCsvToArray(UnitTester $I)
{
$I->wantToTest('Translate\Adapter\Csv - toArray()');

$language = $this->getCsvConfig()['en'];
$translator = new Csv(new InterpolatorFactory(), $language);

$expected = [
'hi' => 'Hello',
'bye' => 'Good Bye',
'hello-key' => 'Hello %name%',
'song-key' => 'This song is %song% (%artist%)',
];
$actual = $translator->toArray();
$I->assertSame($expected, $actual);
}
}
50 changes: 50 additions & 0 deletions tests/unit/Translate/Adapter/NativeArray/ToArrayCest.php
@@ -0,0 +1,50 @@
<?php

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Phalcon\Tests\Unit\Translate\Adapter\NativeArray;

use Phalcon\Tests\Fixtures\Traits\TranslateNativeArrayTrait;
use Phalcon\Translate\Adapter\NativeArray;
use Phalcon\Translate\InterpolatorFactory;
use UnitTester;

class ToArrayCest
{
use TranslateNativeArrayTrait;

/**
* Tests Phalcon\Translate\Adapter\NativeArray :: toArray()
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalcon.io>
* @since 2020-09-09
*/
public function translateAdapterNativeToArray(UnitTester $I)
{
$I->wantToTest('Translate\Adapter\NativeArray - toArray()');

$language = $this->getArrayConfig()['en'];

$translator = new NativeArray(
new InterpolatorFactory(),
[
'content' => $language,
]
);

$expected = $language;
$actual = $translator->toArray();
$I->assertSame($expected, $actual);
}
}

0 comments on commit 3d864e3

Please sign in to comment.