Browse Source

Fix up tests.

mscherer 7 years ago
parent
commit
54e5a91f92

+ 20 - 20
tests/TestCase/Http/Client/RequestTest.php

@@ -37,10 +37,10 @@ class RequestTest extends TestCase
         $data = ['a' => 'b', 'c' => 'd'];
         $request = new Request('http://example.com', 'POST', $headers, json_encode($data));
 
-        $this->assertEquals('http://example.com', (string)$request->getUri());
+        $this->assertSame('http://example.com', (string)$request->getUri());
         $this->assertStringContainsString($request->getMethod(), 'POST');
-        $this->assertEquals('application/json', $request->getHeaderLine('Content-Type'));
-        $this->assertEquals(json_encode($data), $request->getBody()->__toString());
+        $this->assertSame('application/json', $request->getHeaderLine('Content-Type'));
+        $this->assertSame(json_encode($data), $request->getBody()->__toString());
     }
     /**
      * @param array $headers The HTTP headers to set.
@@ -53,10 +53,10 @@ class RequestTest extends TestCase
     {
         $request = new Request('http://example.com', $method, $headers, json_encode($data));
 
-        $this->assertEquals($request->getMethod(), $method);
-        $this->assertEquals('http://example.com', (string)$request->getUri());
-        $this->assertEquals('application/json', $request->getHeaderLine('Content-Type'));
-        $this->assertEquals(json_encode($data), $request->getBody()->__toString());
+        $this->assertSame($request->getMethod(), $method);
+        $this->assertSame('http://example.com', (string)$request->getUri());
+        $this->assertSame('application/json', $request->getHeaderLine('Content-Type'));
+        $this->assertSame(json_encode($data), $request->getBody()->__toString());
     }
     /**
      * @dataProvider additionProvider
@@ -91,10 +91,10 @@ class RequestTest extends TestCase
         $data = ['a' => 'b', 'c' => 'd'];
         $request = new Request('http://example.com', 'POST', $headers, $data);
 
-        $this->assertEquals('http://example.com', (string)$request->getUri());
-        $this->assertEquals('POST', $request->getMethod());
-        $this->assertEquals('application/x-www-form-urlencoded', $request->getHeaderLine('Content-Type'));
-        $this->assertEquals('a=b&c=d', $request->getBody()->__toString());
+        $this->assertSame('http://example.com', (string)$request->getUri());
+        $this->assertSame('POST', $request->getMethod());
+        $this->assertSame('application/x-www-form-urlencoded', $request->getHeaderLine('Content-Type'));
+        $this->assertSame('a=b&c=d', $request->getBody()->__toString());
     }
 
     /**
@@ -111,10 +111,10 @@ class RequestTest extends TestCase
         $data = ['a' => 'b', 'c' => ['foo', 'bar']];
         $request = new Request('http://example.com', 'POST', $headers, $data);
 
-        $this->assertEquals('http://example.com', (string)$request->getUri());
-        $this->assertEquals('POST', $request->getMethod());
-        $this->assertEquals('application/x-www-form-urlencoded', $request->getHeaderLine('Content-Type'));
-        $this->assertEquals('a=b&c%5B0%5D=foo&c%5B1%5D=bar', $request->getBody()->__toString());
+        $this->assertSame('http://example.com', (string)$request->getUri());
+        $this->assertSame('POST', $request->getMethod());
+        $this->assertSame('application/x-www-form-urlencoded', $request->getHeaderLine('Content-Type'));
+        $this->assertSame('a=b&c%5B0%5D=foo&c%5B1%5D=bar', $request->getBody()->__toString());
     }
 
     /**
@@ -127,7 +127,7 @@ class RequestTest extends TestCase
         $data = '{"json":"data"}';
         $request = new Request('', Request::METHOD_GET, [], $data);
 
-        $this->assertEquals($data, $request->getBody()->__toString());
+        $this->assertSame($data, $request->getBody()->__toString());
     }
 
     /**
@@ -143,8 +143,8 @@ class RequestTest extends TestCase
             'e' => ['f', 'g'],
         ];
         $request = new Request('', Request::METHOD_GET, [], $data);
-        $this->assertEquals('application/x-www-form-urlencoded', $request->getHeaderLine('content-type'));
-        $this->assertEquals(
+        $this->assertSame('application/x-www-form-urlencoded', $request->getHeaderLine('content-type'));
+        $this->assertSame(
             'a=b&c=d&e%5B0%5D=f&e%5B1%5D=g',
             $request->getBody()->__toString(),
             'Body should be serialized'
@@ -174,7 +174,7 @@ class RequestTest extends TestCase
     public function testDefaultHeaders()
     {
         $request = new Request();
-        $this->assertEquals('CakePHP', $request->getHeaderLine('User-Agent'));
-        $this->assertEquals('close', $request->getHeaderLine('Connection'));
+        $this->assertSame('CakePHP', $request->getHeaderLine('User-Agent'));
+        $this->assertSame('close', $request->getHeaderLine('Connection'));
     }
 }

+ 17 - 6
tests/TestCase/Http/ServerTest.php

@@ -37,6 +37,11 @@ require_once __DIR__ . '/server_mocks.php';
 class ServerTest extends TestCase
 {
     /**
+     * @var string
+     */
+    protected $config;
+
+    /**
      * Setup
      *
      * @return void
@@ -69,7 +74,8 @@ class ServerTest extends TestCase
      */
     public function testAppGetSet()
     {
-        $app = $this->getMockBuilder('Cake\Http\BaseApplication')
+        /** @var \Cake\Http\BaseApplication|\PHPUnit\Framework\MockObject\MockObject $app */
+        $app = $this->getMockBuilder(BaseApplication::class)
             ->setConstructorArgs([$this->config])
             ->getMock();
 
@@ -78,7 +84,7 @@ class ServerTest extends TestCase
             ->willReturn($manager);
 
         $server = new Server($app);
-        $this->assertSame($app, $server->getApp($app));
+        $this->assertSame($app, $server->getApp());
         $this->assertSame($app->getEventManager(), $server->getEventManager());
     }
 
@@ -118,6 +124,7 @@ class ServerTest extends TestCase
         $request = new ServerRequest();
         $request = $request->withHeader('X-pass', 'request header');
 
+        /** @var \TestApp\Http\MiddlewareApplication|\PHPUnit\Framework\MockObject\MockObject $app */
         $app = $this->getMockBuilder(MiddlewareApplication::class)
             ->setMethods(['pluginBootstrap', 'pluginEvents', 'pluginMiddleware'])
             ->setConstructorArgs([$this->config])
@@ -132,7 +139,7 @@ class ServerTest extends TestCase
             }));
 
         $server = new Server($app);
-        $res = $server->run($request, $response);
+        $res = $server->run($request);
         $this->assertEquals(
             'source header',
             $res->getHeaderLine('X-testing'),
@@ -233,8 +240,7 @@ class ServerTest extends TestCase
         $server = new Server($app);
         $this->called = false;
 
-        $server->getEventManager()->on('Server.buildMiddleware', function (EventInterface $event, $middleware) {
-            $this->assertInstanceOf('Cake\Http\MiddlewareQueue', $middleware);
+        $server->getEventManager()->on('Server.buildMiddleware', function (EventInterface $event, MiddlewareQueue $middleware) {
             $middleware->add(function ($req, $res, $next) {
                 $this->called = true;
 
@@ -255,6 +261,7 @@ class ServerTest extends TestCase
      */
     public function testEventManagerProxies()
     {
+        /** @var \Cake\Http\BaseApplication|\PHPUnit\Framework\MockObject\MockObject $app */
         $app = $this->getMockForAbstractClass(
             BaseApplication::class,
             [$this->config]
@@ -271,6 +278,7 @@ class ServerTest extends TestCase
      */
     public function testGetEventManagerNonEventedApplication()
     {
+        /** @var \Cake\Core\HttpApplicationInterface|\PHPUnit\Framework\MockObject\MockObject $app */
         $app = $this->createMock(HttpApplicationInterface::class);
 
         $server = new Server($app);
@@ -284,11 +292,14 @@ class ServerTest extends TestCase
      */
     public function testSetEventManagerNonEventedApplication()
     {
-        $this->expectException(InvalidArgumentException::class);
+        /** @var \Cake\Core\HttpApplicationInterface|\PHPUnit\Framework\MockObject\MockObject $app */
         $app = $this->createMock(HttpApplicationInterface::class);
 
         $events = new EventManager();
         $server = new Server($app);
+
+        $this->expectException(InvalidArgumentException::class);
+
         $server->setEventManager($events);
     }
 }

+ 0 - 2
tests/TestCase/Http/SessionTest.php

@@ -26,8 +26,6 @@ use TestApp\Http\Session\TestWebSession;
  */
 class SessionTest extends TestCase
 {
-    protected static $_gcDivisor;
-
     /**
      * Fixtures used in the SessionTest
      *