Skip to content

Commit

Permalink
Class Query should not be final
Browse files Browse the repository at this point in the history
We use your nice little package in our project. We added it to our Dependency Injection container as a service.

Unfortunately the class `Query` is final. Therefore we can't create mocks for it and therefore can't unit test classes that depend on this service.

Example:
```
<?php
namespace Pickware\PickwareErpStarter\ImportExport\Csv;

use Franzose\DoctrineBulkInsert\Query;
use PHPUnit\Framework\TestCase;

class CsvToDatabaseReaderTest extends TestCase
{
    /**
     * @before
     */
    public function setUpTest()
    {
        $this->bulkInserterMock = $this->createMock(Query::class);
        $this->csvToDatabaseReader = new CsvToDatabaseReader($this->bulkInserterMock);
    }

    public function test_readChunk()
    {
        $this->csvToDatabaseReader->readChunk();
    }
}
```

Leads to:
```
Class "Franzose\DoctrineBulkInsert\Query" is declared "final" and cannot be mocked.
.../vendor/phpunit/phpunit/src/TextUI/Command.php:204
.../vendor/phpunit/phpunit/src/TextUI/Command.php:163
```

Also I think there is no reason, this should be final.
  • Loading branch information
windaishi authored Oct 13, 2020
1 parent 37ad988 commit 6846355
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Identifier;

final class Query
class Query
{
private $connection;

Expand Down

0 comments on commit 6846355

Please sign in to comment.