Skip to content

Commit db18f5c

Browse files
authored
Merge pull request #124 from mringler/test_comparators
Build test reference files from attribute
2 parents e950c78 + 45bfe4a commit db18f5c

File tree

97 files changed

+6465
-1726
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+6465
-1726
lines changed

src/Propel/Generator/Builder/Om/AbstractOMBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ public function getUuidSwapFlagLiteral(): string
615615
*/
616616
protected function generateTimestampBlock(): string
617617
{
618-
if ($this->getBuildProperty('generator.objectModel.addTimeStamp')) {
618+
if (!$this->getBuildProperty('generator.objectModel.addTimeStamp')) {
619619
return '';
620620
}
621621
$now = gmdate('c');

src/Propel/Generator/Builder/Om/ObjectBuilder/ColumnTypes/ColumnCodeProducer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function getApplyDefaultValueStatement(): string
160160
$defaultValue = $this->getDefaultValueString();
161161
if ($this->column->isPhpObjectType()) {
162162
$assumedClassName = $this->declareClass($this->column->getPhpType());
163-
$defaultValue = "new $assumedClassName($defaultValue )";
163+
$defaultValue = "new $assumedClassName($defaultValue)";
164164
}
165165

166166
return "

src/Propel/Generator/Builder/Om/ObjectBuilder/RelationCodeProducer/FkRelationCodeProducer.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,7 @@ public function get{$relationIdentifierSingular}(?ConnectionInterface \$con = nu
258258
}
259259
260260
return \$this->$varName;
261-
}
262-
";
261+
}\n";
263262
}
264263

265264
/**

src/Propel/Generator/Builder/Om/ObjectBuilder/RelationCodeProducer/ManyToManyRelationCodeProducer.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ public function get{$targetIdentifierPlural}(?Criteria \$criteria = null, ?Conne
179179
}
180180
181181
return \$this->$attributeName;
182-
}
183-
";
182+
}\n";
184183
}
185184

186185
/**
@@ -308,7 +307,6 @@ protected function doAdd{$targetIdentifierSingular}($parameterDeclaration): void
308307
} elseif (!{$targetObject}->get{$ownIdentifierPlural}($targetGetterParameters)->contains(\$this)) {
309308
{$targetObject}->get{$ownIdentifierPlural}($targetGetterParameters)->push(\$this);
310309
}
311-
}
312-
";
310+
}\n";
313311
}
314312
}

src/Propel/Generator/Builder/Util/SchemaReader.php

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Propel\Generator\Builder\Util;
66

7+
use Exception;
78
use Propel\Generator\Config\AbstractGeneratorConfig;
89
use Propel\Generator\Exception\SchemaException;
910
use Propel\Generator\Model\Index;
@@ -24,7 +25,6 @@
2425
use function strpos;
2526
use function strtolower;
2627
use function version_compare;
27-
use function vsprintf;
2828
use function xml_error_string;
2929
use function xml_get_current_column_number;
3030
use function xml_get_current_line_number;
@@ -54,7 +54,7 @@ class SchemaReader
5454
private $schema;
5555

5656
/**
57-
* @var \XMLParser|resource
57+
* @var \XMLParser
5858
*/
5959
private $parser;
6060

@@ -201,14 +201,13 @@ public function parseString(string $xmlString, ?string $xmlFile = null): ?Schema
201201
$this->parser = xml_parser_create();
202202
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
203203
xml_set_element_handler($this->parser, [$this, 'startElement'], [$this, 'endElement']);
204-
if (!xml_parse($this->parser, $xmlString)) {
205-
throw new SchemaException(
206-
sprintf(
207-
'XML error: %s at line %d',
208-
xml_error_string(xml_get_error_code($this->parser)),
209-
xml_get_current_line_number($this->parser),
210-
),
211-
);
204+
try {
205+
$success = xml_parse($this->parser, $xmlString);
206+
} catch (Exception $e) {
207+
throw new SchemaException('XML parser failed at ' . $this->getLocationDescription() . ': ' . $e->getMessage(), 0, $e);
208+
}
209+
if (!$success) {
210+
$this->throwParserError();
212211
}
213212
if (version_compare(phpversion(), '8.1', '<')) {
214213
xml_parser_free($this->parser);
@@ -221,7 +220,7 @@ public function parseString(string $xmlString, ?string $xmlFile = null): ?Schema
221220
}
222221

223222
/**
224-
* @param resource $parser
223+
* @param \XMLParser $parser
225224
* @param string $tagName
226225
* @param array $attributes
227226
*
@@ -236,10 +235,7 @@ public function startElement($parser, string $tagName, array $attributes): void
236235
switch ($tagName) {
237236
case 'database':
238237
if ($this->isExternalSchema()) {
239-
$this->currentPackage = $attributes['package'] ?? null;
240-
if ($this->currentPackage === null) {
241-
$this->currentPackage = $this->defaultPackage;
242-
}
238+
$this->currentPackage = $attributes['package'] ?? $this->defaultPackage;
243239
} else {
244240
$this->currDB = $this->schema->addDatabase($attributes);
245241
}
@@ -441,28 +437,27 @@ public function startElement($parser, string $tagName, array $attributes): void
441437
/**
442438
* @param string $tagName
443439
*
440+
* @throws \Propel\Generator\Exception\SchemaException
441+
*
444442
* @return void
445443
*/
446444
protected function throwInvalidTagException(string $tagName): void
447445
{
448-
$this->throwSchemaExceptionWithLocation('Unexpected tag <%s>', $tagName);
446+
throw new SchemaException("Unexpected tag $tagName");
449447
}
450448

451449
/**
452-
* @param string $format
453-
* @param mixed $args sprintf arguments
454-
*
455450
* @throws \Propel\Generator\Exception\SchemaException
456451
*
457452
* @return void
458453
*/
459-
private function throwSchemaExceptionWithLocation(string $format, ...$args): void
454+
protected function throwParserError(): void
460455
{
461-
$format .= ' in %s';
462-
$args[] = $this->getLocationDescription();
463-
$message = vsprintf($format, $args);
456+
$errorCode = xml_get_error_code($this->parser);
457+
$errorMessage = xml_error_string($errorCode);
458+
$location = $this->getLocationDescription();
464459

465-
throw new SchemaException($message);
460+
throw new SchemaException("XML error: $errorMessage at $location");
466461
}
467462

468463
/**
@@ -612,6 +607,8 @@ private function addAttributeToParameterListItem(array $attributes): void
612607
/**
613608
* Feeds the current parameter list to its parent and clears the collector.
614609
*
610+
* @throws \Propel\Generator\Exception\SchemaException
611+
*
615612
* @return void
616613
*/
617614
private function finalizeParameterList(): void
@@ -620,7 +617,7 @@ private function finalizeParameterList(): void
620617
if ($parentTag === 'behavior') {
621618
$this->currBehavior->addParameter($this->currParameterListCollector);
622619
} else {
623-
$this->throwSchemaExceptionWithLocation('Cannot add parameter list to tag <%s>', $parentTag);
620+
throw new SchemaException("Cannot add parameter list to tag `$parentTag`");
624621
}
625622

626623
$this->currParameterListCollector = null;
@@ -632,12 +629,14 @@ private function finalizeParameterList(): void
632629
* @param array $attributes
633630
* @param string $key
634631
*
632+
* @throws \Propel\Generator\Exception\SchemaException
633+
*
635634
* @return string the non-empty value
636635
*/
637636
private function getExpectedValue(array $attributes, string $key): string
638637
{
639638
if (empty($attributes[$key])) {
640-
$this->throwSchemaExceptionWithLocation('Parameter misses expected attribute "%s"', $key);
639+
throw new SchemaException("Parameter misses expected attribute `$key`");
641640
}
642641

643642
return $attributes[$key];

src/Propel/Generator/Command/AbstractCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected function buildGeneratorConfig(?array $properties = null, ?InputInterfa
101101

102102
$configDir = $input->getOption('config-dir');
103103
try {
104-
return new GeneratorConfig($configDir, extraConf: $properties);
104+
return new GeneratorConfig($configDir, $properties);
105105
} catch (InvalidConfigurationException $e) {
106106
$userMessage = $this->getInvalidConfigurationExceptionUserMessage($e->getMessage(), $configDir);
107107

src/Propel/Generator/Config/QuickGeneratorConfig.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Propel\Generator\Config;
66

7+
use Propel\Common\Config\ConfigurationManager;
78
use Propel\Common\Pluralizer\PluralizerInterface;
89
use Propel\Common\Pluralizer\StandardEnglishPluralizer;
910
use Propel\Generator\Platform\PlatformInterface;
@@ -18,9 +19,7 @@ class QuickGeneratorConfig extends AbstractGeneratorConfig
1819
*/
1920
public function __construct(?array $extraConf = [])
2021
{
21-
if ($extraConf === null) {
22-
$extraConf = [];
23-
}
22+
$extraConf = $extraConf === null ? [] : ConfigurationManager::deflateConfigurationArray($extraConf);
2423

2524
//Creates a GeneratorConfig based on Propel default values plus the following
2625
$configs = [

src/Propel/Generator/Manager/ModelManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function build(): void
9292

9393
// If table has enumerated children (uses inheritance) then create the empty child stub classes if they don't already exist.
9494
$col = $table->getChildrenColumn();
95-
if ($col && $col->isEnumeratedClasses()) {
95+
if ($col?->isEnumeratedClasses()) {
9696
foreach ($col->getChildren() as $child) {
9797
foreach ([BuilderType::QueryInheritance] as $target) {
9898
if (!$child->getAncestor() && $child->getClassName() === $table->getPhpName()) {

src/Propel/Generator/Model/Database.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Propel\Generator\Config\AbstractGeneratorConfig;
88
use Propel\Generator\Exception\EngineException;
99
use Propel\Generator\Exception\InvalidArgumentException;
10+
use Propel\Generator\Exception\SchemaException;
1011
use Propel\Generator\Platform\PlatformInterface;
1112
use function array_search;
1213
use function count;
@@ -572,12 +573,16 @@ public function removeTable(Table $table): void
572573
* @param \Propel\Generator\Model\Table|array $table
573574
*
574575
* @throws \Propel\Generator\Exception\EngineException
576+
* @throws \Propel\Generator\Exception\SchemaException
575577
*
576578
* @return \Propel\Generator\Model\Table
577579
*/
578580
public function addTable($table): Table
579581
{
580582
if (!$table instanceof Table) {
583+
if (empty($table['name'])) {
584+
throw new SchemaException('Table misses required attribute `name`');
585+
}
581586
$tbl = new Table($table['name']);
582587
$tbl->setDatabase($this);
583588
$tbl->loadMapping($table);

src/Propel/Generator/Model/Table.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use function strtolower;
3232
use function strtoupper;
3333
use function substr_replace;
34+
use function var_export;
3435

3536
/**
3637
* Data about a table used in an application.
@@ -562,12 +563,16 @@ public function setBaseQueryClass(string $class): void
562563
* @param \Propel\Generator\Model\Column|array $col
563564
*
564565
* @throws \Propel\Generator\Exception\EngineException
566+
* @throws \Propel\Generator\Exception\SchemaException
565567
*
566568
* @return \Propel\Generator\Model\Column
567569
*/
568570
public function addColumn($col): Column
569571
{
570572
if (is_array($col)) {
573+
if (empty($col['name'])) {
574+
throw new SchemaException("Column on table `{$this->commonName}` misses required attribute `name` Attributes:" . var_export($col, true));
575+
}
571576
$column = new Column($col['name']);
572577
$column->setTable($this);
573578
$column->loadMapping($col);

0 commit comments

Comments
 (0)