You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.6 KiB
PHP

<?php
namespace Cijber\OpenSSL\Tests;
use Cijber\OpenSSL\BIO;
use PHPUnit\Framework\TestCase;
use RuntimeException;
class BIOTest extends TestCase
{
public function testCreationAndDestruction()
{
$bio = BIO::new();
$this->assertEquals(11, $bio->write("Hello world"));
$this->assertEquals("Hello world", $bio->read());
$bio->write("Hello world");
$bio->reset();
$this->assertEquals('', $bio->read());
}
public function testOpen()
{
$bio = BIO::open(__DIR__ . "/data/pkcs7/1.SF", "r");
$part = $bio->read(5);
$this->assertEquals("Signa", $part);
$this->assertEquals(5, $bio->tell());
$bio->seek(6);
$this->assertEquals(6, $bio->tell());
$part = $bio->read(3);
$this->assertEquals("ure", $part);
$bio->reset();
$this->assertEquals(0, $bio->tell());
}
public function testBuffer()
{
$bio = BIO::buffer("Hello world");
$this->assertEquals("Hello world", $bio->read());
$this->assertTrue($bio->eof());
$bio->reset();
$part = $bio->read(3);
$this->assertEquals("Hel", $part);
$this->assertEquals("lo", $bio->read(2));
$bio->reset();
$part = $bio->read(3);
$this->assertEquals("Hel", $part);
}
public function testUsingObjectAfterFree()
{
$bio = BIO::buffer("Hello world");
$this->assertTrue($bio->free());
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage("object Cijber\OpenSSL\BIO already freed, can't be used");
$bio->getType();
}
}