Files
phpy/tests/phpunit/IterTest.php
T
he426100 84f0b2dd88 fix core dump when "new PyType" (#30)
* fix core dump when "new PyType"

* add test code

---------

Co-authored-by: 弄月 <{ID}+{username}@users.noreply.github.com>
2023-12-26 18:37:06 +08:00

34 lines
766 B
PHP

<?php
use PHPUnit\Framework\TestCase;
class IterTest extends TestCase
{
function testIter()
{
$os = PyCore::import('os');
$uname = $os->uname();
$iter = PyCore::iter($uname);
$this->assertTrue($iter instanceof PyIter);
$list = [];
while ($next = PyCore::next($iter)) {
$list[] = PyCore::scalar($next);
}
$this->assertIsArray($list);
$this->assertEquals(count($list), 5);
}
function testNewIter()
{
try {
new PyIter;
} catch (Error $error) {
$this->assertStringContainsString('private PyIter::__construct()', $error->getMessage());
$success = false;
}
$this->assertFalse($success);
}
}