www.gusucode.com > Flarum中文优化论坛PHP源码程序 > FlarumChina-master/vendor/ircmaxell/random-lib/test/Unit/RandomLib/Source/RandTest.php

    <?php

namespace RandomLib\Source;

use SecurityLib\Strength;

class RandTest extends \PHPUnit_Framework_TestCase {

    public static function provideGenerate() {
        $data = array();
        for ($i = 0; $i < 100; $i += 5) {
            $not = $i > 0 ? str_repeat(chr(0), $i) : chr(0);
            $data[] = array($i, $not);
        }
        return $data;
    }

    /**
     */
    public function testGetStrength() {
        if (defined('S_ALL')) {
            $strength = new Strength(Strength::LOW);
        } else {
            $strength = new Strength(Strength::VERYLOW);
        }
        $actual = Rand::getStrength();
        $this->assertEquals($actual, $strength);
    }

    /**
     * @dataProvider provideGenerate
     */
    public function testGenerate($length, $not) {
        $rand = new Rand;
        $stub = $rand->generate($length);
        $this->assertEquals($length, strlen($stub));
        $this->assertNotEquals($not, $stub);
    }

}