Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
- Remove test classes from library
- Analyze tests with psalm and fix most of the
  issues, although some cannot be fixed
- Improve type hinting in tests
  • Loading branch information
iquito committed Jun 13, 2021
1 parent 2ddb3dd commit d7f152d
Show file tree
Hide file tree
Showing 26 changed files with 498 additions and 443 deletions.
3 changes: 0 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory>src/TestHelpers</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Unit Tests">
Expand Down
29 changes: 28 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.3.1@2feba22a005a18bf31d4c7b9bdb9252c73897476">
<files psalm-version="4.7.3@38c452ae584467e939d55377aaf83b5a26f19dd1">
<file src="src/Builder/FlattenedFieldsWithTypeTrait.php">
<InvalidReturnType occurrences="4">
<code>bool[]</code>
Expand All @@ -23,4 +23,31 @@
<code>$select['offset'] ?? null</code>
</PossiblyNullArgument>
</file>
<file src="tests/DBPassToLowerLayerTest.php">
<InvalidPropertyAssignmentValue occurrences="1">
<code>\Mockery::mock(DBPassToLowerLayerTrait::class)-&gt;makePartial()</code>
</InvalidPropertyAssignmentValue>
<UndefinedClass occurrences="2">
<code>$this-&gt;dbLowerLayerObject</code>
<code>\Mockery::mock(DBPassToLowerLayerTrait::class)</code>
</UndefinedClass>
<UndefinedInterfaceMethod occurrences="1">
<code>setLowerLayer</code>
</UndefinedInterfaceMethod>
</file>
<file src="tests/Integration/AbstractDoctrineIntegrationTests.php">
<InvalidScalarArgument occurrences="2">
<code>$accountData['balance']</code>
<code>$accountData['balance']</code>
</InvalidScalarArgument>
<PossiblyNullReference occurrences="2">
<code>fetchOne</code>
<code>insert</code>
</PossiblyNullReference>
</file>
<file src="tests/LargeObjectTest.php">
<RedundantConditionGivenDocblockType occurrences="1">
<code>\is_resource($obj-&gt;getStream())</code>
</RedundantConditionGivenDocblockType>
</file>
</files>
38 changes: 38 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,46 @@
>
<projectFiles>
<directory name="src" />
<directory name="tests" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<!-- Tests have static values initialized in the tests -->
<PropertyNotSetInConstructor>
<errorLevel type="suppress">
<directory name="tests"/>
</errorLevel>
</PropertyNotSetInConstructor>
<!-- Deprecated method warnings in tests are false-positives -->
<DeprecatedMethod>
<errorLevel type="suppress">
<directory name="tests"/>
</errorLevel>
</DeprecatedMethod>
<!-- Conflicts with tests where invalid arguments are tested -->
<InvalidArgument>
<errorLevel type="suppress">
<directory name="tests"/>
</errorLevel>
</InvalidArgument>
<!-- We test with internal doctrine classes and methods -->
<InternalClass>
<errorLevel type="suppress">
<directory name="tests"/>
</errorLevel>
</InternalClass>
<InternalMethod>
<errorLevel type="suppress">
<directory name="tests"/>
</errorLevel>
</InternalMethod>
</issueHandlers>

<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
<pluginClass class="Psalm\MockeryPlugin\Plugin"/>
</plugins>
</psalm>
27 changes: 0 additions & 27 deletions src/TestHelpers/DBInterfaceForTests.php

This file was deleted.

9 changes: 0 additions & 9 deletions src/TestHelpers/DBSelectQueryForTests.php

This file was deleted.

13 changes: 6 additions & 7 deletions tests/Builder/CountEntriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

namespace Squirrel\Queries\Tests\Builder;

use Mockery\MockInterface;
use Squirrel\Queries\Builder\CountEntries;
use Squirrel\Queries\DBInterface;

class CountEntriesTest extends \PHPUnit\Framework\TestCase
{
/**
* @var DBInterface
*/
private $db;
/** @var DBInterface&MockInterface */
private DBInterface $db;

protected function setUp(): void
{
$this->db = \Mockery::mock(DBInterface::class);
}

public function testNoDataGetEntries()
public function testNoDataGetEntries(): void
{
$countBuilder = new CountEntries($this->db);

Expand All @@ -41,7 +40,7 @@ public function testNoDataGetEntries()
$this->assertSame($expectedResult[0], $results);
}

public function testGetEntries()
public function testGetEntries(): void
{
$countBuilder = new CountEntries($this->db);

Expand Down Expand Up @@ -79,7 +78,7 @@ public function testGetEntries()
$this->assertSame($expectedResult[0], $results);
}

public function testGetEntriesSingular()
public function testGetEntriesSingular(): void
{
$countBuilder = new CountEntries($this->db);

Expand Down
15 changes: 7 additions & 8 deletions tests/Builder/DeleteEntriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@

namespace Squirrel\Queries\Tests\Builder;

use Mockery\MockInterface;
use Squirrel\Queries\Builder\DeleteEntries;
use Squirrel\Queries\DBInterface;
use Squirrel\Queries\Exception\DBInvalidOptionException;

class DeleteEntriesTest extends \PHPUnit\Framework\TestCase
{
/**
* @var DBInterface
*/
private $db;
/** @var DBInterface&MockInterface */
private DBInterface $db;

protected function setUp(): void
{
$this->db = \Mockery::mock(DBInterface::class);
}

public function testNoDataGetEntries()
public function testNoDataGetEntries(): void
{
$deleteBuilder = new DeleteEntries($this->db);

Expand All @@ -37,7 +36,7 @@ public function testNoDataGetEntries()
$this->assertTrue(true);
}

public function testNoDataGetEntriesWithAffected()
public function testNoDataGetEntriesWithAffected(): void
{
$deleteBuilder = new DeleteEntries($this->db);

Expand All @@ -56,7 +55,7 @@ public function testNoDataGetEntriesWithAffected()
$this->assertSame($expectedResult, $results);
}

public function testGetEntries()
public function testGetEntries(): void
{
$deleteBuilder = new DeleteEntries($this->db);

Expand All @@ -82,7 +81,7 @@ public function testGetEntries()
$this->assertSame($expectedResult, $results);
}

public function testNoWhereNoConfirmation()
public function testNoWhereNoConfirmation(): void
{
$this->expectException(DBInvalidOptionException::class);

Expand Down
13 changes: 6 additions & 7 deletions tests/Builder/InsertEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

namespace Squirrel\Queries\Tests\Builder;

use Mockery\MockInterface;
use Squirrel\Queries\Builder\InsertEntry;
use Squirrel\Queries\DBInterface;

class InsertEntryTest extends \PHPUnit\Framework\TestCase
{
/**
* @var DBInterface
*/
private $db;
/** @var DBInterface&MockInterface */
private DBInterface $db;

protected function setUp(): void
{
$this->db = \Mockery::mock(DBInterface::class);
}

public function testNoDataInsert()
public function testNoDataInsert(): void
{
$insertBuilder = new InsertEntry($this->db);

Expand All @@ -33,7 +32,7 @@ public function testNoDataInsert()
$this->assertTrue(true);
}

public function testInsert()
public function testInsert(): void
{
$insertBuilder = new InsertEntry($this->db);

Expand All @@ -58,7 +57,7 @@ public function testInsert()
$this->assertTrue(true);
}

public function testInsertWithNewId()
public function testInsertWithNewId(): void
{
$insertBuilder = new InsertEntry($this->db);

Expand Down
17 changes: 8 additions & 9 deletions tests/Builder/InsertOrUpdateEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

namespace Squirrel\Queries\Tests\Builder;

use Mockery\MockInterface;
use Squirrel\Queries\Builder\InsertOrUpdateEntry;
use Squirrel\Queries\DBInterface;

class InsertOrUpdateEntryTest extends \PHPUnit\Framework\TestCase
{
/**
* @var DBInterface
*/
private $db;
/** @var DBInterface&MockInterface */
private DBInterface $db;

protected function setUp(): void
{
$this->db = \Mockery::mock(DBInterface::class);
}

public function testNoDataInsert()
public function testNoDataInsert(): void
{
$insertBuilder = new InsertOrUpdateEntry($this->db);

Expand All @@ -33,7 +32,7 @@ public function testNoDataInsert()
$this->assertTrue(true);
}

public function testInsert()
public function testInsert(): void
{
$insertBuilder = new InsertOrUpdateEntry($this->db);

Expand Down Expand Up @@ -68,7 +67,7 @@ public function testInsert()
$this->assertTrue(true);
}

public function testInsertWithReturn()
public function testInsertWithReturn(): void
{
$insertBuilder = new InsertOrUpdateEntry($this->db);

Expand Down Expand Up @@ -103,7 +102,7 @@ public function testInsertWithReturn()
$this->assertTrue(true);
}

public function testUpdateWithReturn()
public function testUpdateWithReturn(): void
{
$insertBuilder = new InsertOrUpdateEntry($this->db);

Expand Down Expand Up @@ -134,7 +133,7 @@ public function testUpdateWithReturn()
$this->assertTrue(true);
}

public function testNoChangeWithReturn()
public function testNoChangeWithReturn(): void
{
$insertBuilder = new InsertOrUpdateEntry($this->db);

Expand Down
Loading

0 comments on commit d7f152d

Please sign in to comment.