Skip to content

Commit

Permalink
Merge pull request #2257 from cakephp/fix-unset-properties
Browse files Browse the repository at this point in the history
Fix fatal errors when calling get methods
  • Loading branch information
dereuromark committed Jan 20, 2024
2 parents 5b42393 + 9de7d3e commit c353796
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Phinx/Db/Table/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ public function setType(string|Literal $type)
*/
public function getType(): string|Literal
{
if (!isset($this->type)) {
throw new RuntimeException('Cannot access `type` it has not been set');
}

return $this->type;
}

Expand Down
4 changes: 4 additions & 0 deletions src/Phinx/Db/Table/ForeignKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public function setReferencedTable(Table $table)
*/
public function getReferencedTable(): Table
{
if (!isset($this->referencedTable)) {
throw new RuntimeException('Cannot access `referencedTable` it has not been set');
}

return $this->referencedTable;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/Phinx/Db/Table/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ public function testSetOptionThrowsExceptionIfOptionIsNotString()
$column->setOptions(['identity']);
}

public function testGetType()
{
$column = new Column();
$this->expectException(RuntimeException::class);
$column->getType();
}

public function testSetOptionsIdentity()
{
$column = new Column();
Expand Down
6 changes: 6 additions & 0 deletions tests/Phinx/Db/Table/ForeignKeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public function testInitiallyActionsEmpty()
$this->assertNull($this->fk->getOnUpdate());
}

public function testRefrencedTableUndefined()
{
$this->expectException(RuntimeException::class);
$this->fk->getReferencedTable();
}

/**
* @param string $dirtyValue
* @param string $valueOfConstant
Expand Down

0 comments on commit c353796

Please sign in to comment.