Add Symfony Deprecation Contracts package
- Created CHANGELOG.md to maintain version history. - Added README.md with usage instructions for the trigger_deprecation() function. - Initialized composer.json for the Symfony Deprecation Contracts library, specifying dependencies and autoloading.
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* The RandomLib library for securely generating random numbers and strings in PHP
|
||||
*
|
||||
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
|
||||
* @copyright 2011 The Authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @version Build @@version@@
|
||||
*/
|
||||
namespace RandomLib\Source;
|
||||
|
||||
use SecurityLib\Strength;
|
||||
|
||||
abstract class AbstractSourceTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$class = static::getTestedClass();
|
||||
|
||||
if (!$class::isSupported()) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
}
|
||||
|
||||
protected static function getTestedClass()
|
||||
{
|
||||
return preg_replace('/Test$/', '', get_called_class());
|
||||
}
|
||||
|
||||
protected static function getExpectedStrength()
|
||||
{
|
||||
return new Strength(Strength::VERYLOW);
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
$class = static::getTestedClass();
|
||||
$strength = static::getExpectedStrength();
|
||||
$actual = $class::getStrength();
|
||||
$this->assertEquals($actual, $strength);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideGenerate
|
||||
* @group slow
|
||||
*/
|
||||
public function testGenerate($length, $not)
|
||||
{
|
||||
$class = static::getTestedClass();
|
||||
$rand = new $class();
|
||||
$stub = $rand->generate($length);
|
||||
$this->assertEquals($length, strlen($stub));
|
||||
$this->assertNotEquals($not, $stub);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* The RandomLib library for securely generating random numbers and strings in PHP
|
||||
*
|
||||
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
|
||||
* @copyright 2011 The Authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @version Build @@version@@
|
||||
*/
|
||||
namespace RandomLib\Source;
|
||||
|
||||
use SecurityLib\Strength;
|
||||
|
||||
class CAPICOMTest extends AbstractSourceTest
|
||||
{
|
||||
protected static function getExpectedStrength()
|
||||
{
|
||||
return new Strength(Strength::MEDIUM);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* The RandomLib library for securely generating random numbers and strings in PHP
|
||||
*
|
||||
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
|
||||
* @copyright 2011 The Authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @version Build @@version@@
|
||||
*/
|
||||
namespace RandomLib\Source;
|
||||
|
||||
use SecurityLib\Strength;
|
||||
|
||||
class MTRandTest extends AbstractSourceTest
|
||||
{
|
||||
protected static function getExpectedStrength()
|
||||
{
|
||||
if (defined('S_ALL')) {
|
||||
return new Strength(Strength::LOW);
|
||||
} else {
|
||||
return new Strength(Strength::VERYLOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* The RandomLib library for securely generating random numbers and strings in PHP
|
||||
*
|
||||
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
|
||||
* @copyright 2011 The Authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @version Build @@version@@
|
||||
*/
|
||||
namespace RandomLib\Source;
|
||||
|
||||
use SecurityLib\Strength;
|
||||
|
||||
class MicroTimeTest extends AbstractSourceTest
|
||||
{
|
||||
protected static function getExpectedStrength()
|
||||
{
|
||||
return new Strength(Strength::VERYLOW);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the initialization of the static counter (!== 0)
|
||||
*/
|
||||
public function testCounterNotNull()
|
||||
{
|
||||
$class = static::getTestedClass();
|
||||
$rand = new $class();
|
||||
$reflection_class = new \ReflectionClass($class);
|
||||
$static = $reflection_class->getStaticProperties();
|
||||
$this->assertTrue($static['counter'] !== 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* The RandomLib library for securely generating random numbers and strings in PHP
|
||||
*
|
||||
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
|
||||
* @copyright 2011 The Authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @version Build @@version@@
|
||||
*/
|
||||
namespace RandomLib\Source;
|
||||
|
||||
use SecurityLib\Strength;
|
||||
|
||||
class RandTest extends AbstractSourceTest
|
||||
{
|
||||
protected static function getExpectedStrength()
|
||||
{
|
||||
if (defined('S_ALL')) {
|
||||
return new Strength(Strength::LOW);
|
||||
} else {
|
||||
return new Strength(Strength::VERYLOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* The RandomLib library for securely generating random numbers and strings in PHP
|
||||
*
|
||||
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
|
||||
* @copyright 2011 The Authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @version Build @@version@@
|
||||
*/
|
||||
namespace RandomLib\Source;
|
||||
|
||||
use SecurityLib\Strength;
|
||||
|
||||
class SodiumTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (!extension_loaded('libsodium')) {
|
||||
$this->markTestSkipped('The libsodium extension is not loaded');
|
||||
}
|
||||
}
|
||||
|
||||
public static function provideGenerate()
|
||||
{
|
||||
$data = array();
|
||||
for ($i = 1; $i < 100; $i += 5) {
|
||||
$not = str_repeat(chr(0), $i);
|
||||
$data[] = array($i, $not);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public function testGetStrength()
|
||||
{
|
||||
$strength = new Strength(Strength::HIGH);
|
||||
$actual = Sodium::getStrength();
|
||||
$this->assertEquals($actual, $strength);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideGenerate
|
||||
*/
|
||||
public function testGenerate($length, $not)
|
||||
{
|
||||
if (!extension_loaded('libsodium')) {
|
||||
$this->markTestSkipped('The libsodium extension is not loaded');
|
||||
}
|
||||
|
||||
$rand = new Sodium();
|
||||
$stub = $rand->generate($length);
|
||||
$this->assertEquals($length, strlen($stub));
|
||||
$this->assertNotEquals($not, $stub);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideGenerate
|
||||
*/
|
||||
public function testGenerateWithoutLibsodium($length, $not)
|
||||
{
|
||||
$rand = new Sodium(false);
|
||||
$stub = $rand->generate($length);
|
||||
$this->assertEquals($length, strlen($stub));
|
||||
$this->assertEquals($not, $stub);
|
||||
}
|
||||
|
||||
public function testGenerateWithZeroLength()
|
||||
{
|
||||
if (!extension_loaded('libsodium')) {
|
||||
$this->markTestSkipped('The libsodium extension is not loaded');
|
||||
}
|
||||
|
||||
$rand = new Sodium();
|
||||
$stub = $rand->generate(0);
|
||||
$this->assertEquals(0, strlen($stub));
|
||||
$this->assertEquals('', $stub);
|
||||
}
|
||||
|
||||
public function testGenerateWithZeroLengthWithoutLibsodium()
|
||||
{
|
||||
$rand = new Sodium(false);
|
||||
$stub = $rand->generate(0);
|
||||
$this->assertEquals(0, strlen($stub));
|
||||
$this->assertEquals('', $stub);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* The RandomLib library for securely generating random numbers and strings in PHP
|
||||
*
|
||||
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
|
||||
* @copyright 2011 The Authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @version Build @@version@@
|
||||
*/
|
||||
namespace RandomLib\Source;
|
||||
|
||||
use SecurityLib\Strength;
|
||||
|
||||
class URandomTest extends AbstractSourceTest
|
||||
{
|
||||
protected static function getExpectedStrength()
|
||||
{
|
||||
return new Strength(Strength::HIGH);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* The RandomLib library for securely generating random numbers and strings in PHP
|
||||
*
|
||||
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
|
||||
* @copyright 2011 The Authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @version Build @@version@@
|
||||
*/
|
||||
namespace RandomLib\Source;
|
||||
|
||||
use SecurityLib\Strength;
|
||||
|
||||
class UniqIDTest extends AbstractSourceTest
|
||||
{
|
||||
protected static function getExpectedStrength()
|
||||
{
|
||||
return new Strength(Strength::LOW);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user