Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'weierophinney/feature/registry-remove-s…
Browse files Browse the repository at this point in the history
…ingleton'
  • Loading branch information
akrabat committed Jun 28, 2012
13 parents 9262db1 + 3569d8b + 00def10 + ecae47b + 0e552a5 + 4f854c2 + 2b17650 + c1c0447 + 73b1f80 + a40eb42 + dd4a335 + bdbd950 + 760bfc0 commit 066eb37
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 93 deletions.
13 changes: 1 addition & 12 deletions src/AbstractValidator.php
Expand Up @@ -478,17 +478,6 @@ public static function setDefaultTranslator($translator = null)
*/
public static function getDefaultTranslator()
{
if (null === self::$defaultTranslator) {
if (Registry::isRegistered('Zend_Translator')) {
$translator = Registry::get('Zend_Translator');
if ($translator instanceof Translator\Adapter\AbstractAdapter) {
return $translator;
} elseif ($translator instanceof Translator\Translator) {
return $translator->getAdapter();
}
}
}

return self::$defaultTranslator;
}

Expand Down Expand Up @@ -543,4 +532,4 @@ public static function setMessageLength($length = -1)
{
self::$messageLength = $length;
}
}
}
7 changes: 0 additions & 7 deletions src/Date.php
Expand Up @@ -24,7 +24,6 @@
use Zend\Date as ZendDate;
use Zend\Locale\Format;
use Zend\Locale\Locale;
use Zend\Registry;
use Zend\Stdlib\ArrayUtils;

/**
Expand Down Expand Up @@ -94,12 +93,6 @@ public function __construct($options = array())
$this->setFormat($options['format']);
}

if (!array_key_exists('locale', $options)) {
if (Registry::isRegistered('Zend_Locale')) {
$options['locale'] = Registry::get('Zend_Locale');
}
}

if (array_key_exists('locale', $options)) {
$this->setLocale($options['locale']);
}
Expand Down
7 changes: 0 additions & 7 deletions src/Iban.php
Expand Up @@ -22,7 +22,6 @@

use Traversable;
use Zend\Locale\Locale;
use Zend\Registry;
use Zend\Stdlib\ArrayUtils;

/**
Expand Down Expand Up @@ -124,12 +123,6 @@ public function __construct($options = null)
}
}

if (empty($options) && ($options !== false)) {
if (Registry::isRegistered('Zend_Locale')) {
$options = Registry::get('Zend_Locale');
}
}

if ($options !== null) {
$this->setLocale($options);
}
Expand Down
6 changes: 0 additions & 6 deletions src/Int.php
Expand Up @@ -65,12 +65,6 @@ public function __construct($options = null)
}
}

if (empty($options)) {
if (Registry::isRegistered('Zend_Locale')) {
$options = Registry::get('Zend_Locale');
}
}

if ($options !== null) {
$this->setLocale($options);
}
Expand Down
11 changes: 3 additions & 8 deletions src/PostCode.php
Expand Up @@ -24,9 +24,6 @@
use Zend\Registry;

/**
* @see Zend_Locale
* @see Zend_Locale_Format
* @see Zend_Registry
* @category Zend
* @package Zend_Validate
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
Expand Down Expand Up @@ -71,11 +68,9 @@ class PostCode extends AbstractValidator
*/
public function __construct($options = null)
{
if (empty($options)) {
if (Registry::isRegistered('Zend_Locale')) {
$this->setLocale(Registry::get('Zend_Locale'));
}
} elseif ($options instanceof Locale\Locale || is_string($options)) {
if (!empty($options)
&& ($options instanceof Locale\Locale || is_string($options))
) {
// Received Locale object or string locale
$this->setLocale($options);
}
Expand Down
7 changes: 2 additions & 5 deletions test/DateTest.php
Expand Up @@ -23,7 +23,6 @@

use Zend\Validator\Date as DateValidator;
use Zend\Date;
use Zend\Registry;

/**
* @category Zend
Expand All @@ -49,7 +48,6 @@ class DateTest extends \PHPUnit_Framework_TestCase

public function setUp()
{
Registry::_unsetInstance();
$this->errorOccurred = false;
$this->validator = new DateValidator();
}
Expand Down Expand Up @@ -203,14 +201,13 @@ public function testNonStringValidation()
*/
public function testUsingApplicationLocale()
{
\Zend\Registry::set('Zend_Locale', new \Zend\Locale\Locale('de'));
$this->markTestSkipped('Depends on system-specific locale');
$valid = new DateValidator();
$this->assertTrue($valid->isValid('10.April.2008'));
}

/**
* @group fml
* ZF-7630
* @group ZF-7630
*/
public function testDateObjectVerification()
{
Expand Down
21 changes: 3 additions & 18 deletions test/FloatTest.php
Expand Up @@ -42,12 +42,7 @@ class FloatTest extends \PHPUnit_Framework_TestCase
protected $locale;
public function setUp()
{
$this->locale = setlocale(LC_ALL, 0); //backup locale

if (\Zend\Registry::isRegistered('Zend_Locale')) {
\Zend\Registry::getInstance()->offsetUnset('Zend_Locale');
}

$this->locale = setlocale(LC_ALL, 0); //backup locale
$this->validator = new FloatValidator();
}

Expand Down Expand Up @@ -110,23 +105,13 @@ public function testSettingLocales()
}

/**
* @ZF-4352
* @group ZF-4352
*/
public function testNonStringValidation()
{
$this->assertFalse($this->validator->isValid(array(1 => 1)));
}

/**
* @ZF-7489
*/
public function testUsingApplicationLocale()
{
\Zend\Registry::set('Zend_Locale', new \Zend\Locale\Locale('de'));
$valid = new FloatValidator();
$this->assertTrue($valid->isValid('123,456'));
}

/**
* @ZF-7987
*/
Expand Down Expand Up @@ -218,4 +203,4 @@ public function testEqualsMessageTemplates()
$this->assertAttributeEquals($validator->getOption('messageTemplates'),
'messageTemplates', $validator);
}
}
}
8 changes: 1 addition & 7 deletions test/IbanTest.php
Expand Up @@ -21,7 +21,6 @@

namespace ZendTest\Validator;

use Zend\Registry;
use Zend\Validator\Iban;

/**
Expand All @@ -34,11 +33,6 @@
*/
class IbanTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
Registry::_unsetInstance();
}

/**
* Ensures that the validator follows expected behavior
*
Expand Down Expand Up @@ -98,4 +92,4 @@ public function testEqualsMessageTemplates()
$this->assertAttributeEquals($validator->getOption('messageTemplates'),
'messageTemplates', $validator);
}
}
}
5 changes: 2 additions & 3 deletions test/IntTest.php
Expand Up @@ -105,7 +105,6 @@ public function testNonStringValidation()
*/
public function testUsingApplicationLocale()
{
\Zend\Registry::set('Zend_Locale', new Locale\Locale('de'));
$valid = new Int();
$this->assertTrue($valid->isValid('10.000'));
}
Expand All @@ -115,7 +114,7 @@ public function testUsingApplicationLocale()
*/
public function testLocaleDetectsNoEnglishLocaleOnOtherSetLocale()
{
\Zend\Registry::set('Zend_Locale', new Locale\Locale('de'));
$this->markTestSkipped('Depends on system-specific locale');
$valid = new Int();
$this->assertTrue($valid->isValid(1200));
$this->assertFalse($valid->isValid('1,200'));
Expand All @@ -127,4 +126,4 @@ public function testEqualsMessageTemplates()
$this->assertAttributeEquals($validator->getOption('messageTemplates'),
'messageTemplates', $validator);
}
}
}
26 changes: 6 additions & 20 deletions test/StaticValidatorTest.php
Expand Up @@ -48,25 +48,20 @@ class StaticValidatorTest extends \PHPUnit_Framework_TestCase
*/
protected $errorOccurred = false;

public function clearRegistry()
{
if (\Zend\Registry::isRegistered('Zend_Translator')) {
$registry = \Zend\Registry::getInstance();
unset($registry['Zend_Translator']);
}
}

/**
* Creates a new validation object for each test method
*
* @return void
*/
public function setUp()
{
$this->clearRegistry();
AbstractValidator::setDefaultTranslator(null);
StaticValidator::setPluginManager(null);
$this->validator = new Alpha();
}

public function tearDown()
{
$this->clearRegistry();
AbstractValidator::setDefaultTranslator(null);
AbstractValidator::setMessageLength(-1);
}
Expand Down Expand Up @@ -101,15 +96,6 @@ public function testGlobalDefaultTranslatorUsedWhenNoLocalTranslatorSet()
$this->assertSame(AbstractValidator::getDefaultTranslator(), $this->validator->getTranslator());
}

public function testGlobalTranslatorFromRegistryUsedWhenNoLocalTranslatorSet()
{
set_error_handler(array($this, 'errorHandlerIgnore'));
$translate = new Translator\Translator('ArrayAdapter', array());
restore_error_handler();
\Zend\Registry::set('Zend_Translator', $translate);
$this->assertSame($translate->getAdapter(), $this->validator->getTranslator());
}

public function testLocalTranslatorPreferredOverGlobalTranslator()
{
$this->testCanSetGlobalDefaultTranslator();
Expand Down Expand Up @@ -187,4 +173,4 @@ public function testExecuteValidWithParameters()
$this->assertTrue(StaticValidator::execute(5, 'Between', array(1, 10)));
$this->assertTrue(StaticValidator::execute(5, 'Between', array('min' => 1, 'max' => 10)));
}
}
}

0 comments on commit 066eb37

Please sign in to comment.