Bladeren bron

Multiple expect conversions to chained calls

Chance 2 jaren geleden
bovenliggende
commit
0f57772057

+ 0 - 1
tests/Feature/ExampleTest.php

@@ -2,5 +2,4 @@
 
 test('example', function () {
     expect(true)->toBeTrue();
-//    expect('3')->toBe(3);
 });

+ 9 - 10
tests/Unit/Connection/UdpConnectionTest.php

@@ -2,6 +2,7 @@
 
 use Workerman\Connection\UdpConnection;
 use Symfony\Component\Process\PhpProcess;
+use Workerman\Protocols\Text;
 
 $remoteAddress = '[::1]:12345';
 beforeAll(function () use ($remoteAddress) {
@@ -20,16 +21,14 @@ it('tests ' . UdpConnection::class, function () use ($remoteAddress) {
 
     $socketClient = stream_socket_client("udp://$remoteAddress");
     $udpConnection = new UdpConnection($socketClient, $remoteAddress);
-    $udpConnection->protocol = \Workerman\Protocols\Text::class;
-    expect($udpConnection->send('foo'))->toBeTrue();
-
-    expect($udpConnection->getRemoteIp())->toBe('::1');
-    expect($udpConnection->getRemotePort())->toBe(12345);
-    expect($udpConnection->getRemoteAddress())->toBe($remoteAddress);
-    expect($udpConnection->getLocalIp())->toBeIn(['::1', '[::1]', '127.0.0.1']);
-    expect($udpConnection->getLocalPort())->toBeInt();
-
-    expect(json_encode($udpConnection))->toBeJson()
+    $udpConnection->protocol = Text::class;
+    expect($udpConnection->send('foo'))->toBeTrue()
+        ->and($udpConnection->getRemoteIp())->toBe('::1')
+        ->and($udpConnection->getRemotePort())->toBe(12345)
+        ->and($udpConnection->getRemoteAddress())->toBe($remoteAddress)
+        ->and($udpConnection->getLocalIp())->toBeIn(['::1', '[::1]', '127.0.0.1'])
+        ->and($udpConnection->getLocalPort())->toBeInt()
+        ->and(json_encode($udpConnection))->toBeJson()
         ->toContain('transport')
         ->toContain('getRemoteIp')
         ->toContain('remotePort')

+ 2 - 2
tests/Unit/Protocols/FrameTest.php

@@ -3,8 +3,8 @@
 use Workerman\Protocols\Frame;
 
 it('tests ::input', function () {
-    expect(Frame::input('foo'))->toBe(0);
-    expect(Frame::input("\0\0\0*foobar"))
+    expect(Frame::input('foo'))->toBe(0)
+        ->and(Frame::input("\0\0\0*foobar"))
         ->toBe(42);
 });
 

+ 6 - 6
tests/Unit/Protocols/Http/ResponseTest.php

@@ -5,9 +5,9 @@ use Workerman\Protocols\Http\Response;
 it('test some simple case', function () {
     $response = new Response(201, ['X-foo' => 'bar'], 'hello, xiami');
 
-    expect($response->getStatusCode())->toBe(201);
-    expect($response->getHeaders())->toBe(['X-foo' => 'bar']);
-    expect($response->rawBody())->toBe('hello, xiami');
+    expect($response->getStatusCode())->toBe(201)
+        ->and($response->getHeaders())->toBe(['X-foo' => 'bar'])
+        ->and($response->rawBody())->toBe('hello, xiami');
 
     //headers
     $response->header('abc', '123');
@@ -18,8 +18,8 @@ it('test some simple case', function () {
         ->toContain('abc: 123')
         ->toContain('def: 456');
     $response->withoutHeader('def');
-    expect((string)$response)->not->toContain('def: 456');
-    expect($response->getHeader('abc'))
+    expect((string)$response)->not->toContain('def: 456')
+        ->and($response->getHeader('abc'))
         ->toBe('123');
 
     $response->withStatus(202, 'some reason');
@@ -36,7 +36,7 @@ it('test some simple case', function () {
 
 
     //cookie
-    $response->cookie('foo', 'bar', httpOnly: true, domain: 'xia.moe');
+    $response->cookie('foo', 'bar', domain: 'xia.moe', httpOnly: true);
     expect((string)$response)
         ->toContain('Set-Cookie: foo=bar; Domain=xia.moe; HttpOnly');
 });

+ 9 - 11
tests/Unit/Protocols/TextTest.php

@@ -15,16 +15,14 @@ test(Text::class, function () {
     });
     //input without "\n"
     expect(Text::input('jhdxr', $connection))
-        ->toBe(0);
-    //input with "\n"
-    expect(Text::input("jhdxr\n", $connection))
-        ->toBe(6);
-
-    //::encode
-    expect(Text::encode('jhdxr'))
-        ->toBe("jhdxr\n");
-
-    //::decode
-    expect(Text::decode("jhdxr\n"))
+        ->toBe(0)
+        //input with "\n"
+        ->and(Text::input("jhdxr\n", $connection))
+        ->toBe(6)
+        //::encode
+        ->and(Text::encode('jhdxr'))
+        ->toBe("jhdxr\n")
+        //::decode
+        ->and(Text::decode("jhdxr\n"))
         ->toBe('jhdxr');
 });