Вход Регистрация
Файл: symfony-2.7/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/LazyChoiceListTest.php
Строк: 101
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SymfonyComponentFormTestsExtensionCoreChoiceList;

use 
SymfonyComponentFormExtensionCoreChoiceListSimpleChoiceList;
use 
SymfonyComponentFormExtensionCoreChoiceListLazyChoiceList;
use 
SymfonyComponentFormExtensionCoreViewChoiceView;

class 
LazyChoiceListTest extends PHPUnit_Framework_TestCase
{
    private 
$list;

    protected function 
setUp()
    {
        
parent::setUp();

        
$this->list = new LazyChoiceListTest_Impl(new SimpleChoiceList(array(
            
'a' => 'A',
            
'b' => 'B',
            
'c' => 'C',
        ), array(
'b')));
    }

    protected function 
tearDown()
    {
        
parent::tearDown();

        
$this->list null;
    }

    public function 
testGetChoices()
    {
        
$this->assertSame(array(=> 'a'=> 'b'=> 'c'), $this->list->getChoices());
    }

    public function 
testGetValues()
    {
        
$this->assertSame(array(=> 'a'=> 'b'=> 'c'), $this->list->getValues());
    }

    public function 
testGetPreferredViews()
    {
        
$this->assertEquals(array(=> new ChoiceView('b''b''B')), $this->list->getPreferredViews());
    }

    public function 
testGetRemainingViews()
    {
        
$this->assertEquals(array(=> new ChoiceView('a''a''A'), => new ChoiceView('c''c''C')), $this->list->getRemainingViews());
    }

    public function 
testLegacyGetIndicesForChoices()
    {
        
$this->iniSet('error_reporting', -& ~E_USER_DEPRECATED);

        
$choices = array('b''c');
        
$this->assertSame(array(12), $this->list->getIndicesForChoices($choices));
    }

    public function 
testLegacyGetIndicesForValues()
    {
        
$this->iniSet('error_reporting', -& ~E_USER_DEPRECATED);

        
$values = array('b''c');
        
$this->assertSame(array(12), $this->list->getIndicesForValues($values));
    }

    public function 
testGetChoicesForValues()
    {
        
$values = array('b''c');
        
$this->assertSame(array('b''c'), $this->list->getChoicesForValues($values));
    }

    public function 
testGetValuesForChoices()
    {
        
$choices = array('b''c');
        
$this->assertSame(array('b''c'), $this->list->getValuesForChoices($choices));
    }

    
/**
     * @expectedException SymfonyComponentFormExceptionInvalidArgumentException
     */
    
public function testLoadChoiceListShouldReturnChoiceList()
    {
        
$list = new LazyChoiceListTest_InvalidImpl();

        
$list->getChoices();
    }
}

class 
LazyChoiceListTest_Impl extends LazyChoiceList
{
    private 
$choiceList;

    public function 
__construct($choiceList)
    {
        
$this->choiceList $choiceList;
    }

    protected function 
loadChoiceList()
    {
        return 
$this->choiceList;
    }
}

class 
LazyChoiceListTest_InvalidImpl extends LazyChoiceList
{
    protected function 
loadChoiceList()
    {
        return new 
stdClass();
    }
}
Онлайн: 2
Реклама