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

Commit

Permalink
Merge branch 'feature/46' into develop
Browse files Browse the repository at this point in the history
Close #46
  • Loading branch information
weierophinney committed Feb 17, 2016
2 parents fd2a1c8 + 6c77e33 commit 1d465d9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ All notable changes to this project will be documented in this file, in reverse
result of an extract class refactoring, and contain the logic specific to
calcualting the checksum for each ISBN style. `Zend\Validator\Isbn` now
instantiates the appropriate one and invokes it.
- [#46](https://github.com/zendframework/zend-validator/pull/46) updates
`Zend\Validator\Db\AbstractDb` to implement `Zend\Db\Adapter\AdapterAwareInterface`,
by composing `Zend\Db\Adapter\AdapterAwareTrait`.

### Deprecated

Expand Down
16 changes: 6 additions & 10 deletions src/Db/AbstractDb.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

use Traversable;
use Zend\Db\Adapter\Adapter as DbAdapter;
use Zend\Db\Adapter\AdapterAwareInterface;
use Zend\Db\Adapter\AdapterAwareTrait;
use Zend\Db\Sql\Select;
use Zend\Db\Sql\Sql;
use Zend\Db\Sql\TableIdentifier;
Expand All @@ -21,8 +23,10 @@
/**
* Class for Database record validation
*/
abstract class AbstractDb extends AbstractValidator
abstract class AbstractDb extends AbstractValidator implements AdapterAwareInterface
{
use AdapterAwareTrait;

/**
* Error constants
*/
Expand Down Expand Up @@ -64,13 +68,6 @@ abstract class AbstractDb extends AbstractValidator
*/
protected $exclude = null;

/**
* Database adapter to use. If null isValid() will throw an exception
*
* @var \Zend\Db\Adapter\Adapter
*/
protected $adapter = null;

/**
* Provides basic configuration for use with Zend\Validator\Db Validators
* Setting $exclude allows a single record to be excluded from matching.
Expand Down Expand Up @@ -166,8 +163,7 @@ public function getAdapter()
*/
public function setAdapter(DbAdapter $adapter)
{
$this->adapter = $adapter;
return $this;
return $this->setDbAdapter($adapter);
}

/**
Expand Down
37 changes: 33 additions & 4 deletions test/Db/AbstractDbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
namespace ZendTest\Validator\Db;

use ZendTest\Validator\Db\TestAsset\ConcreteDbValidator;
use Zend\Db\Adapter\AdapterAwareInterface;
use Zend\Db\Adapter\Adapter;
use Zend\Db\Sql\Select;

/**
Expand All @@ -31,17 +33,21 @@ public function setUp()

public function testConstructorWithNoTableAndSchemaKey()
{
$this->setExpectedException('Zend\Validator\Exception\InvalidArgumentException',
'Table or Schema option missing!');
$this->setExpectedException(
'Zend\Validator\Exception\InvalidArgumentException',
'Table or Schema option missing!'
);
$this->validator = new ConcreteDbValidator([
'field' => 'field',
]);
}

public function testConstructorWithNoFieldKey()
{
$this->setExpectedException('Zend\Validator\Exception\InvalidArgumentException',
'Field option missing!');
$this->setExpectedException(
'Zend\Validator\Exception\InvalidArgumentException',
'Field option missing!'
);
$validator = new ConcreteDbValidator([
'schema' => 'schema',
'table' => 'table',
Expand Down Expand Up @@ -87,4 +93,27 @@ public function testGetExclude()

$this->assertEquals($field, $this->validator->getField());
}

/**
* @group #46
*/
public function testImplementationsAreDbAdapterAware()
{
$this->assertInstanceOf(AdapterAwareInterface::class, $this->validator);
}

/**
* @group #46
*/
public function testSetAdapterIsEquivalentToSetDbAdapter()
{
$adapterFirst = $this->prophesize(Adapter::class)->reveal();
$adapterSecond = $this->prophesize(Adapter::class)->reveal();

$this->validator->setAdapter($adapterFirst);
$this->assertAttributeSame($adapterFirst, 'adapter', $this->validator);

$this->validator->setDbAdapter($adapterSecond);
$this->assertAttributeSame($adapterSecond, 'adapter', $this->validator);
}
}

0 comments on commit 1d465d9

Please sign in to comment.