|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Polyfill\Tests\Php82; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Polyfill\Php82\Random\Engine\Secure as SecureEnginePolyfill; |
| 16 | + |
| 17 | +/** |
| 18 | + * @author Tim Düsterhus <[email protected]> |
| 19 | + */ |
| 20 | +class RandomSecureEngineTest extends TestCase |
| 21 | +{ |
| 22 | + public function secureEngineProvider() |
| 23 | + { |
| 24 | + yield [new SecureEnginePolyfill()]; |
| 25 | + yield [new \Random\Engine\Secure()]; |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * @dataProvider secureEngineProvider |
| 30 | + */ |
| 31 | + public function testGenerateLength($v) |
| 32 | + { |
| 33 | + $this->assertSame(\PHP_INT_SIZE, \strlen($v->generate())); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * @dataProvider secureEngineProvider |
| 38 | + */ |
| 39 | + public function testCloneIsNotAllowed($v) |
| 40 | + { |
| 41 | + $this->expectException(\Error::class); |
| 42 | + $this->expectExceptionMessage("Trying to clone an uncloneable object of class Random\Engine\Secure"); |
| 43 | + |
| 44 | + clone $v; |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @dataProvider secureEngineProvider |
| 49 | + */ |
| 50 | + public function testSerializeIsNotAllowed($v) |
| 51 | + { |
| 52 | + $this->expectException(\Exception::class); |
| 53 | + $this->expectExceptionMessage("Serialization of 'Random\Engine\Secure' is not allowed"); |
| 54 | + |
| 55 | + serialize($v); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @dataProvider secureEngineProvider |
| 60 | + */ |
| 61 | + public function testUnserializeIsNotAllowed($v) |
| 62 | + { |
| 63 | + $this->expectException(\Exception::class); |
| 64 | + $this->expectExceptionMessageMatches("{Unserialization of '.*Random\\\\Engine\\\\Secure' is not allowed}"); |
| 65 | + |
| 66 | + unserialize(sprintf('O:%d:"%s":0:{}', \strlen(\get_class($v)), \get_class($v))); |
| 67 | + } |
| 68 | +} |
0 commit comments