Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/399'
Browse files Browse the repository at this point in the history
Close #399
Fix #376
  • Loading branch information
michalbundyra committed Dec 31, 2019
2 parents 1f83419 + 420c3a2 commit dd6bf89
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -28,6 +28,8 @@ All notable changes to this project will be documented in this file, in reverse

- [#392](https://github.com/zendframework/zend-db/pull/392) fixes `MetadataFeature` to work with `TableIdentifier`.

- [#399](https://github.com/zendframework/zend-db/pull/399) fixes accessing constraint metadata within the Oracle adapter.

## 2.10.0 - 2019-02-25

### Added
Expand Down
2 changes: 2 additions & 0 deletions src/Metadata/Source/OracleMetadata.php
Expand Up @@ -172,6 +172,8 @@ protected function loadConstraintData($table, $schema)
}
}

$this->data['constraints'][$schema][$table] = $constraints;

return $this;
}

Expand Down
69 changes: 67 additions & 2 deletions test/unit/Metadata/Source/OracleMetadataTest.php
Expand Up @@ -43,13 +43,78 @@ protected function setUp()
$this->metadata = new OracleMetadata($this->adapter);
}

public function testGetConstraints()
/**
* @dataProvider constraintDataProvider
*
* @param array $constraintData
*/
public function testGetConstraints(array $constraintData)
{
$statement = $this->getMockBuilder('Zend\Db\Adapter\Driver\Oci8\Statement')
->getMock();
$statement->expects($this->once())
->method('execute')
->willReturn($constraintData);

/** @var \Zend\Db\Adapter\Adapter|\PHPUnit_Framework_MockObject_MockObject $adapter */
$adapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter')
->setConstructorArgs([$this->variables])
->getMock();
$adapter->expects($this->once())
->method('query')
->willReturn($statement);

$this->metadata = new OracleMetadata($adapter);

$constraints = $this->metadata->getConstraints(null, 'main');
self::assertCount(0, $constraints);

self::assertCount(count($constraintData), $constraints);

self::assertContainsOnlyInstancesOf(
'Zend\Db\Metadata\Object\ConstraintObject',
$constraints
);
}

/**
* @return array
*/
public function constraintDataProvider()
{
return [
[
[
// no constraints
]
],
[
[
[
'OWNER' => 'SYS',
'CONSTRAINT_NAME' => 'SYS_C000001',
'CONSTRAINT_TYPE' => 'C',
'CHECK_CLAUSE' => '"COLUMN_1" IS NOT NULL',
'TABLE_NAME' => 'TABLE',
'DELETE_RULE' => null,
'COLUMN_NAME' => 'COLUMN_1',
'REF_TABLE' => null,
'REF_COLUMN' => null,
'REF_OWNER' => null,
],
[
'OWNER' => 'SYS',
'CONSTRAINT_NAME' => 'SYS_C000002',
'CONSTRAINT_TYPE' => 'C',
'CHECK_CLAUSE' => '"COLUMN_2" IS NOT NULL',
'TABLE_NAME' => 'TABLE',
'DELETE_RULE' => null,
'COLUMN_NAME' => 'COLUMN_2',
'REF_TABLE' => null,
'REF_COLUMN' => null,
'REF_OWNER' => null,
],
],
],
];
}
}

0 comments on commit dd6bf89

Please sign in to comment.