Skip to content

Commit 984631b

Browse files
committed
Merge upstream/0.6.x (PR #142) into test/adapter-coverage-100
Resolves 7-file conflict caused by PR #142's test-method renames and attribute cleanup overlapping with this branch's coverage work. - AdapterAwareTraitTest: adopt CoversMethod over CoversTrait to match the rest of the suite (78 other files use CoversMethod; this was the only CoversTrait usage) - AbstractConnectionTest/TestConnection: kept this branch's TestConnection fixture (extends AbstractConnection directly) over upstream's ConnectionWrapper, which extends AbstractPdoConnection and would have reintroduced the wrong-hierarchy coverage gap this PR fixes. Also gave TestConnection a constructor param for driverName so testGetDriverNameReturnsValueWhenSet genuinely exercises a non-null value instead of asserting null - AdapterInterfaceDelegatorTest: both branches independently added the same three tests at different positions; deduplicated to one copy - PdoTest: adopted upstream's `$unused = $pdo->getProfiler()` over a phpstan-ignore comment to silence the unused-result warning - ProfilerTest: kept this branch's split of testProfilerStart into separate string/container tests (one logical assertion per test) over upstream's combined version - Dropped upstream's `CoversMethod(..., '__construct')` additions on AbstractPdo/AbstractPdoConnection in PdoTest/ConnectionTest since neither class declares its own constructor Full unit suite (1451 tests), phpcs, and phpstan all pass post-merge.
2 parents 63efcb8 + 865a19c commit 984631b

10 files changed

Lines changed: 44 additions & 44 deletions

File tree

‎test/unit/Adapter/AdapterAwareTraitTest.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
use PhpDb\Adapter\Driver\DriverInterface;
1010
use PhpDb\Adapter\Platform\PlatformInterface;
1111
use PhpDbTest\Adapter\TestAsset\ConcreteAdapterAwareObject;
12-
use PHPUnit\Framework\Attributes\CoversTrait;
12+
use PHPUnit\Framework\Attributes\CoversMethod;
1313
use PHPUnit\Framework\Attributes\Group;
1414
use PHPUnit\Framework\TestCase;
1515
use ReflectionProperty;
1616

17-
#[CoversTrait(AdapterAwareTrait::class)]
17+
#[CoversMethod(AdapterAwareTrait::class, 'setDbAdapter')]
1818
#[Group('unit')]
1919
class AdapterAwareTraitTest extends TestCase
2020
{

‎test/unit/Adapter/AdapterTest.php‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ protected function setUp(): void
7070
}
7171

7272
#[TestDox('unit test: Test setProfiler() will store profiler')]
73-
public function testSetProfiler(): void
73+
public function testFluentSetProfiler(): void
7474
{
7575
$ret = $this->adapter->setProfiler(new Profiler\Profiler());
7676
self::assertSame($this->adapter, $ret);
7777
}
7878

7979
#[TestDox('unit test: Test getProfiler() will store profiler')]
80-
public function testGetProfiler(): void
80+
public function testGetProfilerReturnsProfiler(): void
8181
{
8282
$this->adapter->setProfiler($profiler = new Profiler\Profiler());
8383
self::assertSame($profiler, $this->adapter->getProfiler());
@@ -91,25 +91,25 @@ public function testGetProfiler(): void
9191
}
9292

9393
#[TestDox('unit test: Test getDriver() will return driver object')]
94-
public function testGetDriver(): void
94+
public function testGetDriverReturnsDriver(): void
9595
{
9696
self::assertSame($this->mockDriver, $this->adapter->getDriver());
9797
}
9898

9999
#[TestDox('unit test: Test getPlatform() returns platform object')]
100-
public function testGetPlatform(): void
100+
public function testGetPlatformReturnsPlatform(): void
101101
{
102102
self::assertSame($this->mockPlatform, $this->adapter->getPlatform());
103103
}
104104

105105
#[TestDox('unit test: Test getPlatform() returns platform object')]
106-
public function testGetQueryResultSetPrototype(): void
106+
public function testGetQueryResultSetPrototypeReturnsResultSet(): void
107107
{
108108
self::assertInstanceOf(ResultSetInterface::class, $this->adapter->getQueryResultSetPrototype());
109109
}
110110

111111
#[TestDox('unit test: Test getCurrentSchema() returns current schema from connection object')]
112-
public function testGetCurrentSchema(): void
112+
public function testGetCurrentSchemaDelegatesToConnection(): void
113113
{
114114
$this->mockConnection->expects($this->any())->method('getCurrentSchema')->willReturn('FooSchema');
115115
self::assertEquals('FooSchema', $this->adapter->getCurrentSchema());
@@ -218,15 +218,13 @@ public function testQueryWhenExecutedProducesAResultSetObjectWhenResultIsQuery()
218218
}
219219

220220
#[TestDox('unit test: Test createStatement() produces a statement object')]
221-
public function testCreateStatement(): void
221+
public function testCreateStatementDelegatesToDriver(): void
222222
{
223223
self::assertSame($this->mockStatement, $this->adapter->createStatement());
224224
}
225225

226-
// @codingStandardsIgnoreStart
227-
public function test__get(): void
226+
public function testMagicGetReturnsDriverAndPlatformCaseInsensitively(): void
228227
{
229-
// @codingStandardsIgnoreEnd
230228
self::assertSame($this->mockDriver, $this->adapter->driver);
231229
/** @phpstan-ignore property.notFound */
232230
self::assertSame($this->mockDriver, $this->adapter->DrivER);

‎test/unit/Adapter/Driver/AbstractConnectionTest.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,15 @@ public function testGetConnectionParametersReturnsEmptyByDefault(): void
5151
}
5252

5353
public function testGetDriverNameReturnsValueWhenSet(): void
54+
{
55+
$connection = new TestConnection('sqlite');
56+
57+
self::assertSame('sqlite', $connection->getDriverName());
58+
}
59+
60+
public function testGetDriverNameReturnsNullByDefault(): void
5461
{
5562
$connection = new TestConnection();
56-
$connection->setConnectionParameters(['driver' => 'sqlite']);
5763

5864
self::assertNull($connection->getDriverName());
5965
}

‎test/unit/Adapter/Driver/Pdo/ConnectionTest.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function testResource(): void
6464
/**
6565
* Test getConnectedDsn returns a DSN string if it has been set
6666
*/
67-
public function testGetDsn(): void
67+
public function testGetDsnReturnsDsnAfterConnect(): void
6868
{
6969
$dsn = "sqlite::memory:";
7070
$this->connection->setConnectionParameters(['dsn' => $dsn]);
@@ -93,7 +93,7 @@ public function testConstructorWithArraySetsConnectionParameters(): void
9393
self::assertSame($params, $connection->getConnectionParameters());
9494
}
9595

96-
public function testSetDriverReturnsInstance(): void
96+
public function testFluentSetDriver(): void
9797
{
9898
$driver = $this->createMock(PdoDriverInterface::class);
9999

‎test/unit/Adapter/Driver/Pdo/PdoTest.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static function getParamsAndType(): array
6666
}
6767

6868
#[DataProvider('getParamsAndType')]
69-
public function testFormatParameterName(int|string $name, ?string $type, string $expected): void
69+
public function testFormatParameterNameFormatsCorrectly(int|string $name, ?string $type, string $expected): void
7070
{
7171
$result = $this->pdo->formatParameterName($name, $type);
7272
$this->assertEquals($expected, $result);
@@ -90,7 +90,7 @@ public function testFormatParameterNameWithInvalidCharacters(string $name): void
9090
$this->pdo->formatParameterName($name);
9191
}
9292

93-
public function testGetResultPrototype(): void
93+
public function testGetResultPrototypeReturnsResult(): void
9494
{
9595
$resultPrototype = $this->pdo->getResultPrototype();
9696

@@ -172,8 +172,8 @@ public function testGetProfilerThrowsWhenNotInitialized(): void
172172
$pdo = new TestPdo([]);
173173

174174
$this->expectException(Error::class);
175-
/** @phpstan-ignore method.resultUnused */
176-
$pdo->getProfiler();
175+
176+
$unused = $pdo->getProfiler();
177177
}
178178

179179
public function testGetProfilerReturnsSetProfiler(): void

‎test/unit/Adapter/Driver/Pdo/ResultTest.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final class ResultTest extends TestCase
4242
/**
4343
* Tests current method returns same data on consecutive calls.
4444
*/
45-
public function testCurrent(): void
45+
public function testCurrentReturnsSameDataOnConsecutiveCalls(): void
4646
{
4747
$stub = $this->getMockBuilder('PDOStatement')->getMock();
4848
$stub->expects($this->any())
@@ -55,7 +55,7 @@ public function testCurrent(): void
5555
self::assertEquals($result->current(), $result->current());
5656
}
5757

58-
public function testFetchModeException(): void
58+
public function testSetFetchModeThrowsOnInvalidMode(): void
5959
{
6060
$result = new Result();
6161

@@ -66,7 +66,7 @@ public function testFetchModeException(): void
6666
/**
6767
* Tests whether the fetch mode was set properly and
6868
*/
69-
public function testFetchModeAnonymousObject(): void
69+
public function testFetchModeObjReturnsStdClass(): void
7070
{
7171
$stub = $this->getMockBuilder('PDOStatement')->getMock();
7272
$stub->expects($this->any())
@@ -84,7 +84,7 @@ public function testFetchModeAnonymousObject(): void
8484
/**
8585
* Tests whether the fetch mode has a broader range
8686
*/
87-
public function testFetchModeRange(): void
87+
public function testFetchModeAcceptsNamedMode(): void
8888
{
8989
$stub = $this->getMockBuilder('PDOStatement')->getMock();
9090
$stub->expects($this->any())
@@ -97,7 +97,7 @@ public function testFetchModeRange(): void
9797
self::assertInstanceOf('stdClass', $result->current());
9898
}
9999

100-
public function testMultipleRewind(): void
100+
public function testRewindResetsIterationToStart(): void
101101
{
102102
$data = [
103103
['test' => 1],

‎test/unit/Adapter/Driver/Pdo/StatementTest.php‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,27 +62,24 @@ protected function tearDown(): void
6262
{
6363
}
6464

65-
public function testSetDriver(): void
65+
public function testFluentSetDriver(): void
6666
{
6767
self::assertEquals($this->statement, $this->statement->setDriver(new TestPdo([])));
6868
}
6969

70-
public function testSetParameterContainer(): void
70+
public function testFluentSetParameterContainer(): void
7171
{
7272
self::assertSame($this->statement, $this->statement->setParameterContainer(new ParameterContainer()));
7373
}
7474

75-
/**
76-
* @todo Implement testGetParameterContainer().
77-
*/
78-
public function testGetParameterContainer(): void
75+
public function testGetParameterContainerReturnsContainer(): void
7976
{
8077
$container = new ParameterContainer();
8178
$this->statement->setParameterContainer($container);
8279
self::assertSame($container, $this->statement->getParameterContainer());
8380
}
8481

85-
public function testGetResource(): void
82+
public function testGetResourceReturnsPdoStatement(): void
8683
{
8784
$pdo = new SqliteMemoryPdo();
8885
$stmt = $pdo->prepare('SELECT 1');
@@ -103,26 +100,23 @@ public function testGetSql(): void
103100
self::assertEquals('SELECT 1', $this->statement->getSql());
104101
}
105102

106-
/**
107-
* Test that prepare() returns the statement for method chaining
108-
*/
109-
public function testPrepare(): void
103+
public function testFluentPrepare(): void
110104
{
111105
$this->statement->initialize(new SqliteMemoryPdo());
112106
$result = $this->statement->prepare('SELECT 1');
113107
self::assertInstanceOf(Statement::class, $result);
114108
self::assertSame($this->statement, $result);
115109
}
116110

117-
public function testIsPrepared(): void
111+
public function testIsPreparedReturnsTrueAfterPrepare(): void
118112
{
119113
self::assertFalse($this->statement->isPrepared());
120114
$this->statement->initialize(new SqliteMemoryPdo());
121115
$this->statement->prepare('SELECT 1');
122116
self::assertTrue($this->statement->isPrepared());
123117
}
124118

125-
public function testExecute(): void
119+
public function testExecuteReturnsResult(): void
126120
{
127121
$this->statement->setDriver(new TestPdo(new TestConnection($pdo = new SqliteMemoryPdo())));
128122
$this->statement->initialize($pdo);

‎test/unit/Adapter/Driver/TestAsset/TestConnection.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
final class TestConnection extends AbstractConnection
1212
{
13-
protected ?string $driverName = null;
13+
public function __construct(protected ?string $driverName = null)
14+
{
15+
}
1416

1517
public function beginTransaction(): ConnectionInterface
1618
{

‎test/unit/Adapter/Platform/Sql92Test.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function testQuoteValueRaisesNoticeWithoutPlatformSupport(): void
8282
$this->platform->quoteValue('value');
8383
}
8484

85-
public function testQuoteValue(): void
85+
public function testQuoteValueThrowsWithoutDriver(): void
8686
{
8787
$this->expectException(VunerablePlatformQuoteException::class);
8888
self::assertEquals("'value'", @$this->platform->quoteValue('value'));
@@ -97,7 +97,7 @@ public function testQuoteValue(): void
9797
);
9898
}
9999

100-
public function testQuoteTrustedValue(): void
100+
public function testQuoteTrustedValueEscapesSpecialCharacters(): void
101101
{
102102
self::assertEquals("'value'", $this->platform->quoteTrustedValue('value'));
103103
self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteTrustedValue("Foo O'Bar"));
@@ -113,7 +113,7 @@ public function testQuoteTrustedValue(): void
113113
);
114114
}
115115

116-
public function testQuoteValueList(): void
116+
public function testQuoteValueListThrowsWithoutDriver(): void
117117
{
118118
$this->expectException(VunerablePlatformQuoteException::class);
119119
self::assertEquals("'Foo O\\'Bar'", $this->platform->quoteValueList("Foo O'Bar"));

‎test/unit/Adapter/Profiler/ProfilerTest.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testProfilerStartWithStatementContainer(): void
4444
self::assertSame($this->profiler, $ret);
4545
}
4646

47-
public function testProfilerFinish(): void
47+
public function testProfilerFinishThrowsWithoutStart(): void
4848
{
4949
$this->profiler->profilerStart('SELECT * FROM FOO');
5050
$ret = $this->profiler->profilerFinish();
@@ -56,7 +56,7 @@ public function testProfilerFinish(): void
5656
$profiler->profilerFinish();
5757
}
5858

59-
public function testGetLastProfile(): void
59+
public function testGetLastProfileReturnsSqlAndTimings(): void
6060
{
6161
$this->profiler->profilerStart('SELECT * FROM FOO');
6262
$this->profiler->profilerFinish();
@@ -68,7 +68,7 @@ public function testGetLastProfile(): void
6868
self::assertIsFloat($profile['elapse']);
6969
}
7070

71-
public function testGetProfiles(): void
71+
public function testGetProfilesReturnsAllRecordedProfiles(): void
7272
{
7373
$this->profiler->profilerStart('SELECT * FROM FOO1');
7474
$this->profiler->profilerFinish();

0 commit comments

Comments
 (0)