Skip to content

Commit 59dcb54

Browse files
committed
Test enhancement
1 parent 9ee48ac commit 59dcb54

File tree

3 files changed

+48
-23
lines changed

3 files changed

+48
-23
lines changed

.travis.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ php:
44
- 5.6
55
- 7.0
66
- 7.1
7+
- 7.2
78
- nightly
89
- hhvm
910

1011
sudo: false
1112

1213
matrix:
1314
allow_failures:
14-
- php: 5.3
15-
- php: 5.4
16-
- php: 5.5
1715
- php: nightly
1816
fast_finish: true
1917

@@ -26,11 +24,10 @@ env:
2624
- PREFER_LOWEST=""
2725

2826
before_script:
29-
- composer update --ignore-platform-reqs --prefer-dist $PREFER_LOWEST
30-
- composer --optimize-autoloader --no-interaction
27+
- composer update --prefer-dist $PREFER_LOWEST
3128

3229
script:
33-
- bin/phpunit --configuration . --coverage-clover=build/logs/clover.xml --coverage-html=build/html/coverage
30+
- bin/phpunit --coverage-clover=build/logs/clover.xml --coverage-html=build/html/coverage
3431

3532
after_script:
3633
- if [ $(phpenv version-name) == "5.6" ] && [ "$PREFER_LOWEST" == "--prefer-lowest" ]; then bin/codacycoverage clover build/logs/clover.xml > /dev/null 2>&1; fi

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"paragonie/random_compat": "^2.0"
2020
},
2121
"require-dev": {
22-
"phpunit/phpunit": "^5.7",
22+
"phpunit/phpunit": "^5.7 || ^6.5",
2323
"codacy/coverage": "^1.0.5",
2424
"symfony/var-dumper": "^3.2"
2525
},

tests/GeneratorTest.php

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
* (The MIT license)
5-
* Copyright 2017 clickalicious, Benjamin Carl
5+
* Copyright 2017 clickalicious, Benjamin Carl.
66
*
77
* Permission is hereby granted, free of charge, to any person obtaining a
88
* copy of this software and associated documentation files (the
@@ -27,12 +27,12 @@
2727

2828
namespace Clickalicious\Rng;
2929

30+
use PHPUnit\Framework\TestCase;
31+
3032
/**
31-
* Class GeneratorTest
32-
*
33-
* @package Rng
33+
* Class GeneratorTest.
3434
*/
35-
class GeneratorTest extends \PHPUnit_Framework_TestCase
35+
class GeneratorTest extends TestCase
3636
{
3737
/**
3838
* Test: Get instance.
@@ -42,7 +42,7 @@ class GeneratorTest extends \PHPUnit_Framework_TestCase
4242
public function testInstance()
4343
{
4444
$this->assertInstanceOf(
45-
'Clickalicious\Rng\Generator',
45+
Generator::class,
4646
new Generator()
4747
);
4848
}
@@ -57,7 +57,7 @@ public function testCreatingInstanceByModeDefault()
5757
$generator = new Generator();
5858

5959
$this->assertInstanceOf(
60-
'Clickalicious\Rng\Generator',
60+
Generator::class,
6161
$generator
6262
);
6363
}
@@ -74,7 +74,7 @@ public function testCreatingInstanceByModePhpDefault()
7474
);
7575

7676
$this->assertInstanceOf(
77-
'Clickalicious\Rng\Generator',
77+
Generator::class,
7878
$generator
7979
);
8080
}
@@ -91,7 +91,7 @@ public function testCreatingInstanceByModePhpMersenneTwister()
9191
);
9292

9393
$this->assertInstanceOf(
94-
'Clickalicious\Rng\Generator',
94+
Generator::class,
9595
$generator
9696
);
9797
}
@@ -108,7 +108,7 @@ public function testCreatingInstanceByModeOpenSsl()
108108
);
109109

110110
$this->assertInstanceOf(
111-
'Clickalicious\Rng\Generator',
111+
Generator::class,
112112
$generator
113113
);
114114
}
@@ -176,7 +176,7 @@ public function testCreatingInstanceByInvalidModeException()
176176
public function testGeneratingIntegerSeed()
177177
{
178178
$generator = new Generator();
179-
$seed = $generator->generateSeed();
179+
$seed = $generator->generateSeed();
180180

181181
$this->assertInternalType('int', $seed);
182182
}
@@ -188,7 +188,7 @@ public function testGeneratingIntegerSeed()
188188
*/
189189
public function testCreatingInstanceByModeOpenSslWithSeed()
190190
{
191-
$seed = 123456;
191+
$seed = 123456;
192192
$generator = new Generator(Generator::MODE_OPEN_SSL, $seed);
193193
$this->assertSame($seed, $generator->getSeed());
194194
}
@@ -200,7 +200,7 @@ public function testCreatingInstanceByModeOpenSslWithSeed()
200200
*/
201201
public function testCreatingInstanceByModePhpDefaultWithSeed()
202202
{
203-
$seed = 123456;
203+
$seed = 123456;
204204
$generator = new Generator(Generator::MODE_PHP_DEFAULT, $seed);
205205
$this->assertSame($seed, $generator->getSeed());
206206
}
@@ -212,7 +212,7 @@ public function testCreatingInstanceByModePhpDefaultWithSeed()
212212
*/
213213
public function testCreatingInstanceByModePhpMersenneTwisterWithSeed()
214214
{
215-
$seed = 123456;
215+
$seed = 123456;
216216
$generator = new Generator(Generator::MODE_PHP_MERSENNE_TWISTER, $seed);
217217
$this->assertSame($seed, $generator->getSeed());
218218
}
@@ -225,7 +225,7 @@ public function testCreatingInstanceByModePhpMersenneTwisterWithSeed()
225225
*/
226226
public function testTryToSetVariableWithInvalidTypeForSeed()
227227
{
228-
$seed = 'Foo';
228+
$seed = 'Foo';
229229
$generator = new Generator();
230230
$generator
231231
->setSeed($seed);
@@ -277,6 +277,34 @@ public function testTryToSetInvalidEncryptionMode()
277277
public function testPassingSeedToConstructor()
278278
{
279279
$generator = new Generator(Generator::MODE_OPEN_SSL, time());
280-
$this->assertInstanceOf('Clickalicious\Rng\Generator', $generator);
280+
$this->assertInstanceOf(Generator::class, $generator);
281+
}
282+
283+
/**
284+
* Test: Test should throw the invalid range excpetion.
285+
*
286+
* @author Benjamin Carl <opensource@clickalicious.de>
287+
*/
288+
public function testGenerateOnInvalidRange()
289+
{
290+
$this->expectException(Exception::class);
291+
$this->expectExceptionMessage('Bad range');
292+
$generator = new Generator(Generator::MODE_OPEN_SSL);
293+
$generator->generate(-PHP_INT_MAX, PHP_INT_MAX);
294+
}
295+
296+
/**
297+
* Test: Test should throw the invalid range excpetion.
298+
*
299+
* @author Benjamin Carl <opensource@clickalicious.de>
300+
*/
301+
public function testIsCryptographicStrong()
302+
{
303+
$generator = new Generator(Generator::MODE_OPEN_SSL);
304+
$this->assertNull($generator->isCryptographicStrong());
305+
306+
$generator = new Generator(Generator::MODE_OPEN_SSL);
307+
$generator->generate();
308+
$this->assertTrue($generator->isCryptographicStrong());
281309
}
282310
}

0 commit comments

Comments
 (0)