Вход Регистрация
Файл: symfony-2.7/src/Symfony/Component/Validator/Tests/Constraints/FileTest.php
Строк: 71
<?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 SymfonyComponentValidatorTestsConstraints;

use 
SymfonyComponentValidatorConstraintsFile;

class 
FileTest extends PHPUnit_Framework_TestCase
{
    
/**
     * @param mixed $maxSize
     * @param int   bytes
     * @param bool  $bytes
     * @dataProvider provideValidSizes
     */
    
public function testMaxSize($maxSize$bytes$binaryFormat)
    {
        
$file = new File(array('maxSize' => $maxSize));

        
$this->assertSame($bytes$file->maxSize);
        
$this->assertSame($binaryFormat$file->binaryFormat);
    }

    
/**
     * @param mixed $maxSize
     * @param int   $bytes
     * @dataProvider provideInValidSizes
     * @expectedException SymfonyComponentValidatorExceptionConstraintDefinitionException
     */
    
public function testInvalideMaxSize($maxSize)
    {
        
$file = new File(array('maxSize' => $maxSize));
    }

    
/**
     * @return array
     */
    
public function provideValidSizes()
    {
        return array(
            array(
'500'500false),
            array(
1230012300false),
            array(
'1ki'1024true),
            array(
'1KI'1024true),
            array(
'2k'2000false),
            array(
'2K'2000false),
            array(
'1mi'1048576true),
            array(
'1MI'1048576true),
            array(
'3m'3000000false),
            array(
'3M'3000000false),
        );
    }

    
/**
     * @return array
     */
    
public function provideInvalidSizes()
    {
        return array(
            array(
'+100'),
            array(
'foo'),
            array(
'1Ko'),
            array(
'1kio'),
            array(
'1G'),
            array(
'1Gi'),
        );
    }

    
/**
     * @param mixed $maxSize
     * @param bool  $guessedFormat
     * @param bool  $binaryFormat
     * @dataProvider provideFormats
     */
    
public function testBinaryFormat($maxSize$guessedFormat$binaryFormat)
    {
        
$file = new File(array('maxSize' => $maxSize'binaryFormat' => $guessedFormat));

        
$this->assertSame($binaryFormat$file->binaryFormat);
    }

    
/**
     * @return array
     */
    
public function provideFormats()
    {
        return array(
            array(
100nullfalse),
            array(
100truetrue),
            array(
100falsefalse),
            array(
'100K'nullfalse),
            array(
'100K'truetrue),
            array(
'100K'falsefalse),
            array(
'100Ki'nulltrue),
            array(
'100Ki'truetrue),
            array(
'100Ki'falsefalse),
        );
    }
}
Онлайн: 1
Реклама