Skip to content

Commit

Permalink
qa: apply automated fixes suggested by Psalm and establish baseline
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Weier O'Phinney <[email protected]>
  • Loading branch information
weierophinney committed Jun 23, 2021
1 parent a35ba2c commit 6602a47
Show file tree
Hide file tree
Showing 9 changed files with 665 additions and 26 deletions.
638 changes: 638 additions & 0 deletions psalm-baseline.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function run()
$event = $this->event;

// Define callback used to determine whether or not to short-circuit
$shortCircuit = function ($r) use ($event) {
$shortCircuit = function ($r) use ($event): bool {
if ($r instanceof ResponseInterface) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions test/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function setUpMvcEvent(Application $app, $request, $response): Applicatio
return $app;
}

public function testRouteListenerRaisingExceptionTriggersDispatchErrorAndSkipsDispatch()
public function testRouteListenerRaisingExceptionTriggersDispatchErrorAndSkipsDispatch(): void
{
$events = $this->app->getEventManager();
$response = $this->prophesize(PhpEnvironment\Response::class)->reveal();
Expand Down Expand Up @@ -137,7 +137,7 @@ public function testRouteListenerRaisingExceptionTriggersDispatchErrorAndSkipsDi
$this->assertSame($response, $this->app->getResponse());
}

public function testStopPropagationFromPrevEventShouldBeCleared()
public function testStopPropagationFromPrevEventShouldBeCleared(): void
{
$events = $this->app->getEventManager();
$response = $this->prophesize(PhpEnvironment\Response::class)->reveal();
Expand Down
2 changes: 1 addition & 1 deletion test/AutoloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function classesToAutoload(): array
/**
* @dataProvider classesToAutoload
*/
public function testAutoloaderDoesNotTransformUnderscoresToDirectorySeparators(string $className)
public function testAutoloaderDoesNotTransformUnderscoresToDirectorySeparators(string $className): void
{
$autoloader = new Autoloader([
'namespaces' => [
Expand Down
10 changes: 5 additions & 5 deletions test/DbConnectedResourceAbstractFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,34 @@ protected function setUp(): void
$this->factory = new DbConnectedResourceAbstractFactory();
}

public function testWillNotCreateServiceIfConfigServiceMissing()
public function testWillNotCreateServiceIfConfigServiceMissing(): void
{
$this->services->has('config')->willReturn(false);
$this->assertFalse($this->factory->canCreate($this->services->reveal(), 'Foo'));
}

public function testWillNotCreateServiceIfApiToolsConfigMissing()
public function testWillNotCreateServiceIfApiToolsConfigMissing(): void
{
$this->services->has('config')->willReturn(true);
$this->services->get('config')->willReturn([]);
$this->assertFalse($this->factory->canCreate($this->services->reveal(), 'Foo'));
}

public function testWillNotCreateServiceIfApiToolsConfigIsNotAnArray()
public function testWillNotCreateServiceIfApiToolsConfigIsNotAnArray(): void
{
$this->services->has('config')->willReturn(true);
$this->services->get('config')->willReturn(['api-tools' => 'invalid']);
$this->assertFalse($this->factory->canCreate($this->services->reveal(), 'Foo'));
}

public function testWillNotCreateServiceIfApiToolsConfigDoesNotHaveDbConnectedSegment()
public function testWillNotCreateServiceIfApiToolsConfigDoesNotHaveDbConnectedSegment(): void
{
$this->services->has('config')->willReturn(true);
$this->services->get('config')->willReturn(['api-tools' => ['foo' => 'bar']]);
$this->assertFalse($this->factory->canCreate($this->services->reveal(), 'Foo'));
}

public function testWillNotCreateServiceIfDbConnectedSegmentDoesNotHaveRequestedName()
public function testWillNotCreateServiceIfDbConnectedSegmentDoesNotHaveRequestedName(): void
{
$this->services->has('config')->willReturn(true);
$this->services->get('config')
Expand Down
6 changes: 3 additions & 3 deletions test/DbConnectedResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function setInputFilter(
$p->setValue($resource, $inputFilter);
}

public function testCreatePullsDataFromComposedInputFilterWhenPresent()
public function testCreatePullsDataFromComposedInputFilterWhenPresent(): void
{
$filtered = [
'foo' => 'BAR',
Expand All @@ -60,7 +60,7 @@ public function testCreatePullsDataFromComposedInputFilterWhenPresent()
$this->assertEquals($filtered, $this->resource->create(['foo' => 'bar']));
}

public function testUpdatePullsDataFromComposedInputFilterWhenPresent()
public function testUpdatePullsDataFromComposedInputFilterWhenPresent(): void
{
$filtered = [
'foo' => 'BAR',
Expand All @@ -82,7 +82,7 @@ public function testUpdatePullsDataFromComposedInputFilterWhenPresent()
$this->assertEquals($filtered, $this->resource->update('foo', ['foo' => 'bar']));
}

public function testPatchPullsDataFromComposedInputFilterWhenPresent()
public function testPatchPullsDataFromComposedInputFilterWhenPresent(): void
{
$filtered = [
'foo' => 'BAR',
Expand Down
2 changes: 1 addition & 1 deletion test/Model/MongoConnectedListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function testDelete(string $lastId): void
$this->assertTrue($result);
}

public function testFetchAll()
public function testFetchAll(): void
{
$num = 3;
for ($i = 0; $i < $num; $i++) {
Expand Down
2 changes: 1 addition & 1 deletion test/MvcAuth/UnauthorizedListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class UnauthorizedListenerTest extends TestCase
/**
* @covers \Laminas\ApiTools\MvcAuth\UnauthorizedListener::__invoke
*/
public function testInvokePropagates403ResponseWhenAuthenticationHasFailed()
public function testInvokePropagates403ResponseWhenAuthenticationHasFailed(): void
{
$unauthorizedListener = new UnauthorizedListener();

Expand Down
25 changes: 13 additions & 12 deletions test/TableGatewayAbstractFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,55 +33,55 @@ protected function setUp(): void
$this->factory = new TableGatewayAbstractFactory();
}

public function testWillNotCreateServiceWithoutAppropriateSuffix()
public function testWillNotCreateServiceWithoutAppropriateSuffix(): void
{
$this->services->has('config')->shouldNotBeCalled();
$this->assertFalse($this->factory->canCreate($this->services->reveal(), 'Foo'));
}

public function testWillNotCreateServiceIfConfigServiceIsMissing()
public function testWillNotCreateServiceIfConfigServiceIsMissing(): void
{
$this->services->has('config')->willReturn(false);
$this->services->get('config')->shouldNotBeCalled();
$this->assertFalse($this->factory->canCreate($this->services->reveal(), 'Foo\Table'));
}

public function testWillNotCreateServiceIfMissingApiToolsConfig()
public function testWillNotCreateServiceIfMissingApiToolsConfig(): void
{
$this->services->has('config')->willReturn(true);
$this->services->get('config')->willReturn([]);
$this->assertFalse($this->factory->canCreate($this->services->reveal(), 'Foo\Table'));
}

public function testWillNotCreateServiceIfMissingDbConnectedConfigSegment()
public function testWillNotCreateServiceIfMissingDbConnectedConfigSegment(): void
{
$this->services->has('config')->willReturn(true);
$this->services->get('config')->willReturn(['api-tools' => []]);
$this->assertFalse($this->factory->canCreate($this->services->reveal(), 'Foo\Table'));
}

public function testWillNotCreateServiceIfMissingServiceSubSegment()
public function testWillNotCreateServiceIfMissingServiceSubSegment(): void
{
$this->services->has('config')->willReturn(true);
$this->services->get('config')->willReturn(['api-tools' => ['db-connected' => []]]);
$this->assertFalse($this->factory->canCreate($this->services->reveal(), 'Foo\Table'));
}

public function testWillNotCreateServiceIfServiceSubSegmentIsInvalid()
public function testWillNotCreateServiceIfServiceSubSegmentIsInvalid(): void
{
$this->services->has('config')->willReturn(true);
$this->services->get('config')->willReturn(['api-tools' => ['db-connected' => ['Foo' => 'invalid']]]);
$this->assertFalse($this->factory->canCreate($this->services->reveal(), 'Foo\Table'));
}

public function testWillNotCreateServiceIfServiceSubSegmentDoesNotContainTableName()
public function testWillNotCreateServiceIfServiceSubSegmentDoesNotContainTableName(): void
{
$this->services->has('config')->willReturn(true);
$this->services->get('config')->willReturn(['api-tools' => ['db-connected' => ['Foo' => []]]]);
$this->assertFalse($this->factory->canCreate($this->services->reveal(), 'Foo\Table'));
}

public function testWillNotCreateServiceIfServiceSubSegmentDoesNotContainAdapterInformation()
public function testWillNotCreateServiceIfServiceSubSegmentDoesNotContainAdapterInformation(): void
{
$this->services->has('config')->willReturn(true);
$this->services->get('config')
Expand All @@ -102,7 +102,7 @@ public function testWillNotCreateServiceIfServiceSubSegmentDoesNotContainAdapter
$this->assertFalse($this->factory->canCreate($this->services->reveal(), 'Foo\Table'));
}

public function testWillCreateServiceIfConfigContainsValidTableNameAndAdapterName()
public function testWillCreateServiceIfConfigContainsValidTableNameAndAdapterName(): void
{
$this->services->has('config')->willReturn(true);
$this->services->get('config')
Expand All @@ -121,7 +121,8 @@ public function testWillCreateServiceIfConfigContainsValidTableNameAndAdapterNam
$this->assertTrue($this->factory->canCreate($this->services->reveal(), 'Foo\Table'));
}

public function testWillCreateServiceIfConfigContainsValidTableNameNoAdapterNameAndServicesContainDefaultAdapter()
// phpcs:ignore Generic.Files.LineLength.TooLong
public function testWillCreateServiceIfConfigContainsValidTableNameNoAdapterNameAndServicesContainDefaultAdapter(): void
{
$this->services->has('config')->willReturn(true);
$this->services->get('config')
Expand Down Expand Up @@ -154,7 +155,7 @@ public function validConfig(): array
/**
* @dataProvider validConfig
*/
public function testFactoryReturnsTableGatewayInstanceBasedOnConfiguration(string $adapterServiceName)
public function testFactoryReturnsTableGatewayInstanceBasedOnConfiguration(string $adapterServiceName): void
{
$hydrator = $this->prophesize($this->getClassMethodsHydratorClassName())->reveal();

Expand Down Expand Up @@ -208,7 +209,7 @@ public function testFactoryReturnsTableGatewayInstanceBasedOnConfiguration(strin
*/
public function testFactoryReturnsTableGatewayInstanceBasedOnConfigurationWithoutLaminasRest(
string $adapterServiceName
) {
): void {
$hydrator = $this->prophesize($this->getClassMethodsHydratorClassName())->reveal();

$hydrators = $this->prophesize(HydratorPluginManager::class);
Expand Down

0 comments on commit 6602a47

Please sign in to comment.