Skip to content

Commit 653267a

Browse files
committed
fix: add required response headers to test doubles
1 parent 93f9e57 commit 653267a

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

‎src/Client/TestDoubleFactory.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ final class TestDoubleFactory
2020
{
2121
public static function createResponse(array $body, array $header = []) : Response
2222
{
23+
$header = array_replace([
24+
Keys::CODE => 0,
25+
Keys::SYNC => 1,
26+
Keys::SCHEMA_ID => 0,
27+
], $header);
28+
2329
return new Response($header, $body);
2430
}
2531

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the tarantool/phpunit-extras package.
5+
*
6+
* (c) Eugene Leonovich <gen.work@gmail.com>
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+
declare(strict_types=1);
13+
14+
namespace Tarantool\PhpUnit\Tests\Client;
15+
16+
use PHPUnit\Framework\TestCase;
17+
use Tarantool\Client\Keys;
18+
use Tarantool\PhpUnit\Client\TestDoubleFactory;
19+
20+
final class TestDoubleFactoryTest extends TestCase
21+
{
22+
public function testResponseIncludesRequiredHeaderFieldsByDefault() : void
23+
{
24+
$response = TestDoubleFactory::createResponse([]);
25+
26+
self::assertSame(0, $response->getCode());
27+
self::assertSame(1, $response->getSync());
28+
self::assertSame(0, $response->getSchemaId());
29+
}
30+
31+
public function testCallerHeaderFieldsOverrideDefaults() : void
32+
{
33+
$response = TestDoubleFactory::createResponse([], [
34+
Keys::CODE => 7,
35+
Keys::SYNC => 42,
36+
Keys::SCHEMA_ID => 9,
37+
]);
38+
39+
self::assertSame(7, $response->getCode());
40+
self::assertSame(42, $response->getSync());
41+
self::assertSame(9, $response->getSchemaId());
42+
}
43+
}

0 commit comments

Comments
 (0)