Skip to content

Commit

Permalink
fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenk committed May 14, 2024
1 parent d8a2918 commit e7e1756
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 27 deletions.
16 changes: 16 additions & 0 deletions src/EmptyResultIterator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace TheCodingMachine\TDBM;

use Psr\Log\NullLogger;
use TheCodingMachine\TDBM\ResultIterator;

class EmptyResultIterator extends ResultIterator
{
protected function __construct()
{
$this->totalCount = 0;
$this->logger = new NullLogger();
}

}
4 changes: 3 additions & 1 deletion src/PageIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ public static function createEmpyIterator(ResultIterator $parentResult): self
public function getIterator()
{
if ($this->innerResultIterator === null) {
if ($this->mode === TDBMService::MODE_CURSOR) {
if ($this->parentResult instanceof EmptyResultIterator) {
$this->innerResultIterator = new EmptyInnerResultIterator();
} elseif ($this->mode === TDBMService::MODE_CURSOR) {
$this->innerResultIterator = InnerResultIterator::createInnerResultIterator($this->magicSql, $this->parameters, $this->limit, $this->offset, $this->columnDescriptors, $this->objectStorage, $this->className, $this->tdbmService, $this->magicQuery, $this->logger);
} else {
$this->innerResultIterator = InnerResultArray::createInnerResultIterator($this->magicSql, $this->parameters, $this->limit, $this->offset, $this->columnDescriptors, $this->objectStorage, $this->className, $this->tdbmService, $this->magicQuery, $this->logger);
Expand Down
2 changes: 1 addition & 1 deletion src/QueryFactory/FindObjectsFromRawSqlQueryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ private function generateGroupedSqlCount(array $parsedSql): array
$item['delim'] = ',';
$innerColumns[] = $item;
}
$innerColumns[count($innerColumns)-1]['delim'] = false;
$innerColumns[count($innerColumns) - 1]['delim'] = false;
$parsedSql['SELECT'] = $innerColumns;

$parsedSql = [
Expand Down
11 changes: 4 additions & 7 deletions src/ResultIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ class ResultIterator implements Result, \ArrayAccess, \JsonSerializable
private $innerResultIterator;

/** @var int|null */
private $totalCount;
protected $totalCount;

/** @var int */
private $mode;

/** @var LoggerInterface */
private $logger;
protected $logger;

final private function __construct()
protected function __construct()
{
}

Expand Down Expand Up @@ -101,10 +101,7 @@ public static function createResultIterator(QueryFactory $queryFactory, array $p

public static function createEmpyIterator(): self
{
$iterator = new static();
$iterator->totalCount = 0;
$iterator->logger = new NullLogger();
return $iterator;
return new EmptyResultIterator();
}

protected function executeCountQuery(): void
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/BeanDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@ private function generateFindByDaoCodeForIndex(Index $index, string $beanNamespa
$parameter = new ParameterGenerator(ltrim($element->getSafeVariableName(), '$'));
if (!$first && !($element->isCompulsory() && $index->isUnique())) {
$parameterType = '?';
//$functionParameter = '?';
//$functionParameter = '?';
} else {
$parameterType = '';
//$functionParameter = '';
Expand Down Expand Up @@ -1765,7 +1765,7 @@ private function generateGetForeignKeys(array $fks): MethodGenerator
* @param string $indent
* @return string
*/
private function psr2VarExport($var, string $indent=''): string
private function psr2VarExport($var, string $indent = ''): string
{
if (is_array($var)) {
$indexed = array_keys($var) === range(0, count($var) - 1);
Expand Down
17 changes: 17 additions & 0 deletions tests/AbstractTDBMObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,21 @@ public function testEmptyResultIterator()
$this->assertEquals(0, $d->count());
}

public function testEmptyPageIterator()
{
$a = ResultIterator::createEmpyIterator();
$b = $a->take(0, 10);
foreach ($b as $empty) {
throw new \LogicException("Not supposed to iterate on an empty page iterator.");
}
$this->assertEquals(0, $b->count());
$this->assertEquals([], $b->toArray());
$this->assertEquals(0, $b->totalCount());
$c = $b->map(function ($foo) {
});
foreach ($c as $empty) {
throw new \LogicException("Not supposed to iterate on an empty iterator.");
}
$this->assertEquals([], $c->toArray());
}
}
2 changes: 1 addition & 1 deletion tests/NativeWeakrefObjectStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testDanglingPointers(): void
$objectStorage = new NativeWeakrefObjectStorage();
$dbRow = $this->createMock(DbRow::class);

for ($i=0; $i<10001; $i++) {
for ($i = 0; $i < 10001; $i++) {
$objectStorage->set('foo', $i, clone $dbRow);
}
$this->assertNull($objectStorage->get('foo', 42));
Expand Down
6 changes: 3 additions & 3 deletions tests/Performance/ManyToOneBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ private static function initSchema(Connection $connection): void
$connection->exec($sqlStmt);
}

for ($i = 1; $i<200; $i++) {
for ($i = 1; $i < 200; $i++) {
TDBMAbstractServiceTest::insert($connection, 'countries', [
'id' => $i,
'label' => 'Country '.$i,
]);
}

for ($i = 1; $i<1000; $i++) {
for ($i = 1; $i < 1000; $i++) {
TDBMAbstractServiceTest::insert($connection, 'users', [
'id' => $i,
'name' => 'User '.$i,
'country_id' => ($i%199) +1,
'country_id' => ($i % 199) + 1,
]);
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/TDBMAbstractServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ private static function initSchema(Connection $connection): void
->column('manager_id')->references('contact')->null();

$db->table('users')
->addAnnotation('AddTrait', ['name'=>TestUserTrait::class], false)
->addAnnotation('AddTrait', ['name'=>TestOtherUserTrait::class, 'modifiers'=>['\\'.TestOtherUserTrait::class.'::method1 insteadof \\'.TestUserTrait::class, '\\'.TestUserTrait::class.'::method1 as method1renamed']], false)
->addAnnotation('AddTraitOnDao', ['name'=>TestUserDaoTrait::class], false)
->addAnnotation('AddTrait', ['name' => TestUserTrait::class], false)
->addAnnotation('AddTrait', ['name' => TestOtherUserTrait::class, 'modifiers' => ['\\'.TestOtherUserTrait::class.'::method1 insteadof \\'.TestUserTrait::class, '\\'.TestUserTrait::class.'::method1 as method1renamed']], false)
->addAnnotation('AddTraitOnDao', ['name' => TestUserDaoTrait::class], false)
->implementsInterface(TestUserInterface::class)
->implementsInterfaceOnDao(TestUserDaoInterface::class)
->extends('contact')
Expand Down Expand Up @@ -721,7 +721,7 @@ private static function initSchema(Connection $connection): void

self::insert($connection, 'tracks', [
'album_id' => 1,
'title' =>'Pigs on the Wing 1',
'title' => 'Pigs on the Wing 1',
// Note: Oracle does not have a TIME column type
'duration' => $timeType->convertToDatabaseValue(new DateTimeImmutable('1970-01-01 00:01:25'), $connection->getDatabasePlatform()),
]);
Expand Down
12 changes: 6 additions & 6 deletions tests/Utils/Annotation/AnnotationParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testParse(): void
'UUID' => UUID::class,
'Autoincrement' => Autoincrement::class
]);
$column = new Column('foo', Type::getType(Type::STRING), ['comment'=>'@UUID']);
$column = new Column('foo', Type::getType(Type::STRING), ['comment' => '@UUID']);
$table = new Table('bar');
$annotations = $parser->getColumnAnnotations($column, $table);

Expand All @@ -40,7 +40,7 @@ public function testParseMultiLine(): void
'UUID' => UUID::class,
'Autoincrement' => Autoincrement::class
]);
$column = new Column('foo', Type::getType(Type::STRING), ['comment'=>"\n@UUID"]);
$column = new Column('foo', Type::getType(Type::STRING), ['comment' => "\n@UUID"]);
$table = new Table('bar');
$annotations = $parser->getColumnAnnotations($column, $table);

Expand All @@ -54,7 +54,7 @@ public function testParseMultiAnnotations(): void
'UUID' => UUID::class,
'Autoincrement' => Autoincrement::class
]);
$column = new Column('foo', Type::getType(Type::STRING), ['comment'=>"\n@UUID\n@Autoincrement"]);
$column = new Column('foo', Type::getType(Type::STRING), ['comment' => "\n@UUID\n@Autoincrement"]);
$table = new Table('bar');
$annotations = $parser->getColumnAnnotations($column, $table);

Expand All @@ -68,7 +68,7 @@ public function testException(): void
'UUID' => UUID::class,
'Autoincrement' => Autoincrement::class
]);
$table = new Table('bar', [], [], [], 0, ['comment'=>"@UUID\n@UUID"]);
$table = new Table('bar', [], [], [], 0, ['comment' => "@UUID\n@UUID"]);
$annotations = $parser->getTableAnnotations($table);

$this->expectException(TDBMException::class);
Expand All @@ -81,7 +81,7 @@ public function testParseParameters(): void
'UUID' => UUID::class,
'Autoincrement' => Autoincrement::class
]);
$table = new Table('bar', [], [], [], 0, ['comment'=>'@UUID("v4")']);
$table = new Table('bar', [], [], [], 0, ['comment' => '@UUID("v4")']);
$annotations = $parser->getTableAnnotations($table);

$annotation = $annotations->findAnnotation(UUID::class);
Expand All @@ -94,7 +94,7 @@ public function testParseOldUUID(): void
'UUID' => UUID::class,
]);
// First generation UUID did not use the Doctrine syntax.
$table = new Table('bar', [], [], [], 0, ['comment'=>'@UUID v4']);
$table = new Table('bar', [], [], [], 0, ['comment' => '@UUID v4']);
$annotations = $parser->getTableAnnotations($table);

$annotation = $annotations->findAnnotation(UUID::class);
Expand Down
2 changes: 1 addition & 1 deletion tests/Utils/DbalUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public function testGenerateTypes(): void
'key4' => 1,
];

$this->assertSame(['key2'=>Connection::PARAM_INT_ARRAY, 'key3'=>Connection::PARAM_STR_ARRAY, 'key4'=>ParameterType::INTEGER], DbalUtils::generateTypes($params));
$this->assertSame(['key2' => Connection::PARAM_INT_ARRAY, 'key3' => Connection::PARAM_STR_ARRAY, 'key4' => ParameterType::INTEGER], DbalUtils::generateTypes($params));
}
}
2 changes: 1 addition & 1 deletion tests/Utils/DefaultNamingStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function testExceptions(): void

public function testBeanAnnotation(): void
{
$table = new Table('chevaux', [], [], [], 0, ['comment'=>'@Bean(name="Cheval")']);
$table = new Table('chevaux', [], [], [], 0, ['comment' => '@Bean(name="Cheval")']);
$strategy = $this->getDefaultNamingStrategyWithStubTables([$table]);
$this->assertSame('ChevalDao', $strategy->getDaoClassName('chevaux'));
}
Expand Down

0 comments on commit e7e1756

Please sign in to comment.