Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T13007 nativearray missing patch #13748

Merged
merged 13 commits into from
Jan 10, 2019
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ branches:
only:
- master
- /^(4|5)\.\d+\.(\d+|x)$/
- /^T\d+-[a-zA-Z-]+/

addons:
apt:
Expand Down
4 changes: 2 additions & 2 deletions phalcon/translate/adapter/nativearray.zep
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class NativeArray extends Adapter implements \ArrayAccess
}

if fetch error, options["triggerError"] {
let this->triggerError = true;
let this->triggerError = (bool) error;
}

if typeof data !== "array" {
Expand All @@ -68,7 +68,7 @@ class NativeArray extends Adapter implements \ArrayAccess
public function notFound(string! index) -> string
{
if (true === this->triggerError) {
trigger_error("Cannot find translation key: " . index, E_USER_NOTICE);
throw new Exception("Cannot find translation key: " . index);
}

return index;
Expand Down
29 changes: 28 additions & 1 deletion tests/unit/Translate/Adapter/NativeArray/NotFoundCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Phalcon\Test\Fixtures\Traits\TranslateTrait;
use Phalcon\Test\Fixtures\Translate\Adapter\NativeAdapter;
use Phalcon\Translate\Adapter\NativeArray;
use Phalcon\Translate\Exception;
use UnitTester;

/**
Expand Down Expand Up @@ -55,7 +56,7 @@ public function translateAdapterNativearrayNotFoundTriggerError(UnitTester $I)
{
$I->wantToTest('Translate\Adapter\NativeArray - notFound() - triggerError');
$I->expectThrowable(
new \Exception('Cannot find translation key: unknown', 1024),
new Exception('Cannot find translation key: unknown'),
function () {
$language = $this->getArrayConfig()['en'];
$translator = new NativeArray(
Expand All @@ -69,6 +70,32 @@ function () {
);
}

/**
* Tests Phalcon\Translate\Adapter\NativeArray :: notFound() - triggerError random value
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2018-11-13
*/
public function translateAdapterNativearrayNotFoundTriggerErrorRandomVaue(UnitTester $I)
{
$I->wantToTest('Translate\Adapter\NativeArray - notFound() - triggerError random value');
$I->expectThrowable(
new Exception('Cannot find translation key: unknown'),
function () {
$language = $this->getArrayConfig()['en'];
$translator = new NativeArray(
[
'content' => $language,
'triggerError' => 'blahblah',
]
);
$translator->query('unknown');
}
);
}

/**
* Tests Phalcon\Translate\Adapter\NativeArray :: notFound() - custom
*
Expand Down