Skip to content

Commit

Permalink
Add method name in exception
Browse files Browse the repository at this point in the history
When we assert a given exception should be thrown, and get this instead,
it is hard to figure out what went wrong.
  • Loading branch information
greg0ire committed Oct 10, 2023
1 parent 48edb33 commit 194f506
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
10 changes: 8 additions & 2 deletions tests/Doctrine/Tests/Mocks/ConnectionMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,18 @@ public function delete($table, array $criteria, array $types = [])
*/
public function fetchColumn($statement, array $params = [], $colunm = 0, array $types = [])
{
throw new BadMethodCallException('Call to deprecated method.');
throw new BadMethodCallException(sprintf(
'Call to deprecated method %s().',
__METHOD__
));
}

public function query(?string $sql = null): Result
{
throw new BadMethodCallException('Call to deprecated method.');
throw new BadMethodCallException(sprintf(
'Call to deprecated method %s().',
__METHOD__
));
}

/**
Expand Down
17 changes: 14 additions & 3 deletions tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
use Doctrine\DBAL\Exception as DBALException;
use Doctrine\DBAL\Platforms\AbstractPlatform;

use function sprintf;

/**
* Mock class for DatabasePlatform.
*/
class DatabasePlatformMock extends AbstractPlatform
{
public function prefersIdentityColumns(): bool
{
throw new BadMethodCallException('Call to deprecated method.');
throw new BadMethodCallException(sprintf(
'Call to deprecated method %s().',
__METHOD__
));
}

public function supportsIdentityColumns(): bool
Expand All @@ -25,7 +30,10 @@ public function supportsIdentityColumns(): bool

public function prefersSequences(): bool
{
throw new BadMethodCallException('Call to deprecated method.');
throw new BadMethodCallException(sprintf(
'Call to deprecated method %s().',
__METHOD__
));
}

public function supportsSequences(): bool
Expand Down Expand Up @@ -94,7 +102,10 @@ public function getClobTypeDeclarationSQL(array $field)

public function getName(): string
{
throw new BadMethodCallException('Call to deprecated method.');
throw new BadMethodCallException(sprintf(
'Call to deprecated method %s().',
__METHOD__
));
}

/**
Expand Down
7 changes: 6 additions & 1 deletion tests/Doctrine/Tests/Mocks/DriverMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Exception;

use function sprintf;

/**
* Mock class for Driver.
*/
Expand Down Expand Up @@ -70,7 +72,10 @@ public function setSchemaManager(AbstractSchemaManager $sm): void
*/
public function getName()
{
throw new BadMethodCallException('Call to deprecated method.');
throw new BadMethodCallException(sprintf(
'Call to deprecated method %s().',
__METHOD__
));
}

/**
Expand Down
6 changes: 5 additions & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Doctrine\Tests\OrmFunctionalTestCase;

use function debug_backtrace;
use function sprintf;

use const PHP_INT_MAX;

Expand Down Expand Up @@ -347,7 +348,10 @@ public function query($sql = null): Result
/** {@inheritDoc} */
public function executeUpdate($query, array $params = [], array $types = []): int
{
throw new BadMethodCallException('Call to deprecated method.');
throw new BadMethodCallException(sprintf(
'Call to deprecated method %s().',
__METHOD__
));
}

/** {@inheritDoc} */
Expand Down

0 comments on commit 194f506

Please sign in to comment.