8000 fix CI · thecodingmachine/tdbm@e7e1756 · GitHub
[go: up one dir, main page]

Skip to content

Commit e7e1756

Browse files
committed
fix CI
1 parent d8a2918 commit e7e1756

12 files changed

+59
-27
lines changed

src/EmptyResultIterator.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace TheCodingMachine\TDBM;
4+
5+
use Psr\Log\NullLogger;
6+
use TheCodingMachine\TDBM\ResultIterator;
7+
8+
class EmptyResultIterator extends ResultIterator
9+
{
10+
protected function __construct()
11+
{
12+
$this->totalCount = 0;
13+
$this->logger = new NullLogger();
14+
}
15+
16+
}

src/PageIterator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ public static function createEmpyIterator(ResultIterator $parentResult): self
121121
public function getIterator()
122122
{
123123
if ($this->innerResultIterator === null) {
124-
if ($this->mode === TDBMService::MODE_CURSOR) {
124+
if ($this->parentResult instanceof EmptyResultIterator) {
125+
$this->innerResultIterator = new EmptyInnerResultIterator();
126+
} elseif ($this->mode === TDBMService::MODE_CURSOR) {
125127
$this->innerResultIterator = InnerResultIterator::createInnerResultIterator($this->magicSql, $this->parameters, $this->limit, $this->offset, $this->columnDescriptors, $this->objectStorage, $this->className, $this->tdbmService, $this->magicQuery, $this->logger);
126128
} else {
127129
$this->innerResultIterator = InnerResultArray::createInnerResultIterator($this->magicSql, $this->parameters, $this->limit, $this->offset, $this->columnDescriptors, $this->objectStorage, $this->className, $this->tdbmService, $this->magicQuery, $this->logger);

src/QueryFactory/FindObjectsFromRawSqlQueryFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ private function generateGroupedSqlCount(array $parsedSql): array
403403
$item['delim'] = ',';
404404
$innerColumns[] = $item;
405405
}
406-
$innerColumns[count($innerColumns)-1]['delim'] = false;
406+
$innerColumns[count($innerColumns) - 1]['delim'] = false;
407407
$parsedSql['SELECT'] = $innerColumns;
408408

409409
$parsedSql = [

src/ResultIterator.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ class ResultIterator implements Result, \ArrayAccess, \JsonSerializable
6565
private $innerResultIterator;
6666

6767
/** @var int|null */
68-
private $totalCount;
68+
protected $totalCount;
6969

7070
/** @var int */
7171
private $mode;
7272

7373
/** @var LoggerInterface */
74-
private $logger;
74+
protected $logger;
7575

76-
final private function __construct()
76+
protected function __construct()
7777
{
7878
}
7979

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

102102
public static function createEmpyIterator(): self
103103
{
104-
$iterator = new static();
105-
$iterator->totalCount = 0;
106-
$iterator->logger = new NullLogger();
107-
return $iterator;
104+
return new EmptyResultIterator();
108105
}
109106

110107
protected function executeCountQuery(): void

src/Utils/BeanDescriptor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ private function generateFindByDaoCodeForIndex(Index $index, string $beanNamespa
13331333
$parameter = new ParameterGenerator(ltrim($element->getSafeVariableName(), '$'));
13341334
if (!$first && !($element->isCompulsory() && $index->isUnique())) {
13351335
$parameterType = '?';
1336-
//$functionParameter = '?';
1336+
//$functionParameter = '?';
13371337
} else {
13381338
$parameterType = '';
13391339
//$functionParameter = '';
@@ -1765,7 +1765,7 @@ private function generateGetForeignKeys(array $fks): MethodGenerator
17651765
* @param string $indent
17661766
* @return string
17671767
*/
1768-
private function psr2VarExport($var, string $indent=''): string
1768+
private function psr2VarExport($var, string $indent = ''): string
17691769
{
17701770
if (is_array($var)) {
17711771
$indexed = array_keys($var) === range(0, count($var) - 1);

tests/AbstractTDBMObjectTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,21 @@ public function testEmptyResultIterator()
4242
$this->assertEquals(0, $d->count());
4343
}
4444

45+
public function testEmptyPageIterator()
46+
{
47+
$a = ResultIterator::createEmpyIterator();
48+
$b = $a->take(0, 10);
49+
foreach ($b as $empty) {
50+
throw new \LogicException("Not supposed to iterate on an empty page iterator.");
51+
}
52+
$this->assertEquals(0, $b->count());
53+
$this->assertEquals([], $b->toArray());
54+
$this->assertEquals(0, $b->totalCount());
55+
$c = $b->map(function ($foo) {
56+
});
57+
foreach ($c as $empty) {
58+
throw new \LogicException("Not supposed to iterate on an empty iterator.");
59+
}
60+
$this->assertEquals([], $c->toArray());
61+
}
4562
}

tests/NativeWeakrefObjectStorageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testDanglingPointers(): void
3030
$objectStorage = new NativeWeakrefObjectStorage();
3131
$dbRow = $this->createMock(DbRow::class);
3232

33-
for ($i=0; $i<10001; $i++) {
33+
for ($i = 0; $i < 10001; $i++) {
3434
$objectStorage->set('foo', $i, clone $dbRow);
3535
}
3636
$this->assertNull($objectStorage->get('foo', 42));

tests/Performance/ManyToOneBench.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,18 @@ private static function initSchema(Connection $connection): void
7373
$connection->exec($sqlStmt);
7474
}
7575

76-
for ($i = 1; $i<200; $i++) {
76+
for ($i = 1; $i < 200; $i++) {
7777
TDBMAbstractServiceTest::insert($connection, 'countries', [
7878
'id' => $i,
7979
'label' => 'Country '.$i,
8080
]);
8181
}
8282

83-
for ($i = 1; $i<1000; $i++) {
83+
for ($i = 1; $i < 1000; $i++) {
8484
TDBMAbstractServiceTest::insert($connection, 'users', [
8585
'id' => $i,
8686
'name' => 'User '.$i,
87-
'country_id' => ($i%199) +1,
87+
'country_id' => ($i % 199) + 1,
8888
]);
8989
}
9090
}

tests/TDBMAbstractServiceTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ private static function initSchema(Connection $connection): void
211211
->column('manager_id')->references('contact')->null();
212212

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

722722
self::insert($connection, 'tracks', [
723723
'album_id' => 1,
724-
'title' =>'Pigs on the Wing 1',
724+
'title' => 'Pigs on the Wing 1',
725725
// Note: Oracle does not have a TIME column type
726726
'duration' => $timeType->convertToDatabaseValue(new DateTimeImmutable('1970-01-01 00:01:25'), $connection->getDatabasePlatform()),
727727
]);

tests/Utils/Annotation/AnnotationParserTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function testParse(): void
1919
'UUID' => UUID::class,
2020
'Autoincrement' => Autoincrement::class
2121
]);
22-
$column = new Column('foo', Type::getType(Type::STRING), ['comment'=>'@UUID']);
22+
$column = new Column('foo', Type::getType(Type::STRING), ['comment' => '@UUID']);
2323
$table = new Table('bar');
2424
$annotations = $parser->getColumnAnnotations($column, $table);
2525

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

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

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

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

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

100100
$annotation = $annotations->findAnnotation(UUID::class);

0 commit comments

Comments
 (0)
0