Skip to content

Commit

Permalink
Merge pull request #3228 from peter279k/assertion_enhancement
Browse files Browse the repository at this point in the history
Using assertSame to let assert equal be restricted
  • Loading branch information
akrabat committed Nov 5, 2022
2 parents 3d7ea05 + 3c13502 commit ca629c1
Show file tree
Hide file tree
Showing 18 changed files with 174 additions and 174 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
Expand All @@ -27,7 +27,7 @@ jobs:
coverage: xdebug

- name: Install dependencies with Composer
uses: ramsey/composer-install@v1
uses: ramsey/composer-install@v2

- name: Coding standards
if: matrix.analysis
Expand Down
66 changes: 33 additions & 33 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function testGetPostPutPatchDeleteOptionsMethods(string $method): void
});
$response = $app->handle($requestProphecy->reveal());

$this->assertEquals('Hello World', (string) $response->getBody());
$this->assertSame('Hello World', (string) $response->getBody());
}

public function testAnyRoute(): void
Expand Down Expand Up @@ -236,7 +236,7 @@ public function testAnyRoute(): void

$response = $app->handle($requestProphecy->reveal());

$this->assertEquals('Hello World', (string) $response->getBody());
$this->assertSame('Hello World', (string) $response->getBody());
}
}

Expand Down Expand Up @@ -290,7 +290,7 @@ public function testMapRoute(string $method): void
});
$response = $app->handle($requestProphecy->reveal());

$this->assertEquals('Hello World', (string) $response->getBody());
$this->assertSame('Hello World', (string) $response->getBody());
}

public function testRedirectRoute(): void
Expand Down Expand Up @@ -333,8 +333,8 @@ public function testRedirectRoute(): void
$response = $app->handle($requestProphecy->reveal());

$responseFactoryProphecy->createResponse(301)->shouldHaveBeenCalled();
$this->assertEquals(301, $response->getStatusCode());
$this->assertEquals($to, $response->getHeaderLine('Location'));
$this->assertSame(301, $response->getStatusCode());
$this->assertSame($to, $response->getHeaderLine('Location'));
}

public function testRouteWithInternationalCharacters(): void
Expand Down Expand Up @@ -369,7 +369,7 @@ public function testRouteWithInternationalCharacters(): void
$response = $app->handle($requestProphecy->reveal());

$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertEquals('Hello World', (string) $response->getBody());
$this->assertSame('Hello World', (string) $response->getBody());
}

/********************************************************************************
Expand Down Expand Up @@ -402,7 +402,7 @@ public function testRoutePatterns(string $pattern): void
$routeCollector = $app->getRouteCollector();
$route = $routeCollector->lookupRoute('route0');

$this->assertEquals($pattern, $route->getPattern());
$this->assertSame($pattern, $route->getPattern());
}

/********************************************************************************
Expand Down Expand Up @@ -566,7 +566,7 @@ public function testRouteGroupCombinations(array $sequence, string $expectedPath
$routeCollector = $app->getRouteCollector();
$route = $routeCollector->lookupRoute('route0');

$this->assertEquals($expectedPath, $route->getPattern());
$this->assertSame($expectedPath, $route->getPattern());
}

public function testRouteGroupPattern(): void
Expand All @@ -579,7 +579,7 @@ public function testRouteGroupPattern(): void
$group = $app->group('/foo', function () {
});

$this->assertEquals('/foo', $group->getPattern());
$this->assertSame('/foo', $group->getPattern());
}

/********************************************************************************
Expand Down Expand Up @@ -855,7 +855,7 @@ public function testAddMiddlewareOnRoute(): void

$app->handle($requestProphecy->reveal());

$this->assertEquals('In2In1CenterOut1Out2', $output);
$this->assertSame('In2In1CenterOut1Out2', $output);
}

public function testAddMiddlewareOnRouteGroup(): void
Expand Down Expand Up @@ -937,7 +937,7 @@ public function testAddMiddlewareOnRouteGroup(): void

$app->handle($requestProphecy->reveal());

$this->assertEquals('In2In1CenterOut1Out2', $output);
$this->assertSame('In2In1CenterOut1Out2', $output);
}

public function testAddMiddlewareOnTwoRouteGroup(): void
Expand Down Expand Up @@ -1057,7 +1057,7 @@ public function testAddMiddlewareOnTwoRouteGroup(): void

$app->handle($requestProphecy->reveal());

$this->assertEquals('In1In2In3CenterOut3Out2Out1', $output);
$this->assertSame('In1In2In3CenterOut3Out2Out1', $output);
}

public function testAddMiddlewareAsStringNotImplementingInterfaceThrowsException(): void
Expand Down Expand Up @@ -1132,7 +1132,7 @@ public function testInvokeWithMatchingRoute(): void
$response = $app->handle($requestProphecy->reveal());

$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertEquals('Hello World', (string) $response->getBody());
$this->assertSame('Hello World', (string) $response->getBody());
}

public function testInvokeWithMatchingRouteWithSetArgument(): void
Expand Down Expand Up @@ -1172,7 +1172,7 @@ public function testInvokeWithMatchingRouteWithSetArgument(): void
$response = $app->handle($requestProphecy->reveal());

$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertEquals('Hello World', (string) $response->getBody());
$this->assertSame('Hello World', (string) $response->getBody());
}

public function testInvokeWithMatchingRouteWithSetArguments(): void
Expand Down Expand Up @@ -1212,7 +1212,7 @@ public function testInvokeWithMatchingRouteWithSetArguments(): void
$response = $app->handle($requestProphecy->reveal());

$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertEquals('Hello World', (string) $response->getBody());
$this->assertSame('Hello World', (string) $response->getBody());
}

public function testInvokeWithMatchingRouteWithNamedParameterRequestResponseStrategy(): void
Expand Down Expand Up @@ -1252,7 +1252,7 @@ public function testInvokeWithMatchingRouteWithNamedParameterRequestResponseStra
$response = $app->handle($requestProphecy->reveal());

$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertEquals('Hello World', (string) $response->getBody());
$this->assertSame('Hello World', (string) $response->getBody());
}

public function testInvokeWithMatchingRouteWithNamedParameterRequestResponseArgStrategy(): void
Expand Down Expand Up @@ -1293,7 +1293,7 @@ public function testInvokeWithMatchingRouteWithNamedParameterRequestResponseArgS
$response = $app->handle($requestProphecy->reveal());

$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertEquals('Hello World', (string) $response->getBody());
$this->assertSame('Hello World', (string) $response->getBody());
}

public function testInvokeWithMatchingRouteWithNamedParameterRequestResponseNamedArgsStrategy(): void
Expand Down Expand Up @@ -1341,7 +1341,7 @@ function (ServerRequestInterface $request, ResponseInterface $response, $name, $
$response = $app->handle($requestProphecy->reveal());

$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertEquals('Hello World', (string) $response->getBody());
$this->assertSame('Hello World', (string) $response->getBody());
}

public function testInvokeWithMatchingRouteWithNamedParameterOverwritesSetArgument(): void
Expand Down Expand Up @@ -1381,7 +1381,7 @@ public function testInvokeWithMatchingRouteWithNamedParameterOverwritesSetArgume
$response = $app->handle($requestProphecy->reveal());

$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertEquals('Hello World', (string) $response->getBody());
$this->assertSame('Hello World', (string) $response->getBody());
}

public function testInvokeWithoutMatchingRoute(): void
Expand Down Expand Up @@ -1447,7 +1447,7 @@ public function foo(ServerRequestInterface $request, ResponseInterface $response
$response = $app->handle($requestProphecy->reveal());

$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertEquals('Hello World', (string) $response->getBody());
$this->assertSame('Hello World', (string) $response->getBody());
}

public function testInvokeWithNonExistentMethodOnCallableRegisteredInContainer(): void
Expand Down Expand Up @@ -1527,7 +1527,7 @@ public function testInvokeWithCallableInContainerViaCallMagicMethod(): void

$expectedPayload = json_encode(['name' => 'foo', 'arguments' => []]);
$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertEquals($expectedPayload, (string) $response->getBody());
$this->assertSame($expectedPayload, (string) $response->getBody());
}

public function testInvokeFunctionName(): void
Expand Down Expand Up @@ -1573,7 +1573,7 @@ function handle($request, ResponseInterface $response)
$response = $app->handle($requestProphecy->reveal());

$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertEquals('Hello World', (string) $response->getBody());
$this->assertSame('Hello World', (string) $response->getBody());
}

public function testCurrentRequestAttributesAreNotLostWhenAddingRouteArguments(): void
Expand Down Expand Up @@ -1613,7 +1613,7 @@ public function testCurrentRequestAttributesAreNotLostWhenAddingRouteArguments()
$response = $app->handle($requestProphecy->reveal()->withAttribute('greeting', 'Hello'));

$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertEquals('Hello World', (string) $response->getBody());
$this->assertSame('Hello World', (string) $response->getBody());
}

public function testCurrentRequestAttributesAreNotLostWhenAddingRouteArgumentsRequestResponseArg(): void
Expand Down Expand Up @@ -1654,7 +1654,7 @@ public function testCurrentRequestAttributesAreNotLostWhenAddingRouteArgumentsRe
$response = $app->handle($requestProphecy->reveal()->withAttribute('greeting', 'Hello'));

$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertEquals('Hello World', (string) $response->getBody());
$this->assertSame('Hello World', (string) $response->getBody());
}

public function testRun(): void
Expand Down Expand Up @@ -1801,7 +1801,7 @@ public function testHandleReturnsEmptyResponseBodyWithHeadRequestMethod(): void

$response = $app->handle($requestProphecy->reveal());

$this->assertEquals(1, $called);
$this->assertSame(1, $called);
$this->assertEmpty((string) $response->getBody());
}

Expand Down Expand Up @@ -1917,7 +1917,7 @@ public function testCanBeReExecutedRecursivelyDuringDispatch(): void

$this->assertSame(204, $response->getStatusCode());
$this->assertSame(['nested', 'outer'], $response->getHeader('X-TRACE'));
$this->assertEquals('11', (string) $response->getBody());
$this->assertSame('11', (string) $response->getBody());
}

// TODO: Re-add testUnsupportedMethodWithoutRoute
Expand Down Expand Up @@ -1959,7 +1959,7 @@ public function testContainerSetToRoute(): void

$response = $app->handle($requestProphecy->reveal());

$this->assertEquals('Hello World', (string) $response->getBody());
$this->assertSame('Hello World', (string) $response->getBody());
}

public function testAppIsARequestHandler(): void
Expand Down Expand Up @@ -2005,7 +2005,7 @@ public function testInvokeSequentialProcessToAPathWithOptionalArgsAndWithoutOpti
});

$response = $app->handle($requestProphecy->reveal());
$this->assertEquals('1', (string) $response->getBody());
$this->assertSame('1', (string) $response->getBody());

$uriProphecy2 = $this->prophesize(UriInterface::class);
$uriProphecy2->getPath()->willReturn('/Hello');
Expand All @@ -2021,7 +2021,7 @@ public function testInvokeSequentialProcessToAPathWithOptionalArgsAndWithoutOpti

$streamProphecy->__toString()->willReturn('');
$response = $app->handle($requestProphecy2->reveal());
$this->assertEquals('0', (string) $response->getBody());
$this->assertSame('0', (string) $response->getBody());
}

public function testInvokeSequentialProcessToAPathWithOptionalArgsAndWithoutOptionalArgsAndKeepSetedArgs(): void
Expand Down Expand Up @@ -2059,7 +2059,7 @@ public function testInvokeSequentialProcessToAPathWithOptionalArgsAndWithoutOpti
});

$response = $app->handle($requestProphecy->reveal());
$this->assertEquals('2', (string) $response->getBody());
$this->assertSame('2', (string) $response->getBody());

$uriProphecy2 = $this->prophesize(UriInterface::class);
$uriProphecy2->getPath()->willReturn('/Hello');
Expand All @@ -2075,7 +2075,7 @@ public function testInvokeSequentialProcessToAPathWithOptionalArgsAndWithoutOpti

$streamProphecy->__toString()->willReturn('');
$response = $app->handle($requestProphecy2->reveal());
$this->assertEquals('1', (string) $response->getBody());
$this->assertSame('1', (string) $response->getBody());
}

public function testInvokeSequentialProcessAfterAddingAnotherRouteArgument(): void
Expand Down Expand Up @@ -2118,12 +2118,12 @@ public function testInvokeSequentialProcessAfterAddingAnotherRouteArgument(): vo
});

$response = $app->handle($requestProphecy->reveal());
$this->assertEquals('2', (string) $response->getBody());
$this->assertSame('2', (string) $response->getBody());

$route->setArgument('extra2', 'value2');

$streamProphecy->__toString()->willReturn('');
$response = $app->handle($requestProphecy->reveal());
$this->assertEquals('3', (string) $response->getBody());
$this->assertSame('3', (string) $response->getBody());
}
}
Loading

0 comments on commit ca629c1

Please sign in to comment.