You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
nextcloud-server/tests/lib/AppFramework/Http/StreamGeneratorResponseTest...

47 lines
1.1 KiB

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\AppFramework\Http;
use OCP\AppFramework\Http\IOutput;
use OCP\AppFramework\Http\StreamGeneratorResponse;
class StreamGeneratorResponseTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
}
public function testConstructor() {
$generator = function () {
yield 'chunk1';
yield 'chunk2';
};
$response = new StreamGeneratorResponse($generator(), 'text/plain');
$headers = $response->getHeaders();
$this->assertEquals('text/plain', $headers['Content-Type']);
$this->assertEquals(200, $response->getStatus());
}
public function testCallback() {
$count = 0;
$generator = function () use (&$count) {
$count++;
yield 'chunk1';
$count++;
yield 'chunk2';
};
$response = new StreamGeneratorResponse($generator(), 'text/plain');
$output = $this->createMock(IOutput::class);
$response->callback($output);
$this->assertEquals($count, 2);
}
}